forked from DGNum/gestioCOF
2bc5f3d646
- Drop `%` in favour of `.format` which has a better specification - Remove a string concatenation - Remove the trailing slashes according to the PEP8: https://www.python.org/dev/peps/pep-0008/#maximum-line-length NB. We let some which will disappear in the next commit. - Remove an unused import and change the imports order
132 lines
4.8 KiB
Python
132 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from functools import reduce
|
|
|
|
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
def choices_length(choices):
|
|
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
|
|
|
|
LEVELS_CHOICES = (
|
|
('college', _("Collège")),
|
|
('lycee', _("Lycée")),
|
|
('prepa1styear', _("Prépa 1ère année / L1")),
|
|
('prepa2ndyear', _("Prépa 2ème année / L2")),
|
|
('licence3', _("Licence 3")),
|
|
('other', _("Autre (préciser dans les commentaires)")),
|
|
)
|
|
|
|
|
|
class PetitCoursSubject(models.Model):
|
|
name = models.CharField(_("Matière"), max_length=30)
|
|
users = models.ManyToManyField(User, related_name="petits_cours_matieres",
|
|
through="PetitCoursAbility")
|
|
|
|
class Meta:
|
|
verbose_name = "Matière de petits cours"
|
|
verbose_name_plural = "Matières des petits cours"
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class PetitCoursAbility(models.Model):
|
|
user = models.ForeignKey(User)
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière"))
|
|
niveau = models.CharField(_("Niveau"),
|
|
choices=LEVELS_CHOICES,
|
|
max_length=choices_length(LEVELS_CHOICES))
|
|
agrege = models.BooleanField(_("Agrégé"), default=False)
|
|
|
|
class Meta:
|
|
verbose_name = "Compétence petits cours"
|
|
verbose_name_plural = "Compétences des petits cours"
|
|
|
|
def __str__(self):
|
|
return "{:s} - {!s} - {:s}".format(
|
|
self.user.username, self.matiere, self.niveau
|
|
)
|
|
|
|
|
|
class PetitCoursDemande(models.Model):
|
|
name = models.CharField(_("Nom/prénom"), max_length=200)
|
|
email = models.CharField(_("Adresse email"), max_length=300)
|
|
phone = models.CharField(_("Téléphone (facultatif)"),
|
|
max_length=20, blank=True)
|
|
quand = models.CharField(
|
|
_("Quand ?"),
|
|
help_text=_("Indiquez ici la période désirée pour les petits"
|
|
" cours (vacances scolaires, semaine, week-end)."),
|
|
max_length=300, blank=True)
|
|
freq = models.CharField(
|
|
_("Fréquence"),
|
|
help_text=_("Indiquez ici la fréquence envisagée "
|
|
"(hebdomadaire, 2 fois par semaine, ...)"),
|
|
max_length=300, blank=True)
|
|
lieu = models.CharField(
|
|
_("Lieu (si préférence)"),
|
|
help_text=_("Si vous avez avez une préférence sur le lieu."),
|
|
max_length=300, blank=True)
|
|
|
|
matieres = models.ManyToManyField(
|
|
PetitCoursSubject, verbose_name=_("Matières"),
|
|
related_name="demandes")
|
|
agrege_requis = models.BooleanField(_("Agrégé requis"), default=False)
|
|
niveau = models.CharField(_("Niveau"),
|
|
default="",
|
|
choices=LEVELS_CHOICES,
|
|
max_length=choices_length(LEVELS_CHOICES))
|
|
|
|
remarques = models.TextField(_("Remarques et précisions"), blank=True)
|
|
|
|
traitee = models.BooleanField(_("Traitée"), default=False)
|
|
traitee_par = models.ForeignKey(User, blank=True, null=True)
|
|
processed = models.DateTimeField(_("Date de traitement"),
|
|
blank=True, null=True)
|
|
created = models.DateTimeField(_("Date de création"), auto_now_add=True)
|
|
|
|
class Meta:
|
|
verbose_name = "Demande de petits cours"
|
|
verbose_name_plural = "Demandes de petits cours"
|
|
|
|
def __str__(self):
|
|
return "Demande {:d} du {:s}".format(
|
|
self.id, self.created.strftime("%d %b %Y")
|
|
)
|
|
|
|
|
|
class PetitCoursAttribution(models.Model):
|
|
user = models.ForeignKey(User)
|
|
demande = models.ForeignKey(PetitCoursDemande, verbose_name=_("Demande"))
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière"))
|
|
date = models.DateTimeField(_("Date d'attribution"), auto_now_add=True)
|
|
rank = models.IntegerField("Rang dans l'email")
|
|
selected = models.BooleanField(_("Sélectionné par le demandeur"),
|
|
default=False)
|
|
|
|
class Meta:
|
|
verbose_name = "Attribution de petits cours"
|
|
verbose_name_plural = "Attributions de petits cours"
|
|
|
|
def __str__(self):
|
|
return "Attribution de la demande {:d} à {:s} pour {!s}".format(
|
|
self.demande.id, self.user.username, self.matiere
|
|
)
|
|
|
|
|
|
class PetitCoursAttributionCounter(models.Model):
|
|
user = models.ForeignKey(User)
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matiere"))
|
|
count = models.IntegerField("Nombre d'envois", default=0)
|
|
|
|
class Meta:
|
|
verbose_name = "Compteur d'attribution de petits cours"
|
|
verbose_name_plural = "Compteurs d'attributions de petits cours"
|
|
|
|
def __str__(self):
|
|
return "{:d} demandes envoyées à {:s} pour {!s}".format(
|
|
self.count, self.user.username, self.matiere
|
|
)
|