2016-09-30 20:10:35 +02:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django.core import exceptions
|
|
|
|
from django.db import models
|
|
|
|
from re import search as re_search
|
|
|
|
|
|
|
|
|
|
|
|
def validate_color(value):
|
|
|
|
def is_hex_color(s):
|
|
|
|
return re_search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', s)
|
|
|
|
if not is_hex_color(value):
|
|
|
|
raise exceptions.ValidationError(
|
|
|
|
_("%(value)s n'est pas une couleur"),
|
|
|
|
code='invalid_choice',
|
|
|
|
params={'value': value},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Event(models.Model):
|
|
|
|
title = models.CharField(
|
|
|
|
_("Nom de l'évènement"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Identificateur'),
|
|
|
|
unique=True,
|
|
|
|
primary_key=True,
|
|
|
|
help_text=_("Seulement des lettres, des chiffres ou \
|
|
|
|
les caractères '_' ou '-'."),
|
|
|
|
)
|
|
|
|
created_by = models.ForeignKey(
|
|
|
|
User,
|
2016-10-03 00:31:21 +02:00
|
|
|
related_name="created_events",
|
2016-09-30 20:10:35 +02:00
|
|
|
editable=False,
|
|
|
|
)
|
|
|
|
creation_date = models.DateTimeField(
|
|
|
|
_('Date de création'),
|
|
|
|
auto_now_add=True,
|
|
|
|
)
|
|
|
|
description = models.TextField(_('Description'))
|
|
|
|
beginning_date = models.DateTimeField(_('Date de début'))
|
|
|
|
ending_date = models.DateTimeField(_('Date de fin'))
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Évènement")
|
|
|
|
verbose_name_plural = _("Évènements")
|
|
|
|
|
2016-10-03 00:31:21 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2016-09-30 20:10:35 +02:00
|
|
|
|
|
|
|
class Place(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
_("Nom du lieu"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
description = models.TextField(blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Lieu")
|
|
|
|
verbose_name_plural = _("Lieux")
|
|
|
|
|
2016-10-03 00:31:21 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2016-09-30 20:10:35 +02:00
|
|
|
|
|
|
|
class ActivityTag(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
_("Nom du tag"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
is_public = models.BooleanField(
|
|
|
|
help_text=_("TODO"),
|
|
|
|
)
|
|
|
|
color = models.CharField(
|
|
|
|
_('Couleur'),
|
|
|
|
max_length=7,
|
|
|
|
validators=[validate_color],
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Tag")
|
|
|
|
verbose_name_plural = _("Tags")
|
|
|
|
|
2016-10-03 00:31:21 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2016-09-30 20:10:35 +02:00
|
|
|
|
|
|
|
class ActivityTemplate(models.Model):
|
|
|
|
title = models.CharField(
|
|
|
|
_("Nom de l'activité"),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
is_public = models.NullBooleanField(
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
has_perm = models.NullBooleanField(
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
min_perm = models.PositiveSmallIntegerField(
|
|
|
|
_('Nombre minimum de permanents'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
max_perm = models.PositiveSmallIntegerField(
|
|
|
|
_('Nombre maximum de permanents'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
description = models.TextField(
|
|
|
|
_('Description'),
|
|
|
|
help_text=_("Public, Visible par tout le monde."),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
remarks = models.TextField(
|
|
|
|
_('Remarques'),
|
|
|
|
help_text=_("Visible uniquement par les organisateurs"),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
tags = models.ManyToManyField(
|
|
|
|
ActivityTag,
|
2016-10-03 00:31:21 +02:00
|
|
|
related_name="activities",
|
2016-09-30 20:10:35 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
place = models.ManyToManyField(
|
|
|
|
Place,
|
2016-10-03 00:31:21 +02:00
|
|
|
related_name="activities",
|
2016-09-30 20:10:35 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Template activité")
|
|
|
|
verbose_name_plural = _("Templates activité")
|
|
|
|
|
2016-10-03 00:31:21 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2016-09-30 20:10:35 +02:00
|
|
|
|
|
|
|
class Activity(ActivityTemplate):
|
|
|
|
parent = models.ForeignKey(
|
|
|
|
ActivityTemplate,
|
2016-10-03 00:31:21 +02:00
|
|
|
related_name="children",
|
2016-09-30 20:10:35 +02:00
|
|
|
)
|
|
|
|
staff = models.ManyToManyField(
|
|
|
|
User,
|
2016-10-03 00:31:21 +02:00
|
|
|
related_name="in_perm_activities",
|
2016-09-30 20:10:35 +02:00
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
# TODO : Utiliser db_constraint ou through
|
|
|
|
# equipement = models.ManyToManyField(Equipement)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Activité")
|
|
|
|
verbose_name_plural = _("Activités")
|
|
|
|
|
2016-10-03 00:31:21 +02:00
|
|
|
# Si le champ de l'activité n'est pas spécifié
|
|
|
|
# alors on va chercher celui de self.parent
|
2016-09-30 20:10:35 +02:00
|
|
|
def __getattr__(self, attrname):
|
2016-10-03 00:31:21 +02:00
|
|
|
attr = super(Activity, self).__getattr__(attrname)
|
2016-09-30 20:10:35 +02:00
|
|
|
if (attrname == 'parent'
|
2016-10-03 00:31:21 +02:00
|
|
|
or attrname == 'staff'
|
2016-09-30 20:10:35 +02:00
|
|
|
or attrname == 'equipement'):
|
2016-10-03 00:31:21 +02:00
|
|
|
return attr
|
|
|
|
elif attr is None:
|
|
|
|
return self.parent.__getattr__(attrname)
|
2016-09-30 20:10:35 +02:00
|
|
|
else:
|
2016-10-03 00:31:21 +02:00
|
|
|
return attr
|