kpsul/gestioncof/petits_cours_models.py

127 lines
4.8 KiB
Python
Raw Normal View History

2013-10-06 11:20:59 +02:00
# coding: utf-8
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)
2013-10-06 11:20:59 +02:00
LEVELS_CHOICES = (
('college', _(u"Collège")),
('lycee', _(u"Lycée")),
('prepa1styear', _(u"Prépa 1ère année / L1")),
('prepa2ndyear', _(u"Prépa 2ème année / L2")),
('licence3', _(u"Licence 3")),
2013-10-06 11:20:59 +02:00
('other', _(u"Autre (préciser dans les commentaires)")),
)
2013-10-06 11:20:59 +02:00
class PetitCoursSubject(models.Model):
2016-06-17 13:26:55 +02:00
name = models.CharField(_(u"Matière"), max_length=30)
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"
def __unicode__(self):
return self.name
2013-10-06 11:20:59 +02:00
class PetitCoursAbility(models.Model):
user = models.ForeignKey(User)
2016-06-17 13:26:55 +02:00
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière"))
niveau = models.CharField(_(u"Niveau"),
choices=LEVELS_CHOICES,
max_length=choices_length(LEVELS_CHOICES))
2016-06-17 13:26:55 +02:00
agrege = models.BooleanField(_(u"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"
def __unicode__(self):
return u"%s - %s - %s" % (self.user.username,
self.matiere, self.niveau)
2013-10-06 11:20:59 +02:00
class PetitCoursDemande(models.Model):
2016-06-17 13:26:55 +02:00
name = models.CharField(_(u"Nom/prénom"), max_length=200)
email = models.CharField(_(u"Adresse email"), max_length=300)
phone = models.CharField(_(u"Téléphone (facultatif)"),
max_length=20, blank=True)
quand = models.CharField(
_(u"Quand ?"),
help_text=_(u"Indiquez ici la période désirée pour les petits"
" cours (vacances scolaires, semaine, week-end)."),
max_length=300, blank=True)
2016-06-17 13:26:55 +02:00
freq = models.CharField(
_(u"Fréquence"),
help_text=_(u"Indiquez ici la fréquence envisagée "
2016-06-17 13:26:55 +02:00
+ "(hebdomadaire, 2 fois par semaine, ...)"),
max_length=300, blank=True)
2016-06-17 13:26:55 +02:00
lieu = models.CharField(
_(u"Lieu (si préférence)"),
help_text=_(u"Si vous avez avez une préférence sur le lieu."),
max_length=300, blank=True)
2016-06-17 13:26:55 +02:00
matieres = models.ManyToManyField(
PetitCoursSubject, verbose_name=_(u"Matières"),
related_name="demandes")
2016-06-17 13:26:55 +02:00
agrege_requis = models.BooleanField(_(u"Agrégé requis"), default=False)
niveau = models.CharField(_(u"Niveau"),
default="",
choices=LEVELS_CHOICES,
max_length=choices_length(LEVELS_CHOICES))
2013-10-06 11:20:59 +02:00
2016-06-17 13:26:55 +02:00
remarques = models.TextField(_(u"Remarques et précisions"), blank=True)
2013-10-06 11:20:59 +02:00
2016-06-17 13:26:55 +02:00
traitee = models.BooleanField(_(u"Traitée"), default=False)
traitee_par = models.ForeignKey(User, blank=True, null=True)
processed = models.DateTimeField(_(u"Date de traitement"),
blank=True, null=True)
2016-06-17 13:26:55 +02:00
created = models.DateTimeField(_(u"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"
def __unicode__(self):
return u"Demande %d du %s" % (self.id,
self.created.strftime("%d %b %Y"))
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"))
matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière"))
date = models.DateTimeField(_(u"Date d'attribution"), auto_now_add=True)
2013-10-06 11:20:59 +02:00
rank = models.IntegerField("Rang dans l'email")
2016-06-17 13:26:55 +02:00
selected = models.BooleanField(_(u"Sélectionné par le demandeur"),
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"
def __unicode__(self):
2016-06-17 13:26:55 +02:00
return u"Attribution de la demande %d à %s pour %s" \
% (self.demande.id, self.user.username, self.matiere)
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"
def __unicode__(self):
2016-06-17 13:26:55 +02:00
return u"%d demandes envoyées à %s pour %s" \
% (self.count, self.user.username, self.matiere)