2016-09-30 20:10:35 +02:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-10-17 19:40:31 +02:00
|
|
|
from django.core.validators import RegexValidator
|
2016-10-21 18:49:46 +02:00
|
|
|
from django.core.exceptions import FieldError
|
2016-09-30 20:10:35 +02:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Event(models.Model):
|
|
|
|
title = models.CharField(
|
|
|
|
_("Nom de l'évènement"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Identificateur'),
|
|
|
|
unique=True,
|
|
|
|
primary_key=True,
|
2016-10-21 18:49:46 +02:00
|
|
|
help_text=_("Seulement des lettres, des chiffres ou"
|
|
|
|
"les caractères '_' ou '-'."),
|
2016-09-30 20:10:35 +02:00
|
|
|
)
|
|
|
|
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:
|
2016-10-13 11:51:41 +02:00
|
|
|
verbose_name = _("évènement")
|
|
|
|
verbose_name_plural = _("évènements")
|
2016-09-30 20:10:35 +02:00
|
|
|
|
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:
|
2016-10-13 11:51:41 +02:00
|
|
|
verbose_name = _("lieu")
|
|
|
|
verbose_name_plural = _("lieux")
|
2016-09-30 20:10:35 +02:00
|
|
|
|
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(
|
2016-10-17 20:06:00 +02:00
|
|
|
help_text=_("Sert à faire une distinction dans"
|
|
|
|
" l'affichage selon que cela soit"
|
|
|
|
" destiné au public ou à l'équipe"
|
|
|
|
" organisatrice"),
|
2016-09-30 20:10:35 +02:00
|
|
|
)
|
2016-10-17 19:40:31 +02:00
|
|
|
color_regex = RegexValidator(
|
|
|
|
regex=r'^#(?:[0-9a-fA-F]{3}){1,2}$',
|
2017-04-27 01:14:47 +02:00
|
|
|
message=_("La chaîne de caractère rentrée n'est pas"
|
2017-05-16 20:20:38 +02:00
|
|
|
" une couleur en hexadécimal."),
|
2016-10-17 19:40:31 +02:00
|
|
|
)
|
2016-09-30 20:10:35 +02:00
|
|
|
color = models.CharField(
|
|
|
|
_('Couleur'),
|
|
|
|
max_length=7,
|
2016-10-17 19:40:31 +02:00
|
|
|
validators=[color_regex],
|
2017-04-27 01:14:47 +02:00
|
|
|
help_text=_("Rentrer une couleur en hexadécimal"),
|
2016-09-30 20:10:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2016-10-13 11:51:41 +02:00
|
|
|
verbose_name = _("tag")
|
|
|
|
verbose_name_plural = _("tags")
|
2016-09-30 20:10:35 +02:00
|
|
|
|
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,
|
|
|
|
)
|
2016-10-13 11:51:41 +02:00
|
|
|
# FIXME: voir comment on traite l'héritage de `event`
|
|
|
|
event = models.ForeignKey(
|
|
|
|
Event,
|
|
|
|
related_name="activities",
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
2016-09-30 20:10:35 +02:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2016-10-13 11:51:41 +02:00
|
|
|
verbose_name = _("template activité")
|
|
|
|
verbose_name_plural = _("templates activité")
|
2016-09-30 20:10:35 +02:00
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2016-10-13 11:51:41 +02:00
|
|
|
def get_herited(self, attrname):
|
|
|
|
attr = super(Activity, self).__getattribute__(attrname)
|
2017-02-21 17:25:46 +01:00
|
|
|
if attrname in {"parent", "staff", "equipment"}:
|
2016-10-21 18:49:46 +02:00
|
|
|
raise FieldError(
|
|
|
|
_("%(attrname)s n'est pas un champ héritable"),
|
|
|
|
params={'attrname': attrname},
|
|
|
|
)
|
2016-10-13 11:51:41 +02:00
|
|
|
elif (attrname == 'place' or attrname == 'tags'):
|
|
|
|
if attr.exists():
|
|
|
|
return attr
|
|
|
|
else:
|
|
|
|
return self.parent.__getattribute__(attrname)
|
2016-10-03 00:31:21 +02:00
|
|
|
elif attr is None:
|
2016-10-13 11:51:41 +02:00
|
|
|
return self.parent.__getattribute__(attrname)
|
2016-09-30 20:10:35 +02:00
|
|
|
else:
|
2016-10-03 00:31:21 +02:00
|
|
|
return attr
|
2016-10-13 11:51:41 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("activité")
|
|
|
|
verbose_name_plural = _("activités")
|
|
|
|
|
2016-10-13 16:26:35 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.get_herited('title')
|