2017-02-20 01:12:06 +01:00
|
|
|
from django.contrib.auth.models import User, Group
|
2017-02-09 21:04:32 +01:00
|
|
|
from django.db import models
|
2017-02-10 20:10:45 +01:00
|
|
|
from django.dispatch import receiver
|
|
|
|
from django.db.models.signals import post_save, post_delete
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-02-09 21:04:32 +01:00
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
from cof.petits_cours_models import choices_length
|
|
|
|
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# User management
|
|
|
|
# ---
|
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
OCCUPATION_CHOICES = (
|
|
|
|
('exterieur', _("Extérieur")),
|
|
|
|
('1A', _("1A")),
|
|
|
|
('2A', _("2A")),
|
|
|
|
('3A', _("3A")),
|
|
|
|
('4A', _("4A")),
|
|
|
|
('archicube', _("Archicube")),
|
|
|
|
('doctorant', _("Doctorant")),
|
|
|
|
('CST', _("CST")),
|
|
|
|
)
|
|
|
|
|
2017-02-20 01:12:06 +01:00
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
class Profile(models.Model):
|
2017-02-22 19:28:34 +01:00
|
|
|
user = models.OneToOneField(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
2017-06-24 14:42:33 +02:00
|
|
|
related_name="profile",
|
|
|
|
verbose_name=_("utilisateur"),
|
2017-02-22 19:28:34 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
login_clipper = models.CharField(
|
|
|
|
_("login clipper"),
|
|
|
|
max_length=8,
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
phone = models.CharField(_("téléphone"), max_length=20, blank=True)
|
|
|
|
occupation = models.CharField(_("occupation"),
|
2017-02-10 20:10:45 +01:00
|
|
|
default="1A",
|
|
|
|
choices=OCCUPATION_CHOICES,
|
|
|
|
max_length=choices_length(
|
|
|
|
OCCUPATION_CHOICES))
|
2017-06-24 14:42:33 +02:00
|
|
|
departement = models.CharField(_("département"), max_length=50,
|
2017-02-10 20:10:45 +01:00
|
|
|
blank=True)
|
|
|
|
comments = models.TextField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("commentaires visibles par l'utilisateur"), blank=True
|
|
|
|
)
|
2017-02-10 20:10:45 +01:00
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("profil")
|
|
|
|
verbose_name_plural = _("profils")
|
2017-02-10 20:10:45 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|
|
|
|
|
2017-02-20 01:12:06 +01:00
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
@receiver(post_save, sender=User)
|
|
|
|
def create_user_profile(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
Profile.objects.get_or_create(user=instance)
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Profile)
|
|
|
|
def post_delete_user(sender, instance, *args, **kwargs):
|
|
|
|
instance.user.delete()
|
2017-02-20 01:12:06 +01:00
|
|
|
|
|
|
|
|
2017-06-24 23:35:25 +02:00
|
|
|
class Association(models.Model):
|
|
|
|
name = models.CharField(_("nom de l'association"), max_length=30)
|
|
|
|
staff_group = models.ForeignKey(
|
|
|
|
Group,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name="staff_groups",
|
|
|
|
blank=True, null=True,
|
|
|
|
verbose_name=_("groupe des membre du bureau"),
|
|
|
|
)
|
|
|
|
members_group = models.ForeignKey(
|
|
|
|
Group,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name="member_groups",
|
|
|
|
blank=True, null=True,
|
|
|
|
verbose_name=_("groupe des membres"),
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("association")
|
|
|
|
verbose_name_plural = _("associations")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2017-03-18 21:48:17 +01:00
|
|
|
# ---
|
|
|
|
# Clubs
|
|
|
|
# ---
|
|
|
|
|
2017-02-20 01:12:06 +01:00
|
|
|
class Club(models.Model):
|
|
|
|
ANNUAL = "ANN"
|
|
|
|
SEMESTER = "SEM"
|
|
|
|
COURSE = "COU"
|
|
|
|
|
|
|
|
COTISATION_FREQUENCY_CHOICES = [
|
|
|
|
(ANNUAL, _("Annuel")),
|
|
|
|
(SEMESTER, _("Semestriel")),
|
|
|
|
(COURSE, _("Au cours"))
|
|
|
|
]
|
|
|
|
|
2017-06-24 23:35:25 +02:00
|
|
|
association = models.ForeignKey(
|
|
|
|
Association,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name="clubs",
|
|
|
|
verbose_name=_("association"),
|
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
name = models.CharField(_("nom"), max_length=200, unique=True)
|
|
|
|
description = models.TextField("description", blank=True)
|
2017-02-20 01:12:06 +01:00
|
|
|
members = models.ManyToManyField(
|
|
|
|
User,
|
|
|
|
through="ClubUser",
|
|
|
|
related_name="in_clubs",
|
2017-06-24 14:42:33 +02:00
|
|
|
blank=True,
|
|
|
|
verbose_name=_("membres du club"),
|
2017-02-20 01:12:06 +01:00
|
|
|
)
|
|
|
|
price = models.DecimalField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("cotisation (€)"),
|
2017-02-20 01:12:06 +01:00
|
|
|
decimal_places=2,
|
|
|
|
max_digits=5,
|
|
|
|
blank=True,
|
|
|
|
default=0
|
|
|
|
)
|
|
|
|
cotisation_frequency = models.CharField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("fréquence de la cotisation"),
|
2017-02-20 01:12:06 +01:00
|
|
|
default=ANNUAL,
|
|
|
|
choices=COTISATION_FREQUENCY_CHOICES,
|
|
|
|
max_length=3,
|
|
|
|
blank=True
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
template = (
|
2017-06-24 14:42:33 +02:00
|
|
|
self.price
|
|
|
|
and _("%(name)s (%(price).2f€ / %(cotisation_frequency)s)")
|
|
|
|
or _("%(name)s")
|
2017-02-20 01:12:06 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
return template % vars(self)
|
2017-02-20 01:12:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ClubUser(models.Model):
|
2017-02-23 10:47:48 +01:00
|
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
|
|
club = models.ForeignKey(Club, on_delete=models.CASCADE)
|
2017-06-24 14:42:33 +02:00
|
|
|
is_respo = models.BooleanField(_("est responsable du club"))
|
|
|
|
has_paid = models.BooleanField(_("a payé sa cotisation"))
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Events
|
|
|
|
# ---
|
|
|
|
|
2017-04-11 03:48:39 +02:00
|
|
|
class Location(models.Model):
|
2017-06-24 14:42:33 +02:00
|
|
|
name = models.CharField(_("nom du lieux"), max_length=200)
|
2017-04-11 03:48:39 +02:00
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("lieu")
|
|
|
|
verbose_name_plural = _("lieux")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2017-04-11 03:48:39 +02:00
|
|
|
|
|
|
|
|
2017-03-18 21:48:17 +01:00
|
|
|
class Event(models.Model):
|
2017-06-24 14:42:33 +02:00
|
|
|
associations = models.ManyToManyField(
|
2017-06-24 23:35:25 +02:00
|
|
|
Association,
|
2017-06-24 14:42:33 +02:00
|
|
|
related_name="events",
|
|
|
|
verbose_name=_("associations"),
|
|
|
|
)
|
|
|
|
title = models.CharField(_("titre"), max_length=200)
|
|
|
|
location = models.ForeignKey(
|
|
|
|
Location,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
verbose_name=_("lieux"),
|
|
|
|
)
|
|
|
|
start_date = models.DateTimeField(
|
|
|
|
_("début de l'événement"),
|
|
|
|
blank=True, null=True,
|
|
|
|
)
|
|
|
|
end_date = models.DateTimeField(
|
|
|
|
_("fin de l'événement"),
|
|
|
|
blank=True, null=True,
|
|
|
|
)
|
|
|
|
description = models.TextField(_("description"), blank=True)
|
2017-03-18 21:48:17 +01:00
|
|
|
image = models.ImageField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("image"),
|
|
|
|
blank=True, null=True,
|
|
|
|
upload_to="public/imgs/events/",
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
|
|
|
registration_open = models.BooleanField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("les inscriptions sont ouvertes"),
|
|
|
|
default=True
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
old = models.BooleanField(_("archiver (événement fini)"), default=False)
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("événement")
|
|
|
|
verbose_name_plural = _("événements")
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
|
|
|
class EventCommentField(models.Model):
|
|
|
|
TEXT = "text"
|
|
|
|
CHAR = "char"
|
|
|
|
|
|
|
|
FIELD_TYPE = [
|
|
|
|
(TEXT, _("Texte long")),
|
|
|
|
(CHAR, _("Texte court")),
|
|
|
|
]
|
|
|
|
|
|
|
|
event = models.ForeignKey(
|
|
|
|
Event,
|
|
|
|
on_delete=models.CASCADE,
|
2017-06-24 14:42:33 +02:00
|
|
|
related_name="commentfields",
|
|
|
|
verbose_name=_("événement"),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
name = models.CharField(_("nom du champ"), max_length=200)
|
2017-03-18 21:48:17 +01:00
|
|
|
fieldtype = models.CharField(
|
2017-06-24 14:42:33 +02:00
|
|
|
_("type de champ"),
|
|
|
|
max_length=10,
|
|
|
|
choices=FIELD_TYPE, default=TEXT,
|
|
|
|
)
|
|
|
|
default = models.TextField(_("valeur par défaut"), blank=True)
|
|
|
|
ordering = models.IntegerField(
|
|
|
|
_("ordre des champs"),
|
|
|
|
help_text=_(
|
|
|
|
"plus petit en premier, ordre alphabétique sur le nom si "
|
|
|
|
"ambiguïté"
|
|
|
|
),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("champ")
|
|
|
|
verbose_name_plural = _("champs")
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class EventCommentValue(models.Model):
|
|
|
|
commentfield = models.ForeignKey(
|
|
|
|
EventCommentField,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="values"
|
|
|
|
)
|
|
|
|
registration = models.ForeignKey(
|
|
|
|
"EventRegistration",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="comments"
|
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
content = models.TextField(_("contenu"), blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ("commentfield", "registration")
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-06-24 14:42:33 +02:00
|
|
|
return (
|
|
|
|
_("Commentaire de %(field_name)s")
|
|
|
|
% {"field_name": self.commentfield}
|
|
|
|
)
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EventOption(models.Model):
|
|
|
|
event = models.ForeignKey(
|
|
|
|
Event,
|
|
|
|
on_delete=models.CASCADE,
|
2017-06-24 14:42:33 +02:00
|
|
|
related_name="options",
|
|
|
|
verbose_name=_("événement"),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
name = models.CharField(_("option"), max_length=200)
|
|
|
|
multi_choices = models.BooleanField(_("choix multiples"), default=False)
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("option des événements")
|
|
|
|
verbose_name_plural = _("options des événements")
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class EventOptionChoice(models.Model):
|
|
|
|
event_option = models.ForeignKey(
|
|
|
|
EventOption,
|
|
|
|
on_delete=models.CASCADE,
|
2017-06-24 14:42:33 +02:00
|
|
|
related_name="choices",
|
|
|
|
verbose_name=_("événement"),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
|
|
|
value = models.CharField("Valeur", max_length=200)
|
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("choix")
|
|
|
|
verbose_name_plural = _("choix")
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.value
|
|
|
|
|
|
|
|
|
|
|
|
class EventRegistration(models.Model):
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
2017-06-24 14:42:33 +02:00
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("utilisateur"),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
|
|
|
event = models.ForeignKey(
|
|
|
|
Event,
|
2017-06-24 14:42:33 +02:00
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("événement"),
|
|
|
|
)
|
|
|
|
options = models.ManyToManyField(
|
|
|
|
EventOptionChoice,
|
|
|
|
verbose_name=_("choix"),
|
2017-03-18 21:48:17 +01:00
|
|
|
)
|
2017-06-24 14:42:33 +02:00
|
|
|
filledcomments = models.ManyToManyField(
|
|
|
|
EventCommentField,
|
|
|
|
through=EventCommentValue,
|
|
|
|
verbose_name=_("commentaires"),
|
|
|
|
)
|
|
|
|
paid = models.BooleanField(_("a payé"), default=False)
|
2017-03-18 21:48:17 +01:00
|
|
|
|
|
|
|
class Meta:
|
2017-06-24 14:42:33 +02:00
|
|
|
verbose_name = _("inscription")
|
|
|
|
verbose_name_plural = _("inscriptions")
|
2017-03-18 21:48:17 +01:00
|
|
|
unique_together = ("user", "event")
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-06-24 14:42:33 +02:00
|
|
|
return (
|
|
|
|
_("Inscription de %(user)s à %(event)s")
|
|
|
|
% {"user": self.user, "event": self.event}
|
|
|
|
)
|