events: tune models.
[xnet] / xnet / events / models.py
CommitLineData
563bc08c
CW
1# -*- coding: utf-8 -*-
2from django.db import models
3from django.utils.translation import ugettext_lazy as _
459317ed
CW
4
5from django_xworkflows import models as xwf_models
6
563bc08c
CW
7import xnet.accounts.models as accounts_models
8
9class 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
0bef2caa
RB
22 short = models.SlugField(max_length=40, unique=True, verbose_name=_(u"nom raccourci"),
23 help_text=_(u"Texte court utilisé dans les URLs."))
74215aac 24 main_description = models.OneToOneField('events.EventDescription', null=True, blank=True,
99c4a1cb
CW
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')
0bef2caa
RB
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."))
563bc08c 30
0bef2caa
RB
31 registration_begin = models.DateTimeField(blank=True, null=True,
32 verbose_name=_(u"date d'ouverture des inscriptions"))
74215aac 33 registration_end = models.DateTimeField(null=True, blank=True,
563bc08c
CW
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"))
0bef2caa 40 registration_limit = models.PositiveIntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
563bc08c
CW
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
ee990e9d
CW
45 def __unicode__(self):
46 return self.short
47
563bc08c
CW
48 class Meta:
49 verbose_name = _(u"événement")
50 verbose_name_plural = _(u"événements")
51
52
53class EventDescription(models.Model):
0bef2caa
RB
54 """A component of an event."""
55
563bc08c
CW
56 name = models.CharField(max_length=100, verbose_name=_(u"nom"))
57 description = models.CharField(max_length=1000, verbose_name=_(u"description"))
99c4a1cb 58 event = models.ForeignKey(Event, verbose_name=_(u"événement parent"), related_name='descriptions')
74215aac 59 registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
0bef2caa
RB
60 main = models.BooleanField(verbose_name=_(u"principale"),
61 help_text=_(u"S'il s'agit du composant principal de l'événement"))
563bc08c 62
ee990e9d
CW
63 def __unicode__(self):
64 return self.name
65
563bc08c
CW
66 class Meta:
67 verbose_name = _(u"description d'événement")
68 verbose_name_plural = _(u"descriptions d'événements")
0bef2caa 69 unique_together = ('event', 'name')
563bc08c
CW
70
71
ee990e9d 72class PriceOption(models.Model):
563bc08c 73 name = models.CharField(max_length=100, verbose_name=_(u"nom"))
ee990e9d 74 amount = models.IntegerField(verbose_name=_(u"montant (centimes)"))
563bc08c 75 event_description = models.ForeignKey(EventDescription, verbose_name=_(u"description associée"),
99c4a1cb 76 related_name='price_options')
563bc08c 77
ee990e9d
CW
78 def __unicode__(self):
79 return self.name
80
563bc08c
CW
81 class Meta:
82 verbose_name = _(u"option de paiement")
83 verbose_name_plural = _(u"options de paiement")
0bef2caa 84 unique_together = ('event_description', 'name')
563bc08c
CW
85
86
459317ed
CW
87class RegistrationWorkflow(xwf_models.Workflow):
88 states = (
89 ('pending', u"En attente"),
90 ('accepted', u"Accepté"),
91 ('cancelled', u"Annulé"),
563bc08c 92 )
459317ed
CW
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
563bc08c 100
459317ed
CW
101
102class Registration(models.Model):
563bc08c 103 user = models.ForeignKey(accounts_models.Account, verbose_name=_(u"utilisateur enregistré"),
99c4a1cb 104 related_name='event_registrations')
74215aac 105 dn_event = models.ForeignKey(EventDescription, verbose_name=_(u"événement associé"),
0bef2caa 106 related_name='registrations', editable=False)
ee990e9d 107 option = models.ForeignKey(PriceOption, verbose_name=_(u"options associées"),
99c4a1cb 108 related_name='registrations')
ee990e9d 109 date_registered = models.DateTimeField(verbose_name=_(u"date d'enregistrement"))
459317ed 110 state = xwf_models.StateField(RegistrationWorkflow, verbose_name=u"état")
563bc08c 111
ee990e9d 112 def __unicode__(self):
2a6bbde8 113 return "%s, %s, %s".format(unicode(self.user), unicode(self.event), unicode(self.option))
ee990e9d
CW
114
115 class Meta:
459317ed
CW
116 verbose_name = _(u"inscription")
117 verbose_name_plural = _(u"inscriptions")
0bef2caa 118 unique_together = ('user', 'option')