Extrait les petits cours dans une application séparée

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
This commit is contained in:
Basile Clement 2018-11-25 00:37:22 +01:00
parent d82c9baf20
commit c960d97b67
27 changed files with 112 additions and 113 deletions

View file

@ -68,6 +68,7 @@ INSTALLED_APPS = [
"django.contrib.admin", "django.contrib.admin",
"django.contrib.admindocs", "django.contrib.admindocs",
"bda", "bda",
"petitscours",
"captcha", "captcha",
"django_cas_ng", "django_cas_ng",
"bootstrapform", "bootstrapform",

View file

@ -20,7 +20,6 @@ from gestioncof.urls import (
clubs_patterns, clubs_patterns,
events_patterns, events_patterns,
export_patterns, export_patterns,
petitcours_patterns,
surveys_patterns, surveys_patterns,
) )
@ -34,7 +33,7 @@ urlpatterns = [
# Les exports # Les exports
url(r"^export/", include(export_patterns)), url(r"^export/", include(export_patterns)),
# Les petits cours # Les petits cours
url(r"^petitcours/", include(petitcours_patterns)), url(r"^petitcours/", include("petitscours.urls")),
# Les sondages # Les sondages
url(r"^survey/", include(surveys_patterns)), url(r"^survey/", include(surveys_patterns)),
# Evenements # Evenements

View file

@ -7,6 +7,13 @@ from django.core.urlresolvers import reverse
from django.db.models import Q from django.db.models import Q
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from petitscours.models import (
PetitCoursAbility,
PetitCoursAttribution,
PetitCoursAttributionCounter,
PetitCoursDemande,
PetitCoursSubject,
)
from gestioncof.models import ( from gestioncof.models import (
Club, Club,
@ -20,13 +27,6 @@ from gestioncof.models import (
SurveyQuestion, SurveyQuestion,
SurveyQuestionAnswer, 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): def add_link_field(target_model="", field="", link_text=str, desc_text=str):

View file

@ -12,15 +12,15 @@ import random
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management import call_command from django.core.management import call_command
from petitscours.models import (
from gestioncof.management.base import MyBaseCommand
from gestioncof.petits_cours_models import (
LEVELS_CHOICES, LEVELS_CHOICES,
PetitCoursAbility, PetitCoursAbility,
PetitCoursAttributionCounter, PetitCoursAttributionCounter,
PetitCoursSubject, PetitCoursSubject,
) )
from gestioncof.management.base import MyBaseCommand
# Où sont stockés les fichiers json # Où sont stockés les fichiers json
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data") DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data")

View file

@ -3,9 +3,9 @@ from django.db import models
from django.db.models.signals import post_delete, post_save from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from petitscours.models import choices_length
from bda.models import Spectacle from bda.models import Spectacle
from gestioncof.petits_cours_models import choices_length
TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court"))) TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court")))

View file

@ -15,7 +15,7 @@ def messages_on_out_login(request, user, **kwargs):
@receiver(cas_user_authenticated) @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( msg = _("Connexion à GestioCOF par CAS réussie. Bienvenue {}.").format(
user.get_short_name() user.get_short_name()
) )

View file

@ -1,15 +1,4 @@
import os
from django.conf import settings
from django.contrib.auth import get_user_model 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() User = get_user_model()
@ -77,31 +66,3 @@ def create_root(username, attrs=None):
attrs.setdefault("is_staff", True) attrs.setdefault("is_staff", True)
attrs.setdefault("is_superuser", True) attrs.setdefault("is_superuser", True)
return _create_user(username, attrs=attrs) 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)

View file

