Tous les modèles et champs sont là

Reste à faire les __getattr__ et __setattr__
This commit is contained in:
Qwann 2016-09-30 20:10:35 +02:00
parent bc827b7f0d
commit 95b492e05d
7 changed files with 173 additions and 0 deletions

View file

@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'event.apps.EventConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',

0
event/__init__.py Normal file
View file

3
event/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
event/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class EventConfig(AppConfig):
name = 'event'

158
event/models.py Normal file
View file

@ -0,0 +1,158 @@
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,
related_name=_("created_events"),
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")
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")
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")
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,
related_name=_("activities"),
blank=True,
null=True,
)
place = models.ManyToManyField(
Place,
related_name=_("activities"),
blank=True,
null=True,
)
class Meta:
verbose_name = _("Template activité")
verbose_name_plural = _("Templates activité")
class Activity(ActivityTemplate):
parent = models.ForeignKey(
ActivityTemplate,
related_name=_("children"),
)
staff = models.ManyToManyField(
User,
related_name=_("in_perm_activities"),
blank=True,
)
# TODO : Utiliser db_constraint ou through
# equipement = models.ManyToManyField(Equipement)
class Meta:
verbose_name = _("Activité")
verbose_name_plural = _("Activités")
def __getattr__(self, attrname):
if (attrname == 'parent'
or attrname == 'staff'
or attrname == 'equipement'):
return super(Activity, self).__getattr__(attrname)
elif attrname is None:
return self.parent.attrname
else:
return attrname

3
event/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
event/views.py Normal file
View file

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.