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