From c960d97b67041e371583b6a20e1e39ff923a2e30 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Sun, 25 Nov 2018 00:37:22 +0100 Subject: [PATCH] =?UTF-8?q?Extrait=20les=20petits=20cours=20dans=20une=20a?= =?UTF-8?q?pplication=20s=C3=A9par=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'application `petitscours` reste assez fortement couplée à `gestioncof`, et n'est pas (encore ?) faite pour être utilisée séparément. De façon similaire, et afin de minimiser de potentiels problèmes dûs à des migrations, les modèles de l'application `petitscours` utilisent `app_label = "gestioncof"` pour que Django les considère comme faisant partie de l'application `"gestioncof"`. Ils pourront être migrés dans un second temps si cela s'avère nécessaire. Les changements sont nombreux, mais assez simples: il s'agit principalement de déplacer des fichiers et changer des imports. J'ai également profité de l'occasion pour réorganiser les templates afin de les placer dans l'espace de nom "petitscours/". cof/ * settings/common.py: Add `petitscours` app * urls.py: Use `petitscours.urls` petitscours/ * __init__.py: Added. * tests/__init__.py: Added. * tests/utils.py: Added. * urls.py: Added. gestioncof/ * admin.py: * management/commands/loaddevdata.py: * models.py: * signals.py: Typo. * urls.py: Moved petitscours_patterns to petitscours.urls * petits_cours_forms.py: Moved to petitscours/forms.py * petits_cours_models.py: Moved to petitscours/models.py * petits_cours_views.py: Moved to petitscours/views.py * tests/utils.py: * tests/test_petitscours_views.py: Moved to petitscours/tests/test_petitscours_views.py * templates/base_title_petitscours.html: Moved to petitscours/templates/petitscours/base_title.html * templates/demande-petit-cours.html: Moved topetitscours/templates/petitscours/demande.html * templates/gestioncof/details_demande_petit_cours.html: Moved to petitscours/templates/petitscours/demande_detail.html * templates/petits_cours_demandes_list.html: Moved to petitscours/templates/petitscours/demande_list.html * templates/demande-petit-cours-raw.html: Moved to petitscours/templates/petitscours/demande_raw.html * templates/details_demande_petit_cours_infos.html: Moved to petitscours/templates/petitscours/details_demande_infos.html * templates/inscription-petit-cours.html: Moved to petitscours/templates/petitscours/inscription.html * templates/inscription-petit-cours-formset.html: Moved to petitscours/templates/petitscours/inscription_formset.html * templates/gestioncof/traitement_demande_petit_cours.html: Moved to petitscours/templates/petitscours/traitement_demande.html * templates/gestioncof/traitement_demande_petit_cours_autre_niveau.html: Moved to petitscours/templates/petitscours/traitement_demande_autre_niveau.html * templates/gestioncof/traitement_demande_petit_cours_success.html: Moved to petitscours/templates/petitscours/traitement_demande_success.html --- cof/settings/common.py | 1 + cof/urls.py | 3 +- gestioncof/admin.py | 14 +++---- gestioncof/management/commands/loaddevdata.py | 6 +-- gestioncof/models.py | 2 +- gestioncof/signals.py | 2 +- gestioncof/tests/utils.py | 39 ------------------- gestioncof/urls.py | 37 +----------------- petitscours/__init__.py | 0 .../forms.py | 3 +- .../models.py | 5 +++ .../templates/petitscours/base_title.html | 0 .../templates/petitscours/demande.html | 0 .../templates/petitscours/demande_detail.html | 4 +- .../templates/petitscours/demande_list.html | 2 +- .../templates/petitscours/demande_raw.html | 0 .../petitscours/details_demande_infos.html | 0 .../templates/petitscours/inscription.html | 2 +- .../petitscours/inscription_formset.html | 0 .../petitscours/traitement_demande.html | 4 +- .../traitement_demande_autre_niveau.html | 4 +- .../traitement_demande_success.html | 2 +- petitscours/tests/__init__.py | 0 .../tests/test_petitscours_views.py | 0 petitscours/tests/utils.py | 38 ++++++++++++++++++ petitscours/urls.py | 31 +++++++++++++++ .../views.py | 26 ++++++------- 27 files changed, 112 insertions(+), 113 deletions(-) create mode 100644 petitscours/__init__.py rename gestioncof/petits_cours_forms.py => petitscours/forms.py (95%) rename gestioncof/petits_cours_models.py => petitscours/models.py (97%) rename gestioncof/templates/base_title_petitscours.html => petitscours/templates/petitscours/base_title.html (100%) rename gestioncof/templates/demande-petit-cours.html => petitscours/templates/petitscours/demande.html (100%) rename gestioncof/templates/gestioncof/details_demande_petit_cours.html => petitscours/templates/petitscours/demande_detail.html (93%) rename gestioncof/templates/petits_cours_demandes_list.html => petitscours/templates/petitscours/demande_list.html (97%) rename gestioncof/templates/demande-petit-cours-raw.html => petitscours/templates/petitscours/demande_raw.html (100%) rename gestioncof/templates/details_demande_petit_cours_infos.html => petitscours/templates/petitscours/details_demande_infos.html (100%) rename gestioncof/templates/inscription-petit-cours.html => petitscours/templates/petitscours/inscription.html (98%) rename gestioncof/templates/inscription-petit-cours-formset.html => petitscours/templates/petitscours/inscription_formset.html (100%) rename gestioncof/templates/gestioncof/traitement_demande_petit_cours.html => petitscours/templates/petitscours/traitement_demande.html (94%) rename gestioncof/templates/gestioncof/traitement_demande_petit_cours_autre_niveau.html => petitscours/templates/petitscours/traitement_demande_autre_niveau.html (95%) rename gestioncof/templates/gestioncof/traitement_demande_petit_cours_success.html => petitscours/templates/petitscours/traitement_demande_success.html (89%) create mode 100644 petitscours/tests/__init__.py rename {gestioncof => petitscours}/tests/test_petitscours_views.py (100%) create mode 100644 petitscours/tests/utils.py create mode 100644 petitscours/urls.py rename gestioncof/petits_cours_views.py => petitscours/views.py (95%) diff --git a/cof/settings/common.py b/cof/settings/common.py index 4c853a16..50622f72 100644 --- a/cof/settings/common.py +++ b/cof/settings/common.py @@ -68,6 +68,7 @@ INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.admindocs", "bda", + "petitscours", "captcha", "django_cas_ng", "bootstrapform", diff --git a/cof/urls.py b/cof/urls.py index 7a0bee4c..c952cd98 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -20,7 +20,6 @@ from gestioncof.urls import ( clubs_patterns, events_patterns, export_patterns, - petitcours_patterns, surveys_patterns, ) @@ -34,7 +33,7 @@ urlpatterns = [ # Les exports url(r"^export/", include(export_patterns)), # Les petits cours - url(r"^petitcours/", include(petitcours_patterns)), + url(r"^petitcours/", include("petitscours.urls")), # Les sondages url(r"^survey/", include(surveys_patterns)), # Evenements diff --git a/gestioncof/admin.py b/gestioncof/admin.py index e89d4271..3886122e 100644 --- a/gestioncof/admin.py +++ b/gestioncof/admin.py @@ -7,6 +7,13 @@ from django.core.urlresolvers import reverse from django.db.models import Q from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ +from petitscours.models import ( + PetitCoursAbility, + PetitCoursAttribution, + PetitCoursAttributionCounter, + PetitCoursDemande, + PetitCoursSubject, +) from gestioncof.models import ( Club, @@ -20,13 +27,6 @@ from gestioncof.models import ( SurveyQuestion, SurveyQuestionAnswer, ) -from gestioncof.petits_cours_models import ( - PetitCoursAbility, - PetitCoursAttribution, - PetitCoursAttributionCounter, - PetitCoursDemande, - PetitCoursSubject, -) def add_link_field(target_model="", field="", link_text=str, desc_text=str): diff --git a/gestioncof/management/commands/loaddevdata.py b/gestioncof/management/commands/loaddevdata.py index 44d77065..e8d742b3 100644 --- a/gestioncof/management/commands/loaddevdata.py +++ b/gestioncof/management/commands/loaddevdata.py @@ -12,15 +12,15 @@ import random from django.contrib.auth.models import User from django.core.management import call_command - -from gestioncof.management.base import MyBaseCommand -from gestioncof.petits_cours_models import ( +from petitscours.models import ( LEVELS_CHOICES, PetitCoursAbility, PetitCoursAttributionCounter, PetitCoursSubject, ) +from gestioncof.management.base import MyBaseCommand + # Où sont stockés les fichiers json DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data") diff --git a/gestioncof/models.py b/gestioncof/models.py index 227fa936..0efb6e88 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -3,9 +3,9 @@ from django.db import models from django.db.models.signals import post_delete, post_save from django.dispatch import receiver from django.utils.translation import ugettext_lazy as _ +from petitscours.models import choices_length from bda.models import Spectacle -from gestioncof.petits_cours_models import choices_length TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court"))) diff --git a/gestioncof/signals.py b/gestioncof/signals.py index 3614b1c8..cf4b1f16 100644 --- a/gestioncof/signals.py +++ b/gestioncof/signals.py @@ -15,7 +15,7 @@ def messages_on_out_login(request, user, **kwargs): @receiver(cas_user_authenticated) -def mesagges_on_cas_login(request, user, **kwargs): +def messages_on_cas_login(request, user, **kwargs): msg = _("Connexion à GestioCOF par CAS réussie. Bienvenue {}.").format( user.get_short_name() ) diff --git a/gestioncof/tests/utils.py b/gestioncof/tests/utils.py index d35cb87f..7325e350 100644 --- a/gestioncof/tests/utils.py +++ b/gestioncof/tests/utils.py @@ -1,15 +1,4 @@ -import os - -from django.conf import settings from django.contrib.auth import get_user_model -from django.core.management import call_command - -from gestioncof.petits_cours_models import ( - PetitCoursAbility, - PetitCoursAttributionCounter, - PetitCoursDemande, - PetitCoursSubject, -) User = get_user_model() @@ -77,31 +66,3 @@ def create_root(username, attrs=None): attrs.setdefault("is_staff", True) attrs.setdefault("is_superuser", True) return _create_user(username, attrs=attrs) - - -def create_petitcours_ability(**kwargs): - if "user" not in kwargs: - kwargs["user"] = create_user() - if "matiere" not in kwargs: - kwargs["matiere"] = create_petitcours_subject() - if "niveau" not in kwargs: - kwargs["niveau"] = "college" - ability = PetitCoursAbility.objects.create(**kwargs) - PetitCoursAttributionCounter.get_uptodate(ability.user, ability.matiere) - return ability - - -def create_petitcours_demande(**kwargs): - return PetitCoursDemande.objects.create(**kwargs) - - -def create_petitcours_subject(**kwargs): - return PetitCoursSubject.objects.create(**kwargs) - - -class PetitCoursTestHelpers: - def require_custommails(self): - data_file = os.path.join( - settings.BASE_DIR, "gestioncof", "management", "data", "custommail.json" - ) - call_command("syncmails", data_file, verbosity=0) diff --git a/gestioncof/urls.py b/gestioncof/urls.py index c4414fa5..e1e36a17 100644 --- a/gestioncof/urls.py +++ b/gestioncof/urls.py @@ -1,8 +1,7 @@ from django.conf.urls import url -from gestioncof import petits_cours_views, views +from gestioncof import views from gestioncof.decorators import buro_required -from gestioncof.petits_cours_views import DemandeDetailView, DemandeListView export_patterns = [ url(r"^members$", views.export_members, name="cof.membres_export"), @@ -21,40 +20,6 @@ export_patterns = [ url(r"^mega$", views.export_mega, name="cof.mega_export"), ] -petitcours_patterns = [ - url( - r"^inscription$", - petits_cours_views.inscription, - name="petits-cours-inscription", - ), - url(r"^demande$", petits_cours_views.demande, name="petits-cours-demande"), - url( - r"^demande-raw$", - petits_cours_views.demande_raw, - name="petits-cours-demande-raw", - ), - url( - r"^demandes$", - buro_required(DemandeListView.as_view()), - name="petits-cours-demandes-list", - ), - url( - r"^demandes/(?P\d+)$", - buro_required(DemandeDetailView.as_view()), - name="petits-cours-demande-details", - ), - url( - r"^demandes/(?P\d+)/traitement$", - petits_cours_views.traitement, - name="petits-cours-demande-traitement", - ), - url( - r"^demandes/(?P\d+)/retraitement$", - petits_cours_views.retraitement, - name="petits-cours-demande-retraitement", - ), -] - surveys_patterns = [ url( r"^(?P\d+)/status$", diff --git a/petitscours/__init__.py b/petitscours/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/gestioncof/petits_cours_forms.py b/petitscours/forms.py similarity index 95% rename from gestioncof/petits_cours_forms.py rename to petitscours/forms.py index b9cfc067..ecaad2d5 100644 --- a/gestioncof/petits_cours_forms.py +++ b/petitscours/forms.py @@ -3,8 +3,7 @@ from django import forms from django.contrib.auth.models import User from django.forms import ModelForm from django.forms.models import BaseInlineFormSet, inlineformset_factory - -from gestioncof.petits_cours_models import PetitCoursAbility, PetitCoursDemande +from petitscours.models import PetitCoursAbility, PetitCoursDemande class BaseMatieresFormSet(BaseInlineFormSet): diff --git a/gestioncof/petits_cours_models.py b/petitscours/models.py similarity index 97% rename from gestioncof/petits_cours_models.py rename to petitscours/models.py index 40031877..50f8910e 100644 --- a/gestioncof/petits_cours_models.py +++ b/petitscours/models.py @@ -27,6 +27,7 @@ class PetitCoursSubject(models.Model): ) class Meta: + app_label = "gestioncof" verbose_name = "Matière de petits cours" verbose_name_plural = "Matières des petits cours" @@ -45,6 +46,7 @@ class PetitCoursAbility(models.Model): agrege = models.BooleanField(_("Agrégé"), default=False) class Meta: + app_label = "gestioncof" verbose_name = "Compétence petits cours" verbose_name_plural = "Compétences des petits cours" @@ -127,6 +129,7 @@ class PetitCoursDemande(models.Model): yield (matiere, candidates) class Meta: + app_label = "gestioncof" verbose_name = "Demande de petits cours" verbose_name_plural = "Demandes de petits cours" @@ -147,6 +150,7 @@ class PetitCoursAttribution(models.Model): selected = models.BooleanField(_("Sélectionné par le demandeur"), default=False) class Meta: + app_label = "gestioncof" verbose_name = "Attribution de petits cours" verbose_name_plural = "Attributions de petits cours" @@ -182,6 +186,7 @@ class PetitCoursAttributionCounter(models.Model): return counter class Meta: + app_label = "gestioncof" verbose_name = "Compteur d'attribution de petits cours" verbose_name_plural = "Compteurs d'attributions de petits cours" diff --git a/gestioncof/templates/base_title_petitscours.html b/petitscours/templates/petitscours/base_title.html similarity index 100% rename from gestioncof/templates/base_title_petitscours.html rename to petitscours/templates/petitscours/base_title.html diff --git a/gestioncof/templates/demande-petit-cours.html b/petitscours/templates/petitscours/demande.html similarity index 100% rename from gestioncof/templates/demande-petit-cours.html rename to petitscours/templates/petitscours/demande.html diff --git a/gestioncof/templates/gestioncof/details_demande_petit_cours.html b/petitscours/templates/petitscours/demande_detail.html similarity index 93% rename from gestioncof/templates/gestioncof/details_demande_petit_cours.html rename to petitscours/templates/petitscours/demande_detail.html index b51c0dc0..e82a67d4 100644 --- a/gestioncof/templates/gestioncof/details_demande_petit_cours.html +++ b/petitscours/templates/petitscours/demande_detail.html @@ -1,11 +1,11 @@ -{% extends "base_title_petitscours.html" %} +{% extends "petitscours/base_title.html" %} {% load staticfiles %} {% block page_size %}col-sm-8{% endblock %} {% block realcontent %}

