2016-07-15 00:02:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-10-06 11:20:59 +02:00
|
|
|
|
2017-02-05 13:32:31 +01:00
|
|
|
from functools import reduce
|
2016-05-26 22:44:10 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
|
|
|
def choices_length(choices):
|
|
|
|
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
LEVELS_CHOICES = (
|
2016-05-26 22:44:10 +02:00
|
|
|
('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)")),
|
2013-10-06 11:20:59 +02:00
|
|
|
)
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
class PetitCoursSubject(models.Model):
|
2016-05-26 22:44:10 +02:00
|
|
|
name = models.CharField(_("Matière"), max_length=30)
|
2016-06-17 13:26:55 +02:00
|
|
|
users = models.ManyToManyField(User, related_name="petits_cours_matieres",
|
|
|
|
through="PetitCoursAbility")
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Matière de petits cours"
|
|
|
|
verbose_name_plural = "Matières des petits cours"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2013-10-06 11:20:59 +02:00
|
|
|
return self.name
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
class PetitCoursAbility(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
2016-07-15 00:02:56 +02:00
|
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière"))
|
|
|
|
niveau = models.CharField(_("Niveau"),
|
2016-07-09 22:31:56 +02:00
|
|
|
choices=LEVELS_CHOICES,
|
|
|
|
max_length=choices_length(LEVELS_CHOICES))
|
2016-07-15 00:02:56 +02:00
|
|
|
agrege = models.BooleanField(_("Agrégé"), default=False)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Compétence petits cours"
|
|
|
|
verbose_name_plural = "Compétences des petits cours"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-02-05 13:49:01 +01:00
|
|
|
return "{:s} - {!s} - {:s}".format(
|
|
|
|
self.user.username, self.matiere, self.niveau
|
|
|
|
)
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class PetitCoursDemande(models.Model):
|
2016-07-15 00:02:56 +02:00
|
|
|
name = models.CharField(_("Nom/prénom"), max_length=200)
|
|
|
|
email = models.CharField(_("Adresse email"), max_length=300)
|
|
|
|
phone = models.CharField(_("Téléphone (facultatif)"),
|
2016-06-17 13:26:55 +02:00
|
|
|
max_length=20, blank=True)
|
|
|
|
quand = models.CharField(
|
2016-07-15 00:02:56 +02:00
|
|
|
_("Quand ?"),
|
|
|
|
help_text=_("Indiquez ici la période désirée pour les petits"
|
2016-07-09 22:31:56 +02:00
|
|
|
" cours (vacances scolaires, semaine, week-end)."),
|
|
|
|
max_length=300, blank=True)
|
2016-06-17 13:26:55 +02:00
|
|
|
freq = models.CharField(
|
2016-07-15 00:02:56 +02:00
|
|
|
_("Fréquence"),
|
|
|
|
help_text=_("Indiquez ici la fréquence envisagée "
|
2017-02-05 13:49:01 +01:00
|
|
|
"(hebdomadaire, 2 fois par semaine, ...)"),
|
2016-07-09 22:31:56 +02:00
|
|
|
max_length=300, blank=True)
|
2016-06-17 13:26:55 +02:00
|
|
|
lieu = models.CharField(
|
2016-07-15 00:02:56 +02:00
|
|
|
_("Lieu (si préférence)"),
|
|
|
|
help_text=_("Si vous avez avez une préférence sur le lieu."),
|
2016-07-09 22:31:56 +02:00
|
|
|
max_length=300, blank=True)
|
2016-06-17 13:26:55 +02:00
|
|
|
|
|
|
|
matieres = models.ManyToManyField(
|
2016-07-15 00:02:56 +02:00
|
|
|
PetitCoursSubject, verbose_name=_("Matières"),
|
2016-07-09 22:31:56 +02:00
|
|
|
related_name="demandes")
|
2016-07-15 00:02:56 +02:00
|
|
|
agrege_requis = models.BooleanField(_("Agrégé requis"), default=False)
|
|
|
|
niveau = models.CharField(_("Niveau"),
|
2016-07-09 22:31:56 +02:00
|
|
|
default="",
|
|
|
|
choices=LEVELS_CHOICES,
|
|
|
|
max_length=choices_length(LEVELS_CHOICES))
|
2013-10-06 11:20:59 +02:00
|
|
|
|
2016-07-15 00:02:56 +02:00
|
|
|
remarques = models.TextField(_("Remarques et précisions"), blank=True)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
2016-07-15 00:02:56 +02:00
|
|
|
traitee = models.BooleanField(_("Traitée"), default=False)
|
2016-06-17 13:26:55 +02:00
|
|
|
traitee_par = models.ForeignKey(User, blank=True, null=True)
|
2016-07-15 00:02:56 +02:00
|
|
|
processed = models.DateTimeField(_("Date de traitement"),
|
2016-06-17 13:29:26 +02:00
|
|
|
blank=True, null=True)
|
2016-07-15 00:02:56 +02:00
|
|
|
created = models.DateTimeField(_("Date de création"), auto_now_add=True)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Demande de petits cours"
|
|
|
|
verbose_name_plural = "Demandes de petits cours"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-02-05 13:49:01 +01:00
|
|
|
return "Demande {:d} du {:s}".format(
|
|
|
|
self.id, self.created.strftime("%d %b %Y")
|
|
|
|
)
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class PetitCoursAttribution(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
2016-06-17 13:26:55 +02:00
|
|
|
demande = models.ForeignKey(PetitCoursDemande, verbose_name=_("Demande"))
|
2016-07-15 00:02:56 +02:00
|
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matière"))
|
|
|
|
date = models.DateTimeField(_("Date d'attribution"), auto_now_add=True)
|
2013-10-06 11:20:59 +02:00
|
|
|
rank = models.IntegerField("Rang dans l'email")
|
2016-07-15 00:02:56 +02:00
|
|
|
selected = models.BooleanField(_("Sélectionné par le demandeur"),
|
2016-07-09 22:31:56 +02:00
|
|
|
default=False)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Attribution de petits cours"
|
|
|
|
verbose_name_plural = "Attributions de petits cours"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-02-05 13:49:01 +01:00
|
|
|
return "Attribution de la demande {:d} à {:s} pour {!s}".format(
|
|
|
|
self.demande.id, self.user.username, self.matiere
|
|
|
|
)
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class PetitCoursAttributionCounter(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
2016-06-17 13:26:55 +02:00
|
|
|
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matiere"))
|
|
|
|
count = models.IntegerField("Nombre d'envois", default=0)
|
2013-10-06 11:20:59 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Compteur d'attribution de petits cours"
|
|
|
|
verbose_name_plural = "Compteurs d'attributions de petits cours"
|
|
|
|
|
2016-07-15 00:02:56 +02:00
|
|
|
def __str__(self):
|
2017-02-05 13:49:01 +01:00
|
|
|
return "{:d} demandes envoyées à {:s} pour {!s}".format(
|
|
|
|
self.count, self.user.username, self.matiere
|
|
|
|
)
|