kpsul/gestioncof/models.py

266 lines
8.4 KiB
Python
Raw Normal View History

from django.contrib.auth.models import User
2012-06-27 23:28:35 +02:00
from django.db import models
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
2012-06-27 23:28:35 +02:00
from django.utils.translation import ugettext_lazy as _
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
2018-11-25 00:37:22 +01:00
from petitscours.models import choices_length
from bda.models import Spectacle
TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court")))
2012-06-27 23:28:35 +02:00
class CofProfile(models.Model):
STATUS_EXTE = "exterieur"
STATUS_1A = "1A"
STATUS_2A = "2A"
STATUS_3A = "3A"
STATUS_4A = "4A"
STATUS_ARCHI = "archicube"
STATUS_DOCTORANT = "doctorant"
STATUS_CST = "CST"
STATUS_PEI = "PEI"
OCCUPATION_CHOICES = (
(STATUS_EXTE, _("Extérieur")),
(STATUS_1A, _("1A")),
(STATUS_2A, _("2A")),
(STATUS_3A, _("3A")),
(STATUS_4A, _("4A")),
(STATUS_ARCHI, _("Archicube")),
(STATUS_DOCTORANT, _("Doctorant")),
(STATUS_CST, _("CST")),
(STATUS_PEI, _("PEI")),
)
COTIZ_ETUDIANT = "etudiant"
COTIZ_NORMALIEN = "normalien"
COTIZ_EXTE = "exterieur"
COTIZ_GRATIS = "gratis"
TYPE_COTIZ_CHOICES = (
(COTIZ_ETUDIANT, _("Normalien étudiant")),
(COTIZ_NORMALIEN, _("Normalien élève")),
(COTIZ_EXTE, _("Extérieur")),
(COTIZ_GRATIS, _("Gratuit")),
)
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
login_clipper = models.CharField("Login clipper", max_length=32, blank=True)
is_cof = models.BooleanField("Membre du COF", default=False)
phone = models.CharField("Téléphone", max_length=20, blank=True)
occupation = models.CharField(
_("Occupation"),
default="1A",
choices=OCCUPATION_CHOICES,
max_length=choices_length(OCCUPATION_CHOICES),
)
departement = models.CharField(_("Département"), max_length=50, blank=True)
type_cotiz = models.CharField(
_("Type de cotisation"),
default="normalien",
choices=TYPE_COTIZ_CHOICES,
max_length=choices_length(TYPE_COTIZ_CHOICES),
)
mailing_cof = models.BooleanField("Recevoir les mails COF", default=False)
mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False)
mailing_unernestaparis = models.BooleanField(
"Recevoir les mails unErnestAParis", default=False
)
mailing_bda_revente = models.BooleanField(
"Recevoir les mails de revente de places BdA", default=False
)
comments = models.TextField("Commentaires visibles par l'utilisateur", blank=True)
is_buro = models.BooleanField("Membre du Burô", default=False)
petits_cours_accept = models.BooleanField(
"Recevoir des petits cours", default=False
)
petits_cours_remarques = models.TextField(
_("Remarques et précisions pour les petits cours"), blank=True, default=""
)
2012-06-27 23:28:35 +02:00
2012-07-11 17:39:20 +02:00
class Meta:
verbose_name = "Profil COF"
verbose_name_plural = "Profils COF"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.user.username
2012-07-11 17:39:20 +02:00
@receiver(post_save, sender=User)
2012-06-27 23:28:35 +02:00
def create_user_profile(sender, instance, created, **kwargs):
if created:
CofProfile.objects.get_or_create(user=instance)
2012-06-27 23:28:35 +02:00
@receiver(post_delete, sender=CofProfile)
def post_delete_user(sender, instance, *args, **kwargs):
instance.user.delete()
2012-06-27 23:28:35 +02:00
class Club(models.Model):
name = models.CharField("Nom", max_length=200, unique=True)
description = models.TextField("Description", blank=True)
respos = models.ManyToManyField(User, related_name="clubs_geres", blank=True)
membres = models.ManyToManyField(User, related_name="clubs", blank=True)
def __str__(self):
return self.name
2012-06-27 23:28:35 +02:00
class Event(models.Model):
title = models.CharField("Titre", max_length=200)
location = models.CharField("Lieu", max_length=200)
start_date = models.DateTimeField("Date de début", blank=True, null=True)
end_date = models.DateTimeField("Date de fin", blank=True, null=True)
description = models.TextField("Description", blank=True)
image = models.ImageField("Image", blank=True, null=True, upload_to="imgs/events/")
registration_open = models.BooleanField("Inscriptions ouvertes", default=True)
old = models.BooleanField("Archiver (événement fini)", default=False)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Événement"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.title
2012-06-27 23:28:35 +02:00
class EventCommentField(models.Model):
event = models.ForeignKey(
Event, on_delete=models.CASCADE, related_name="commentfields"
)
name = models.CharField("Champ", max_length=200)
fieldtype = models.CharField(
"Type", max_length=10, choices=TYPE_COMMENT_FIELD, default="text"
)
default = models.TextField("Valeur par défaut", blank=True)
class Meta:
verbose_name = "Champ"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.name
class EventCommentValue(models.Model):
commentfield = models.ForeignKey(
EventCommentField, on_delete=models.CASCADE, related_name="values"
)
registration = models.ForeignKey(
"EventRegistration", on_delete=models.CASCADE, related_name="comments"
)
content = models.TextField("Contenu", blank=True, null=True)
def __str__(self):
return "Commentaire de %s" % self.commentfield
2012-06-27 23:28:35 +02:00
class EventOption(models.Model):
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="options")
name = models.CharField("Option", max_length=200)
multi_choices = models.BooleanField("Choix multiples", default=False)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Option"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.name
2012-06-27 23:28:35 +02:00
2012-06-27 23:28:35 +02:00
class EventOptionChoice(models.Model):
event_option = models.ForeignKey(
EventOption, on_delete=models.CASCADE, related_name="choices"
)
value = models.CharField("Valeur", max_length=200)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Choix"
verbose_name_plural = "Choix"
2012-06-27 23:28:35 +02:00
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.value
2012-06-27 23:28:35 +02:00
2012-06-27 23:28:35 +02:00
class EventRegistration(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
event = models.ForeignKey(Event, on_delete=models.CASCADE)
2012-06-27 23:28:35 +02:00
options = models.ManyToManyField(EventOptionChoice)
filledcomments = models.ManyToManyField(
EventCommentField, through=EventCommentValue
)
paid = models.BooleanField("A payé", default=False)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Inscription"
2012-07-11 17:39:20 +02:00
unique_together = ("user", "event")
2012-06-27 23:28:35 +02:00
2016-07-15 00:02:56 +02:00
def __str__(self):
2017-05-22 00:39:36 +02:00
return "Inscription de {} à {}".format(self.user, self.event.title)
2012-06-27 23:28:35 +02:00
class Survey(models.Model):
title = models.CharField("Titre", max_length=200)
details = models.TextField("Détails", blank=True)
survey_open = models.BooleanField("Sondage ouvert", default=True)
old = models.BooleanField("Archiver (sondage fini)", default=False)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Sondage"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.title
2012-06-27 23:28:35 +02:00
2012-06-27 23:28:35 +02:00
class SurveyQuestion(models.Model):
survey = models.ForeignKey(
Survey, on_delete=models.CASCADE, related_name="questions"
)
question = models.CharField("Question", max_length=200)
multi_answers = models.BooleanField("Choix multiples", default=False)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Question"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.question
2012-06-27 23:28:35 +02:00
2012-06-27 23:28:35 +02:00
class SurveyQuestionAnswer(models.Model):
survey_question = models.ForeignKey(
SurveyQuestion, on_delete=models.CASCADE, related_name="answers"
)
answer = models.CharField("Réponse", max_length=200)
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Réponse"
def __str__(self):
2017-05-22 00:39:36 +02:00
return self.answer
2012-06-27 23:28:35 +02:00
2012-06-27 23:28:35 +02:00
class SurveyAnswer(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
answers = models.ManyToManyField(SurveyQuestionAnswer, related_name="selected_by")
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Réponses"
2012-07-11 17:39:20 +02:00
unique_together = ("user", "survey")
def __str__(self):
return "Réponse de %s sondage %s" % (
self.user.get_full_name(),
self.survey.title,
)
class CalendarSubscription(models.Model):
token = models.UUIDField()
user = models.OneToOneField(User, on_delete=models.CASCADE)
other_shows = models.ManyToManyField(Spectacle)
subscribe_to_events = models.BooleanField(default=True)
subscribe_to_my_shows = models.BooleanField(default=True)
def __str__(self):
return "Calendrier de %s" % self.user.get_full_name()