2016-07-15 00:02:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
from django.db import models
|
2017-02-12 04:24:33 +01:00
|
|
|
from django.contrib.auth.models import Group, User
|
2012-06-27 23:28:35 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-05-26 22:44:10 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
import django.utils.six as six
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2017-09-05 15:02:33 +02:00
|
|
|
from gestion.models import Association, Profile
|
2016-07-15 01:06:33 +02:00
|
|
|
from bda.models import Spectacle
|
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
from .petits_cours_models import choices_length
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2017-09-05 15:02:33 +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")),
|
|
|
|
)
|
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
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"),
|
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))
|
2017-02-10 20:10:45 +01:00
|
|
|
mailing = models.BooleanField("Recevoir les mails COF", default=False)
|
|
|
|
# XXX. remove the following and put in a BDA profile
|
2016-07-09 21:19:37 +02:00
|
|
|
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)
|
2017-02-10 20:10:45 +01:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
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"),
|
2016-07-09 22:31:56 +02:00
|
|
|
blank=True, default="")
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2017-02-11 23:05:51 +01:00
|
|
|
class Meta:
|
|
|
|
verbose_name = "Profil COF"
|
|
|
|
verbose_name_plural = "Profils COF"
|
|
|
|
permissions = (
|
|
|
|
('member', 'Is a COF member'),
|
|
|
|
('buro', 'Is part of COF staff'),
|
|
|
|
)
|
|
|
|
|
2017-02-11 18:48:13 +01:00
|
|
|
@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')
|
2017-02-12 04:24:33 +01:00
|
|
|
self.profile.user.groups.add(g)
|
2017-02-11 18:48:13 +01:00
|
|
|
|
2017-02-11 23:05:51 +01:00
|
|
|
# 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')
|
2017-02-18 13:00:21 +01:00
|
|
|
self.profile.user.groups.add(g)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2017-02-11 18:48:13 +01:00
|
|
|
return self.profile.user.username
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
@python_2_unicode_compatible
|
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):
|
|
|
|
return six.text_type(self.title)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
@python_2_unicode_compatible
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestion(models.Model):
|
2017-02-22 19:28:34 +01:00
|
|
|
survey = models.ForeignKey(
|
|
|
|
Survey,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="questions"
|
|
|
|
)
|
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):
|
|
|
|
return six.text_type(self.question)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
@python_2_unicode_compatible
|
2012-06-27 23:28:35 +02:00
|
|
|
class SurveyQuestionAnswer(models.Model):
|
2017-02-22 19:28:34 +01:00
|
|
|
survey_question = models.ForeignKey(
|
|
|
|
SurveyQuestion,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="answers"
|
|
|
|
)
|
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):
|
|
|
|
return six.text_type(self.answer)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +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):
|
2017-02-22 19:28:34 +01:00
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE
|
|
|
|
)
|
|
|
|
survey = models.ForeignKey(
|
|
|
|
Survey,
|
|
|
|
on_delete=models.CASCADE
|
|
|
|
)
|
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-15 20:01:45 +02:00
|
|
|
def __str__(self):
|
|
|
|
return "Réponse de %s sondage %s" % (
|
|
|
|
self.user.get_full_name(),
|
|
|
|
self.survey.title)
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-07-16 18:28:20 +02:00
|
|
|
@python_2_unicode_compatible
|
2016-07-15 01:06:33 +02:00
|
|
|
class CalendarSubscription(models.Model):
|
2016-07-15 23:31:26 +02:00
|
|
|
token = models.UUIDField()
|
2017-02-22 19:28:34 +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()
|