@ -1,8 +1,7 @@
from django.conf.urls import url 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.decorators import buro_required
from gestioncof.petits_cours_views import DemandeDetailView, DemandeListView
export_patterns = [ export_patterns = [
url(r"^members$", views.export_members, name="cof.membres_export"), 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"), 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<pk>\d+)$",
buro_required(DemandeDetailView.as_view()),
name="petits-cours-demande-details",
),
url(
r"^demandes/(?P<demande_id>\d+)/traitement$",
petits_cours_views.traitement,
name="petits-cours-demande-traitement",
),
url(
r"^demandes/(?P<demande_id>\d+)/retraitement$",
petits_cours_views.retraitement,
name="petits-cours-demande-retraitement",
),
]
surveys_patterns = [ surveys_patterns = [
url( url(
r"^(?P<survey_id>\d+)/status$", r"^(?P<survey_id>\d+)/status$",

0
petitscours/__init__.py Normal file
View file

View file

@ -3,8 +3,7 @@ from django import forms
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.forms import ModelForm from django.forms import ModelForm
from django.forms.models import BaseInlineFormSet, inlineformset_factory from django.forms.models import BaseInlineFormSet, inlineformset_factory
from petitscours.models import PetitCoursAbility, PetitCoursDemande
from gestioncof.petits_cours_models import PetitCoursAbility, PetitCoursDemande
class BaseMatieresFormSet(BaseInlineFormSet): class BaseMatieresFormSet(BaseInlineFormSet):

View file

@ -27,6 +27,7 @@ class PetitCoursSubject(models.Model):
) )
class Meta: class Meta:
app_label = "gestioncof"
verbose_name = "Matière de petits cours" verbose_name = "Matière de petits cours"
verbose_name_plural = "Matières des 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) agrege = models.BooleanField(_("Agrégé"), default=False)
class Meta: class Meta:
app_label = "gestioncof"
verbose_name = "Compétence petits cours" verbose_name = "Compétence petits cours"
verbose_name_plural = "Compétences des petits cours" verbose_name_plural = "Compétences des petits cours"
@ -127,6 +129,7 @@ class PetitCoursDemande(models.Model):
yield (matiere, candidates) yield (matiere, candidates)
class Meta: class Meta:
app_label = "gestioncof"
verbose_name = "Demande de petits cours" verbose_name = "Demande de petits cours"
verbose_name_plural = "Demandes 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) selected = models.BooleanField(_("Sélectionné par le demandeur"), default=False)
class Meta: class Meta:
app_label = "gestioncof"
verbose_name = "Attribution de petits cours" verbose_name = "Attribution de petits cours"
verbose_name_plural = "Attributions de petits cours" verbose_name_plural = "Attributions de petits cours"
@ -182,6 +186,7 @@ class PetitCoursAttributionCounter(models.Model):
return counter return counter
class Meta: class Meta:
app_label = "gestioncof"
verbose_name = "Compteur d'attribution de petits cours" verbose_name = "Compteur d'attribution de petits cours"
verbose_name_plural = "Compteurs d'attributions de petits cours" verbose_name_plural = "Compteurs d'attributions de petits cours"

View file

@ -1,11 +1,11 @@
{% extends "base_title_petitscours.html" %} {% extends "petitscours/base_title.html" %}
{% load staticfiles %} {% load staticfiles %}
{% block page_size %}col-sm-8{% endblock %} {% block page_size %}col-sm-8{% endblock %}
{% block realcontent %} {% block realcontent %}
<h2>Demande de petits cours</h2> <h2>Demande de petits cours</h2>
{% include "details_demande_petit_cours_infos.html" %} {% include "petitscours/details_demande_infos.html" %}
<hr /> <hr />
<table class="table table-striped"> <table class="table table-striped">
<tr><td><strong>Traitée</strong></td><td> <img src="{% if demande.traitee %}{% static "images/yes.png" %}{% else %}{% static "images/no.png" %}{% endif %}" /></td></tr> <tr><td><strong>Traitée</strong></td><td> <img src="{% if demande.traitee %}{% static "images/yes.png" %}{% else %}{% static "images/no.png" %}{% endif %}" /></td></tr>

View file

@ -1,4 +1,4 @@
{% extends "base_title_petitscours.html" %} {% extends "petitscours/base_title.html" %}
{% load staticfiles %} {% load staticfiles %}
{% block realcontent %} {% block realcontent %}

View file

@ -94,7 +94,7 @@ var django = {
<form class="form-horizontal petit-cours_form" id="bda_form" method="post" action="{% url 'petits-cours-inscription' %}"> <form class="form-horizontal petit-cours_form" id="bda_form" method="post" action="{% url 'petits-cours-inscription' %}">
{% csrf_token %} {% csrf_token %}
<div class="table-top" style="margin-left:0px; margin-right:0px; font-size: 1.25em; font-weight: bold; color: #DE826B;"><input type="checkbox" name="receive_proposals" {% if receive_proposals %}checked="checked"{% endif %} /> Recevoir des propositions de petits cours</div> <div class="table-top" style="margin-left:0px; margin-right:0px; font-size: 1.25em; font-weight: bold; color: #DE826B;"><input type="checkbox" name="receive_proposals" {% if receive_proposals %}checked="checked"{% endif %} /> Recevoir des propositions de petits cours</div>
{% include "inscription-petit-cours-formset.html" %} {% include "petitscours/inscription_formset.html" %}
<div class="inscription-bottom"> <div class="inscription-bottom">
<input type="button" class="btn btn-default pull-right" value="Ajouter une autre matière" id="add_more" /> <input type="button" class="btn btn-default pull-right" value="Ajouter une autre matière" id="add_more" />
<script> <script>

View file

@ -1,8 +1,8 @@
{% extends "base_title_petitscours.html" %} {% extends "petitscours/base_title.html" %}
{% block realcontent %} {% block realcontent %}
<h2>Traitement de la demande de petits cours {{ demande.id }}</h2> <h2>Traitement de la demande de petits cours {{ demande.id }}</h2>
{% include "details_demande_petit_cours_infos.html" %} {% include "petitscours/details_demande_infos.html" %}
<hr /> <hr />
{% if errors %} {% if errors %}
<div class="error"> <div class="error">

View file

@ -1,9 +1,9 @@
{% extends "base_title_petitscours.html" %} {% extends "petitscours/base_title.html" %}
{% load staticfiles %} {% load staticfiles %}
{% block realcontent %} {% block realcontent %}
<h2>Traitement de la demande de petits cours {{ demande.id }}</h2> <h2>Traitement de la demande de petits cours {{ demande.id }}</h2>
{% include "details_demande_petit_cours_infos.html" %} {% include "petitscours/details_demande_infos.html" %}
<hr /> <hr />
<div class="error"> <div class="error">
Attention: demande de petits cours spécifiant le niveau "Autre niveau": choisissez les candidats correspondant aux remarques de la demande. S'il y a moins de 3 candidats adaptés, ne mettre que ceux qui conviennent, pas besoin de faire du bourrage :) Attention: demande de petits cours spécifiant le niveau "Autre niveau": choisissez les candidats correspondant aux remarques de la demande. S'il y a moins de 3 candidats adaptés, ne mettre que ceux qui conviennent, pas besoin de faire du bourrage :)

View file

@ -1,4 +1,4 @@
{% extends "base_title_petitscours.html" %} {% extends "petitscours/base_title.html" %}
{% block realcontent %} {% block realcontent %}
<h2>Traitement de la demande de petits cours {{ demande.id }}</h2> <h2>Traitement de la demande de petits cours {{ demande.id }}</h2>

View file

View file

@ -0,0 +1,38 @@
import os
from django.conf import settings
from django.core.management import call_command
from petitscours.models import (
PetitCoursAbility,
PetitCoursAttributionCounter,
PetitCoursDemande,
PetitCoursSubject,
)
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)

31
petitscours/urls.py Normal file
View file

@ -0,0 +1,31 @@
from django.conf.urls import url
from petitscours import views
from petitscours.views import DemandeDetailView, DemandeListView
from gestioncof.decorators import buro_required
urlpatterns = [
url(r"^inscription$", views.inscription, name="petits-cours-inscription"),
url(r"^demande$", views.demande, name="petits-cours-demande"),
url(r"^demande-raw$", 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<pk>\d+)$",
buro_required(DemandeDetailView.as_view()),
name="petits-cours-demande-details",
),
url(
r"^demandes/(?P<demande_id>\d+)/traitement$",
views.traitement,
name="petits-cours-demande-traitement",
),
url(
r"^demandes/(?P<demande_id>\d+)/retraitement$",
views.retraitement,
name="petits-cours-demande-retraitement",
),
]

