ee1f29b17d
Rmeove the is_cof flag to check permission and start implementing a group and a permission for the respective cof members. XXX. note: migrations do NOT add old is_cof members to the new group (as actually they're just on the tests…)
270 lines
8.8 KiB
Python
270 lines
8.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import models
|
|
from django.dispatch import receiver
|
|
from django.contrib.auth.models import Group, Permission, User
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
import django.utils.six as six
|
|
from django.db.models.signals import post_save, post_delete
|
|
|
|
from gestion.models import Profile
|
|
from bda.models import Spectacle
|
|
|
|
from .petits_cours_models import choices_length
|
|
|
|
TYPE_COTIZ_CHOICES = (
|
|
('etudiant', _("Normalien étudiant")),
|
|
('normalien', _("Normalien élève")),
|
|
('exterieur', _("Extérieur")),
|
|
)
|
|
|
|
TYPE_COMMENT_FIELD = (
|
|
('text', _("Texte long")),
|
|
('char', _("Texte court")),
|
|
)
|
|
|
|
|
|
class CofProfile(models.Model):
|
|
profile = models.OneToOneField(Profile,
|
|
on_delete=models.CASCADE,
|
|
related_name="cof")
|
|
|
|
num = models.IntegerField("Numéro d'adhérent", blank=True, default=0)
|
|
type_cotiz = models.CharField(_("Type de cotisation"),
|
|
default="normalien",
|
|
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 use django auth.
|
|
is_buro = models.BooleanField("Membre du Burô", 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(
|
|
_("Remarques et précisions pour les petits cours"),
|
|
blank=True, default="")
|
|
|
|
|
|
# is_cof = models.BooleanField("Membre du COF", default=False)
|
|
@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.groups.add(g)
|
|
|
|
|
|
class Meta:
|
|
verbose_name = "Profil COF"
|
|
verbose_name_plural = "Profils COF"
|
|
|
|
def __str__(self):
|
|
return self.profile.user.username
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class Club(models.Model):
|
|
name = models.CharField("Nom", max_length=200, unique=True)
|
|
description = models.TextField("Description", blank=True)
|
|
respos = models.ManyToManyField(User, related_name="clubs_geres",
|
|
blank=True)
|
|
membres = models.ManyToManyField(User, related_name="clubs", blank=True)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class CustomMail(models.Model):
|
|
shortname = models.SlugField(max_length=50, blank=False)
|
|
title = models.CharField("Titre", max_length=200, blank=False)
|
|
content = models.TextField("Contenu", blank=False)
|
|
comments = models.TextField("Informations contextuelles sur le mail",
|
|
blank=True)
|
|
|
|
class Meta:
|
|
verbose_name = "Mail personnalisable"
|
|
verbose_name_plural = "Mails personnalisables"
|
|
|
|
def __str__(self):
|
|
return "%s: %s" % (self.shortname, self.title)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class Event(models.Model):
|
|
title = models.CharField("Titre", max_length=200)
|
|
location = models.CharField("Lieu", max_length=200)
|
|
start_date = models.DateTimeField("Date de début", blank=True, null=True)
|
|
end_date = models.DateTimeField("Date de fin", blank=True, null=True)
|
|
description = models.TextField("Description", blank=True)
|
|
image = models.ImageField("Image", blank=True, null=True,
|
|
upload_to="imgs/events/")
|
|
registration_open = models.BooleanField("Inscriptions ouvertes",
|
|
default=True)
|
|
old = models.BooleanField("Archiver (événement fini)", default=False)
|
|
|
|
class Meta:
|
|
verbose_name = "Événement"
|
|
|
|
def __str__(self):
|
|
return six.text_type(self.title)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventCommentField(models.Model):
|
|
event = models.ForeignKey(Event, related_name="commentfields")
|
|
name = models.CharField("Champ", max_length=200)
|
|
fieldtype = models.CharField("Type", max_length=10,
|
|
choices=TYPE_COMMENT_FIELD, default="text")
|
|
default = models.TextField("Valeur par défaut", blank=True)
|
|
|
|
class Meta:
|
|
verbose_name = "Champ"
|
|
|
|
def __str__(self):
|
|
return six.text_type(self.name)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventCommentValue(models.Model):
|
|
commentfield = models.ForeignKey(EventCommentField, related_name="values")
|
|
registration = models.ForeignKey("EventRegistration",
|
|
related_name="comments")
|
|
content = models.TextField("Contenu", blank=True, null=True)
|
|
|
|
def __str__(self):
|
|
return "Commentaire de %s" % self.commentfield
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventOption(models.Model):
|
|
event = models.ForeignKey(Event, related_name="options")
|
|
name = models.CharField("Option", max_length=200)
|
|
multi_choices = models.BooleanField("Choix multiples", default=False)
|
|
|
|
class Meta:
|
|
verbose_name = "Option"
|
|
|
|
def __str__(self):
|
|
return six.text_type(self.name)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventOptionChoice(models.Model):
|
|
event_option = models.ForeignKey(EventOption, related_name="choices")
|
|
value = models.CharField("Valeur", max_length=200)
|
|
|
|
class Meta:
|
|
verbose_name = "Choix"
|
|
verbose_name_plural = "Choix"
|
|
|
|
def __str__(self):
|
|
return six.text_type(self.value)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class EventRegistration(models.Model):
|
|
user = models.ForeignKey(User)
|
|
event = models.ForeignKey(Event)
|
|
options = models.ManyToManyField(EventOptionChoice)
|
|
filledcomments = models.ManyToManyField(EventCommentField,
|
|
through=EventCommentValue)
|
|
paid = models.BooleanField("A payé", default=False)
|
|
|
|
class Meta:
|
|
verbose_name = "Inscription"
|
|
unique_together = ("user", "event")
|
|
|
|
def __str__(self):
|
|
return "Inscription de %s à %s" % (six.text_type(self.user),
|
|
six.text_type(self.event.title))
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
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)
|
|
|
|
class Meta:
|
|
verbose_name = "Sondage"
|
|
|
|
def __str__(self):
|
|
return six.text_type(self.title)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
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 __str__(self):
|
|
return six.text_type(self.question)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
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 __str__(self):
|
|
return six.text_type(self.answer)
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class SurveyAnswer(models.Model):
|
|
user = models.ForeignKey(User)
|
|
survey = models.ForeignKey(Survey)
|
|
answers = models.ManyToManyField(SurveyQuestionAnswer,
|
|
related_name="selected_by")
|
|
|
|
class Meta:
|
|
verbose_name = "Réponses"
|
|
unique_together = ("user", "survey")
|
|
|
|
def __str__(self):
|
|
return "Réponse de %s sondage %s" % (
|
|
self.user.get_full_name(),
|
|
self.survey.title)
|
|
|
|
|
|
#XXX. this needs to be removed according to Martin
|
|
class Clipper(models.Model):
|
|
username = models.CharField("Identifiant", max_length=20)
|
|
fullname = models.CharField("Nom complet", max_length=200)
|
|
|
|
def __str__(self):
|
|
return "Clipper %s" % self.username
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class CalendarSubscription(models.Model):
|
|
token = models.UUIDField()
|
|
user = models.OneToOneField(User)
|
|
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()
|