events: tune models.
[xnet] / xnet / events / models.py
1 # -*- coding: utf-8 -*-
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4
5 from django_xworkflows import models as xwf_models
6
7 import xnet.accounts.models as accounts_models
8
9 class Event(models.Model):
10 NOTIFICATION_RECIPIENT_CREATOR = 'creator'
11 NOTIFICATION_RECIPIENT_ANIM = 'anim'
12 NOTIFICATION_RECIPIENT_BOTH = 'both'
13 NOTIFICATION_RECIPIENT_NONE = 'none'
14
15 NOTIFICATION_RECIPIENT_CHOICES = (
16 (NOTIFICATION_RECIPIENT_CREATOR, _(u"créateur")),
17 (NOTIFICATION_RECIPIENT_ANIM, _(u"animateurs")),
18 (NOTIFICATION_RECIPIENT_BOTH, _(u"les deux")),
19 (NOTIFICATION_RECIPIENT_NONE, _(u"personne")),
20 )
21
22 short = models.SlugField(max_length=40, unique=True, verbose_name=_(u"nom raccourci"),
23 help_text=_(u"Texte court utilisé dans les URLs."))
24 main_description = models.OneToOneField('events.EventDescription', null=True, blank=True,
25 verbose_name=_(u"description principale"), related_name='+')
26 group = models.ForeignKey(accounts_models.XGroup, verbose_name=_(u"groupe"), related_name='events')
27 creator = models.ForeignKey(accounts_models.Account, verbose_name=_(u"créateur"), related_name='created_events')
28 simple = models.BooleanField(verbose_name=_(u"simple"),
29 help_text=_(u"Un événement simple a un seul composant. Permet une mise en page plus légère."))
30
31 registration_begin = models.DateTimeField(blank=True, null=True,
32 verbose_name=_(u"date d'ouverture des inscriptions"))
33 registration_end = models.DateTimeField(null=True, blank=True,
34 verbose_name=_(u"date limite d'inscription"))
35 notification_recipient = models.CharField(max_length=10, choices=NOTIFICATION_RECIPIENT_CHOICES,
36 verbose_name=_(u"destinataire(s) des notifications"))
37 show_registered = models.BooleanField(verbose_name=_(u"montrer les inscriptions aux membres"))
38 allow_non_members = models.BooleanField(verbose_name=_(u"autoriser les non-membres"))
39 allow_guests = models.BooleanField(verbose_name=_(u"autoriser les invités"))
40 registration_limit = models.PositiveIntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
41
42 start_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de début"))
43 end_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de fin"))
44
45 def __unicode__(self):
46 return self.short
47
48 class Meta:
49 verbose_name = _(u"événement")
50 verbose_name_plural = _(u"événements")
51
52
53 class EventDescription(models.Model):
54 """A component of an event."""
55
56 name = models.CharField(max_length=100, verbose_name=_(u"nom"))
57 description = models.CharField(max_length=1000, verbose_name=_(u"description"))
58 event = models.ForeignKey(Event, verbose_name=_(u"événement parent"), related_name='descriptions')
59 registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
60 main = models.BooleanField(verbose_name=_(u"principale"),
61 help_text=_(u"S'il s'agit du composant principal de l'événement"))
62
63 def __unicode__(self):
64 return self.name
65
66 class Meta:
67 verbose_name = _(u"description d'événement")
68 verbose_name_plural = _(u"descriptions d'événements")
69 unique_together = ('event', 'name')
70
71
72 class PriceOption(models.Model):
73 name = models.CharField(max_length=100, verbose_name=_(u"nom"))
74 amount = models.IntegerField(verbose_name=_(u"montant (centimes)"))
75 event_description = models.ForeignKey(EventDescription, verbose_name=_(u"description associée"),
76 related_name='price_options')
77
78 def __unicode__(self):
79 return self.name
80
81 class Meta:
82 verbose_name = _(u"option de paiement")
83 verbose_name_plural = _(u"options de paiement")
84 unique_together = ('event_description', 'name')
85
86
87 class RegistrationWorkflow(xwf_models.Workflow):
88 states = (
89 ('pending', u"En attente"),
90 ('accepted', u"Accepté"),
91 ('cancelled', u"Annulé"),
92 )
93 transitions = (
94 ('accept', ['pending'], 'accepted'),
95 ('cancel', ['pending', 'accepted'], 'cancelled'),
96 )
97 initial_state = 'pending'
98
99 log_model = '' # We don't want logs
100
101
102 class Registration(models.Model):
103 user = models.ForeignKey(accounts_models.Account, verbose_name=_(u"utilisateur enregistré"),
104 related_name='event_registrations')
105 dn_event = models.ForeignKey(EventDescription, verbose_name=_(u"événement associé"),
106 related_name='registrations', editable=False)
107 option = models.ForeignKey(PriceOption, verbose_name=_(u"options associées"),
108 related_name='registrations')
109 date_registered = models.DateTimeField(verbose_name=_(u"date d'enregistrement"))
110 state = xwf_models.StateField(RegistrationWorkflow, verbose_name=u"état")
111
112 def __unicode__(self):
113 return "%s, %s, %s".format(unicode(self.user), unicode(self.event), unicode(self.option))
114
115 class Meta:
116 verbose_name = _(u"inscription")
117 verbose_name_plural = _(u"inscriptions")
118 unique_together = ('user', 'option')