gestioCOF/cof/models.py

168 lines
4.9 KiB
Python
Raw Normal View History

2016-07-15 00:02:56 +02:00
# -*- coding: utf-8 -*-
2012-06-27 23:28:35 +02:00
from django.db import models
from django.contrib.auth.models import Group, User
2012-06-27 23:28:35 +02:00
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
import django.utils.six as six
2012-06-27 23:28:35 +02:00
from gestion.models import Association, Profile
from bda.models import Spectacle
from .petits_cours_models import choices_length
2012-06-27 23:28:35 +02:00
def get_cof_assoc():
return Association.objects.get(name='COF')
2012-06-27 23:28:35 +02:00
class CofProfile(models.Model):
2017-10-26 14:04:15 +02:00
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")),
)
profile = models.OneToOneField(Profile,
on_delete=models.CASCADE,
related_name="cof")
2016-07-15 00:02:56 +02:00
type_cotiz = models.CharField(_("Type de cotisation"),
default="normalien",
2016-07-10 14:24:58 +02:00
choices=TYPE_COTIZ_CHOICES,
max_length=choices_length(
TYPE_COTIZ_CHOICES))
mailing = models.BooleanField("Recevoir les mails COF", default=False)
# XXX. remove the following and put in a BDA profile
mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False)
mailing_bda_revente = models.BooleanField(
"Recevoir les mails de revente de places BdA", default=False)
petits_cours_accept = models.BooleanField(
"Recevoir des petits cours", default=False)
petits_cours_remarques = models.TextField(
2016-07-10 10:46:45 +02:00
_("Remarques et précisions pour les petits cours"),
blank=True, default="")
2012-06-27 23:28:35 +02:00
class Meta:
verbose_name = "Profil COF"
verbose_name_plural = "Profils COF"
permissions = (
('member', 'Is a COF member'),
('buro', 'Is part of COF staff'),
)
@property
def is_cof(self):
return self.profile.user.has_perm('cof.member')
@is_cof.setter
def is_cof(self, really):
if really:
g = Group.objects.get(name='cof_members')
self.profile.user.groups.add(g)
# XXX. remove the following and use django auth.
@property
def is_buro(self):
return self.profile.user.has_perm('cof.buro')
@is_buro.setter
def is_buro(self, really):
if really:
g = Group.objects.get(name='cof_buro')
self.profile.user.groups.add(g)
2012-07-11 17:39:20 +02:00
def __str__(self):
return self.profile.user.username
2012-07-11 17:39:20 +02:00
@python_2_unicode_compatible
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):
return six.text_type(self.title)
2012-06-27 23:28:35 +02:00
@python_2_unicode_compatible
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):
return six.text_type(self.question)
2012-06-27 23:28:35 +02:00
@python_2_unicode_compatible
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):
return six.text_type(self.answer)
2012-06-27 23:28:35 +02:00
2016-07-15 00:02:56 +02:00
@python_2_unicode_compatible
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)
@python_2_unicode_compatible
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()