gestioCOF/gestioncof/models.py
Guillaume Seguin 8e1bf7b705 Initial import
2012-06-27 23:28:35 +02:00

130 lines
4.2 KiB
Python

# 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
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 = (
('etudiant', _(u"Étudiant")),
('normalien', _(u"Normalien")),
('exterieur', _(u"Extérieur")),
)
def choices_length (choices):
return reduce (lambda m, choice: max (m, len (choice[0])), choices, 0)
class CofProfile(models.Model):
user = models.OneToOneField(User)
login_clipper = models.CharField("Login clipper", max_length = 8)
is_cof = models.BooleanField("Membre du COF", default = False)
occupation = models.CharField (_(u"Occupation"),
default = "1A",
choices = OCCUPATION_CHOICES,
max_length = choices_length (OCCUPATION_CHOICES))
type_cotiz = models.CharField (_(u"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 = True)
mailing_bda_revente = models.BooleanField("Recevoir les mails de revente de places BDA", default = True)
is_buro = models.BooleanField("Membre du Burô", default = False)
def create_user_profile(sender, instance, created, **kwargs):
if created:
CofProfile.objects.create(user = instance)
post_save.connect(create_user_profile, sender = User)
class Event(models.Model):
title = models.CharField("Titre", max_length = 200)
location = models.CharField("Lieu", max_length = 200)
start_date = models.DateField("Date de début", blank = True)
end_date = models.DateField("Date de fin", blank = True)
description = models.TextField("Description", blank = True)
registration_open = models.BooleanField("Inscriptions ouvertes", default = True)
class Meta:
verbose_name = "Événement"
def __unicode__(self):
return unicode(self.title)
class EventOption(models.Model):
event = models.ForeignKey(Event)
name = models.CharField("Option", max_length = 200)
class Meta:
verbose_name = "Option"
def __unicode__(self):
return unicode(self.name)
class EventOptionChoice(models.Model):
event_option = models.ForeignKey(EventOption)
value = models.CharField("Valeur", max_length = 200)
class Meta:
verbose_name = "Choix"
def __unicode__(self):
return unicode(self.value)
class EventRegistration(models.Model):
user = models.ForeignKey(User)
event = models.ForeignKey(Event)
options = models.ManyToManyField(EventOptionChoice)
paid = models.BooleanField("A payé", default = False)
class Meta:
verbose_name = "Inscription"
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)
class Meta:
verbose_name = "Sondage"
def __unicode__(self):
return unicode(self.title)
class SurveyQuestion(models.Model):
survey = models.ForeignKey(Survey, related_name = "questions")
question = models.CharField("Question", max_length = 200)
multi_answers = models.BooleanField("Choix multiples", default = False)
class Meta:
verbose_name = "Question"
def __unicode__(self):
return unicode(self.question)
class SurveyQuestionAnswer(models.Model):
survey_question = models.ForeignKey(SurveyQuestion, related_name = "answers")
answer = models.CharField("Réponse", max_length = 200)
class Meta:
verbose_name = "Réponse"
def __unicode__(self):
return unicode(self.answer)
class SurveyAnswer(models.Model):
user = models.ForeignKey(User)
survey = models.ForeignKey(Survey)
answers = models.ManyToManyField(SurveyQuestionAnswer)
class Meta:
verbose_name = "Réponses"