Demande de petits cours

- {% include "details_demande_petit_cours_infos.html" %} + {% include "petitscours/details_demande_infos.html" %}
diff --git a/gestioncof/templates/petits_cours_demandes_list.html b/petitscours/templates/petitscours/demande_list.html similarity index 97% rename from gestioncof/templates/petits_cours_demandes_list.html rename to petitscours/templates/petitscours/demande_list.html index 92e934f5..74654e44 100644 --- a/gestioncof/templates/petits_cours_demandes_list.html +++ b/petitscours/templates/petitscours/demande_list.html @@ -1,4 +1,4 @@ -{% extends "base_title_petitscours.html" %} +{% extends "petitscours/base_title.html" %} {% load staticfiles %} {% block realcontent %} diff --git a/gestioncof/templates/demande-petit-cours-raw.html b/petitscours/templates/petitscours/demande_raw.html similarity index 100% rename from gestioncof/templates/demande-petit-cours-raw.html rename to petitscours/templates/petitscours/demande_raw.html diff --git a/gestioncof/templates/details_demande_petit_cours_infos.html b/petitscours/templates/petitscours/details_demande_infos.html similarity index 100% rename from gestioncof/templates/details_demande_petit_cours_infos.html rename to petitscours/templates/petitscours/details_demande_infos.html diff --git a/gestioncof/templates/inscription-petit-cours.html b/petitscours/templates/petitscours/inscription.html similarity index 98% rename from gestioncof/templates/inscription-petit-cours.html rename to petitscours/templates/petitscours/inscription.html index 4ac0a874..c4920fb3 100644 --- a/gestioncof/templates/inscription-petit-cours.html +++ b/petitscours/templates/petitscours/inscription.html @@ -94,7 +94,7 @@ var django = { {% csrf_token %}
Recevoir des propositions de petits cours
- {% include "inscription-petit-cours-formset.html" %} + {% include "petitscours/inscription_formset.html" %}
Traitée