View file

@ -11,23 +11,23 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from petitscours.forms import DemandeForm, MatieresFormSet
from gestioncof.decorators import buro_required from petitscours.models import (
from gestioncof.models import CofProfile
from gestioncof.petits_cours_forms import DemandeForm, MatieresFormSet
from gestioncof.petits_cours_models import (
PetitCoursAbility, PetitCoursAbility,
PetitCoursAttribution, PetitCoursAttribution,
PetitCoursAttributionCounter, PetitCoursAttributionCounter,
PetitCoursDemande, PetitCoursDemande,
) )
from gestioncof.decorators import buro_required
from gestioncof.models import CofProfile
class DemandeListView(ListView): class DemandeListView(ListView):
queryset = PetitCoursDemande.objects.prefetch_related("matieres").order_by( queryset = PetitCoursDemande.objects.prefetch_related("matieres").order_by(
"traitee", "-id" "traitee", "-id"
) )
template_name = "petits_cours_demandes_list.html" template_name = "petitscours/demande_list.html"
paginate_by = 20 paginate_by = 20
@ -36,7 +36,7 @@ class DemandeDetailView(DetailView):
queryset = PetitCoursDemande.objects.prefetch_related( queryset = PetitCoursDemande.objects.prefetch_related(
"petitcoursattribution_set", "matieres" "petitcoursattribution_set", "matieres"
) )
template_name = "gestioncof/details_demande_petit_cours.html" template_name = "petitscours/demande_detail.html"
context_object_name = "demande" context_object_name = "demande"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -122,7 +122,7 @@ def _finalize_traitement(
messages.error(request, error) messages.error(request, error)
return render( return render(
request, request,
"gestioncof/traitement_demande_petit_cours.html", "petitscours/traitement_demande.html",
{ {
"demande": demande, "demande": demande,
"unsatisfied": unsatisfied, "unsatisfied": unsatisfied,
@ -250,7 +250,7 @@ def _traitement_other(request, demande, redo):
proposed_for = proposed_for.items() proposed_for = proposed_for.items()
return render( return render(
request, request,
"gestioncof/traitement_demande_petit_cours_autre_niveau.html", "petitscours/traitement_demande_autre_niveau.html",
{ {
"demande": demande, "demande": demande,
"unsatisfied": unsatisfied, "unsatisfied": unsatisfied,
@ -332,7 +332,7 @@ def _traitement_post(request, demande):
demande.save() demande.save()
return render( return render(
request, request,
"gestioncof/traitement_demande_petit_cours_success.html", "petitscours/traitement_demande_success.html",
{"demande": demande, "redo": redo}, {"demande": demande, "redo": redo},
) )
@ -362,7 +362,7 @@ def inscription(request):
formset = MatieresFormSet(instance=request.user) formset = MatieresFormSet(instance=request.user)
return render( return render(
request, request,
"inscription-petit-cours.html", "petitscours/inscription.html",
{ {
"formset": formset, "formset": formset,
"success": success, "success": success,
@ -383,7 +383,7 @@ def demande(request):
else: else:
form = DemandeForm() form = DemandeForm()
return render( return render(
request, "demande-petit-cours.html", {"form": form, "success": success} request, "petitscours/demande.html", {"form": form, "success": success}
) )
@ -398,5 +398,5 @@ def demande_raw(request):
else: else:
form = DemandeForm() form = DemandeForm()
return render( return render(
request, "demande-petit-cours-raw.html", {"form": form, "success": success} request, "petitscours/demande_raw.html", {"form": form, "success": success}
) )