2012-06-27 23:28:35 +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 _
|
|
|
|
from django.db.models.signals import post_save
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
from petits_cours_models import *
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
OCCUPATION_CHOICES = (
|
|
|
|
('exterieur', _(u"Extérieur")),
|
|
|
|
('1A', _(u"1A")),
|
|
|
|
('2A', _(u"2A")),
|
|
|
|
('3A', _(u"3A")),
|
|
|
|
('4A', _(u"4A")),
|
|
|
|
('archicube', _(u"Archicube")),
|
|
|
|
('doctorant', _(u"Doctorant")),
|
|
|
|
('CST', _(u"CST")),
|
|
|
|
)
|
|
|
|
|
|
|
|
TYPE_COTIZ_CHOICES = (
|
2015-01-06 11:01:15 +01:00
|
|
|
('etudiant', _(u"Normalien étudiant")),
|
|
|
|
('normalien', _(u"Normalien élève")),
|
2012-06-27 23:28:35 +02:00
|
|
|
('exterieur', _(u"Extérieur")),
|
|
|
|
)
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
TYPE_COMMENT_FIELD = (
|
|
|
|
('text', _(u"Texte long")),
|
|
|
|
('char', _(u"Texte court")),
|
|
|
|
)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
|
|
|
def choices_length(choices):
|
|
|
|
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
class CofProfile(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
user = models.OneToOneField(User, related_name="profile")
|
|
|
|
login_clipper = models.CharField("Login clipper", max_length=8, blank=True)
|
|
|
|
is_cof = models.BooleanField("Membre du COF", default=False)
|
|
|
|
num = models.IntegerField("Numéro d'adhérent", blank=True, default=0)
|
|
|
|
phone = models.CharField("Téléphone", max_length=20, blank=True)
|
|
|
|
occupation = models.CharField(_(u"Occupation"),
|
2016-07-09 22:31:56 +02:00
|
|
|
default="1A",
|
|
|
|
choices=OCCUPATION_CHOICES,
|
|
|
|
max_length=choices_length(
|
|
|
|
OCCUPATION_CHOICES))
|
|
|
|
departement = models.CharField(_(u"Département"), max_length=50,
|
|
|
|
blank=True)
|
2016-07-09 21:19:37 +02:00
|
|
|
type_cotiz = models.CharField(_(u"Type de cotisation"),
|
2016-07-09 22:31:56 +02:00
|
|
|
default="normalien",
|
2016-07-10 14:24:58 +02:00
|
|
|
choices=TYPE_COTIZ_CHOICES,
|
2016-07-09 22:31:56 +02:00
|
|
|
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)
|
2016-07-09 22:31:56 +02:00
|
|
|
mailing_bda_revente = models.BooleanField(
|
|
|
|
"Recevoir les mails de revente de places BdA", default=False)
|
|
|
|
comments = models.TextField(
|
|
|
|
"Commentaires visibles uniquement par le Buro", 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(
|
|
|
|
"Recevoir des petits cours", default=False)
|
|
|
|
petits_cours_remarques = models.TextField(
|
|
|
|
_(u"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 __unicode__(self):
|
|
|
|
return unicode(self.user.username)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
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)
|
|
|
|
post_save.connect(create_user_profile, sender=User)
|
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class Club(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
name = models.CharField("Nom", max_length=200)
|
2014-08-19 12:54:22 +02:00
|
|
|
description = models.TextField("Description")
|
2016-07-09 21:19:37 +02:00
|
|
|
respos = models.ManyToManyField(User, related_name="clubs_geres")
|
|
|
|
membres = models.ManyToManyField(User, related_name="clubs")
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
class CustomMail(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
shortname = models.SlugField(max_length=50, blank=False)
|
|
|
|
title = models.CharField("Titre", max_length=200, blank=False)
|
|
|
|
content = models.TextField("Contenu", blank=False)
|
2016-07-09 22:31:56 +02:00
|
|
|
comments = models.TextField("Informations contextuelles sur le mail",
|
|
|
|
blank=True)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Mails personnalisables"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s: %s" % (self.shortname, self.title)
|
|
|
|
|
2016-07-09 21:19:37 +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)
|
|
|
|
start_date = models.DateField("Date de début", blank=True, null=True)
|
|
|
|
end_date = models.DateField("Date de fin", blank=True, null=True)
|
|
|
|
description = models.TextField("Description", blank=True)
|
2016-07-09 19:42:45 +02:00
|
|
|
image = models.ImageField("Image", blank=True, null=True,
|
|
|
|
upload_to="imgs/events/")
|
2016-07-09 22:31:56 +02:00
|
|
|
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"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.title)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class EventCommentField(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
event = models.ForeignKey(Event, related_name="commentfields")
|
|
|
|
name = models.CharField("Champ", max_length=200)
|
2016-07-09 22:31:56 +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"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.name)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
class EventCommentValue(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
commentfield = models.ForeignKey(EventCommentField, related_name="values")
|
2016-07-09 22:31:56 +02:00
|
|
|
registration = models.ForeignKey("EventRegistration",
|
|
|
|
related_name="comments")
|
2016-07-09 21:19:37 +02:00
|
|
|
content = models.TextField("Contenu", blank=True, null=True)
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventOption(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
event = models.ForeignKey(Event, 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 __unicode__(self):
|
|
|
|
return unicode(self.name)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventOptionChoice(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
event_option = models.ForeignKey(EventOption, related_name="choices")
|
|
|
|
value = models.CharField("Valeur", max_length=200)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Choix"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.value)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class EventRegistration(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
|
|
|
event = models.ForeignKey(Event)
|
|
|
|
options = models.ManyToManyField(EventOptionChoice)
|
2016-07-09 22:31:56 +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
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def __unicode__(self):
|
2016-07-09 22:31:56 +02:00
|
|
|
return u"Inscription de %s à %s" % (unicode(self.user),
|
|
|
|
unicode(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"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.title)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestion(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
survey = models.ForeignKey(Survey, 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 __unicode__(self):
|
|
|
|
return unicode(self.question)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestionAnswer(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
survey_question = models.ForeignKey(SurveyQuestion, 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 __unicode__(self):
|
|
|
|
return unicode(self.answer)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyAnswer(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
|
|
|
survey = models.ForeignKey(Survey)
|
2016-07-09 22:31:56 +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-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
class Clipper(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
username = models.CharField("Identifiant", max_length=20)
|
|
|
|
fullname = models.CharField("Nom complet", max_length=200)
|