2018-10-06 12:35:49 +02:00
|
|
|
from django.contrib.auth.models import User
|
2012-06-27 23:28:35 +02:00
|
|
|
from django.db import models
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.db.models.signals import post_delete, post_save
|
2017-01-04 22:32:50 +01:00
|
|
|
from django.dispatch import receiver
|
2012-06-27 23:28:35 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-15 01:06:33 +02:00
|
|
|
from bda.models import Spectacle
|
2019-06-26 18:57:16 +02:00
|
|
|
from shared.utils import choices_length
|
2016-07-15 01:06:33 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
TYPE_COMMENT_FIELD = (("text", _("Texte long")), ("char", _("Texte court")))
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class CofProfile(models.Model):
|
2017-10-02 13:58:52 +02:00
|
|
|
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")),
|
|
|
|
)
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")
|
2019-01-14 22:46:16 +01:00
|
|
|
login_clipper = models.CharField(
|
|
|
|
"Login clipper", max_length=32, blank=True, unique=True, null=True
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
is_cof = models.BooleanField("Membre du COF", default=False)
|
|
|
|
phone = models.CharField("Téléphone", max_length=20, blank=True)
|
2018-10-06 12:35:49 +02:00
|
|
|
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),
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
mailing_cof = models.BooleanField("Recevoir les mails COF", default=False)
|
|
|
|
mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False)
|
2018-10-06 12:35:49 +02:00
|
|
|
mailing_unernestaparis = models.BooleanField(
|
|
|
|
"Recevoir les mails unErnestAParis", default=False
|
|
|
|
)
|
2016-07-09 22:31:56 +02:00
|
|
|
mailing_bda_revente = models.BooleanField(
|
2018-10-06 12:35:49 +02:00
|
|
|
"Recevoir les mails de revente de places BdA", default=False
|
|
|
|
)
|
|
|
|
comments = models.TextField("Commentaires visibles par l'utilisateur", blank=True)
|
2016-07-09 21:19:37 +02:00
|
|
|
is_buro = models.BooleanField("Membre du Burô", default=False)
|
2016-07-09 22:31:56 +02:00
|
|
|
petits_cours_accept = models.BooleanField(
|
2018-10-06 12:35:49 +02:00
|
|
|
"Recevoir des petits cours", default=False
|
|
|
|
)
|
2016-07-09 22:31:56 +02:00
|
|
|
petits_cours_remarques = models.TextField(
|
2018-10-06 12:35:49 +02:00
|
|
|
_("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"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.user.username
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2017-01-04 22:37:03 +01:00
|
|
|
@receiver(post_save, sender=User)
|
2012-06-27 23:28:35 +02:00
|
|
|
def create_user_profile(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
2016-07-09 21:19:37 +02:00
|
|
|
CofProfile.objects.get_or_create(user=instance)
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2017-01-04 22:32:50 +01:00
|
|
|
@receiver(post_delete, sender=CofProfile)
|
|
|
|
def post_delete_user(sender, instance, *args, **kwargs):
|
|
|
|
instance.user.delete()
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class Club(models.Model):
|
2016-08-23 17:40:24 +02:00
|
|
|
name = models.CharField("Nom", max_length=200, unique=True)
|
|
|
|
description = models.TextField("Description", blank=True)
|
2018-10-06 12:35:49 +02:00
|
|
|
respos = models.ManyToManyField(User, related_name="clubs_geres", blank=True)
|
2016-08-23 17:40:24 +02:00
|
|
|
membres = models.ManyToManyField(User, related_name="clubs", blank=True)
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-07-15 20:01:45 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class Event(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
title = models.CharField("Titre", max_length=200)
|
|
|
|
location = models.CharField("Lieu", max_length=200)
|
2016-07-15 01:06:33 +02:00
|
|
|
start_date = models.DateTimeField("Date de début", blank=True, null=True)
|
|
|
|
end_date = models.DateTimeField("Date de fin", blank=True, null=True)
|
2016-07-09 21:19:37 +02:00
|
|
|
description = models.TextField("Description", blank=True)
|
2018-10-06 12:35:49 +02:00
|
|
|
image = models.ImageField("Image", blank=True, null=True, upload_to="imgs/events/")
|
|
|
|
registration_open = models.BooleanField("Inscriptions ouvertes", default=True)
|
2016-07-09 21:19:37 +02:00
|
|
|
old = models.BooleanField("Archiver (événement fini)", default=False)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Événement"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.title
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class EventCommentField(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
event = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
Event, on_delete=models.CASCADE, related_name="commentfields"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
name = models.CharField("Champ", max_length=200)
|
2018-10-06 12:35:49 +02:00
|
|
|
fieldtype = models.CharField(
|
|
|
|
"Type", max_length=10, choices=TYPE_COMMENT_FIELD, default="text"
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
default = models.TextField("Valeur par défaut", blank=True)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Champ"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.name
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class EventCommentValue(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
commentfield = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
EventCommentField, on_delete=models.CASCADE, related_name="values"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
|
|
|
registration = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
"EventRegistration", on_delete=models.CASCADE, related_name="comments"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
content = models.TextField("Contenu", blank=True, null=True)
|
|
|
|
|
2016-07-15 20:01:45 +02:00
|
|
|
def __str__(self):
|
|
|
|
return "Commentaire de %s" % self.commentfield
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventOption(models.Model):
|
2018-10-06 12:35:49 +02:00
|
|
|
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="options")
|
2016-07-09 21:19:37 +02:00
|
|
|
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"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.name
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventOptionChoice(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
event_option = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
EventOption, on_delete=models.CASCADE, related_name="choices"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
value = models.CharField("Valeur", max_length=200)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Choix"
|
2016-07-15 02:49:56 +02:00
|
|
|
verbose_name_plural = "Choix"
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.value
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventRegistration(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
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)
|
2018-10-06 12:35:49 +02:00
|
|
|
filledcomments = models.ManyToManyField(
|
|
|
|
EventCommentField, through=EventCommentValue
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
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)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class Survey(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
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"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.title
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestion(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
survey = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
Survey, on_delete=models.CASCADE, related_name="questions"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
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"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.question
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestionAnswer(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
survey_question = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
SurveyQuestion, on_delete=models.CASCADE, related_name="answers"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
answer = models.CharField("Réponse", max_length=200)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Réponse"
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-05-22 00:39:36 +02:00
|
|
|
return self.answer
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyAnswer(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
|
|
survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
|
2018-10-06 12:35:49 +02:00
|
|
|
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")
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-15 20:01:45 +02:00
|
|
|
def __str__(self):
|
|
|
|
return "Réponse de %s sondage %s" % (
|
2018-10-06 12:35:49 +02:00
|
|
|
self.user.get_full_name(),
|
|
|
|
self.survey.title,
|
|
|
|
)
|
2016-07-15 20:01:45 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-07-15 01:06:33 +02:00
|
|
|
class CalendarSubscription(models.Model):
|
2016-07-15 23:31:26 +02:00
|
|
|
token = models.UUIDField()
|
2017-11-19 18:41:39 +01:00
|
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
2016-07-16 01:51:20 +02:00
|
|
|
other_shows = models.ManyToManyField(Spectacle)
|
2016-07-15 02:49:56 +02:00
|
|
|
subscribe_to_events = models.BooleanField(default=True)
|
2016-07-16 01:51:20 +02:00
|
|
|
subscribe_to_my_shows = models.BooleanField(default=True)
|
2016-07-16 18:28:20 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Calendrier de %s" % self.user.get_full_name()
|