1 # -*- coding: utf-8 -*-
2 from django
.db
import models
3 from django
.utils
.translation
import ugettext_lazy
as _
5 from django_xworkflows
import models
as xwf_models
7 from xnet
.accounts
import models
as accounts_models
8 from xnet
.groups
import models
as groups_models
10 class Event(models
.Model
):
11 NOTIFICATION_RECIPIENT_CREATOR
= 'creator'
12 NOTIFICATION_RECIPIENT_ANIM
= 'anim'
13 NOTIFICATION_RECIPIENT_BOTH
= 'both'
14 NOTIFICATION_RECIPIENT_NONE
= 'none'
16 NOTIFICATION_RECIPIENT_CHOICES
= (
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")),
23 short
= models
.SlugField(max_length
=40, unique
=True, verbose_name
=_(u
"nom raccourci"),
24 help_text
=_(u
"Texte court utilisé dans les URLs."))
25 main_description
= models
.OneToOneField('events.EventPart', null
=True, blank
=True,
26 verbose_name
=_(u
"description principale"), related_name
='+')
27 group
= models
.ForeignKey(groups_models
.XGroup
, verbose_name
=_(u
"groupe"), related_name
='events')
28 creator
= models
.ForeignKey(accounts_models
.Account
, verbose_name
=_(u
"créateur"), related_name
='created_events')
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."))
32 registration_begin
= models
.DateTimeField(blank
=True, null
=True,
33 verbose_name
=_(u
"date d'ouverture des inscriptions"))
34 registration_end
= models
.DateTimeField(null
=True, blank
=True,
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"))
41 registration_limit
= models
.PositiveIntegerField(verbose_name
=_(u
"limites du nombre d'inscrits"))
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"))
46 def __unicode__(self
):
50 verbose_name
= _(u
"événement")
51 verbose_name_plural
= _(u
"événements")
54 class EventPart(models
.Model
):
55 """A component of an event."""
57 name
= models
.CharField(max_length
=100, verbose_name
=_(u
"nom"))
58 description
= models
.CharField(max_length
=1000, verbose_name
=_(u
"description"))
59 event
= models
.ForeignKey(Event
, verbose_name
=_(u
"événement parent"), related_name
='descriptions')
60 registration_limit
= models
.IntegerField(verbose_name
=_(u
"limites du nombre d'inscrits"))
61 main
= models
.BooleanField(verbose_name
=_(u
"principale"),
62 help_text
=_(u
"S'il s'agit du composant principal de l'événement"))
64 def __unicode__(self
):
68 verbose_name
= _(u
"description d'événement")
69 verbose_name_plural
= _(u
"descriptions d'événements")
70 unique_together
= ('event', 'name')
73 class PriceOption(models
.Model
):
74 name
= models
.CharField(max_length
=100, verbose_name
=_(u
"nom"))
75 amount
= models
.IntegerField(verbose_name
=_(u
"montant (centimes)"))
76 event_part
= models
.ForeignKey(EventPart
, verbose_name
=_(u
"description associée"),
77 related_name
='price_options')
79 def __unicode__(self
):
83 verbose_name
= _(u
"option de paiement")
84 verbose_name_plural
= _(u
"options de paiement")
85 unique_together
= ('event_part', 'name')
88 class RegistrationWorkflow(xwf_models
.Workflow
):
90 ('pending', u
"En attente"),
91 ('accepted', u
"Accepté"),
92 ('cancelled', u
"Annulé"),
95 ('accept', ['pending'], 'accepted'),
96 ('cancel', ['pending', 'accepted'], 'cancelled'),
98 initial_state
= 'pending'
100 log_model
= '' # We don't want logs
103 class Registration(models
.Model
):
104 user
= models
.ForeignKey(accounts_models
.Account
, verbose_name
=_(u
"utilisateur enregistré"),
105 related_name
='event_registrations')
106 dn_event
= models
.ForeignKey(Event
, verbose_name
=_(u
"événement associé"),
107 related_name
='registrations', editable
=False)
108 option
= models
.ForeignKey(PriceOption
, verbose_name
=_(u
"options associées"),
109 related_name
='registrations')
110 date_registered
= models
.DateTimeField(verbose_name
=_(u
"date d'enregistrement"))
111 state
= xwf_models
.StateField(RegistrationWorkflow
, verbose_name
=u
"état")
113 def __unicode__(self
):
114 return "%s, %s, %s".format(unicode(self
.user
), unicode(self
.event
), unicode(self
.option
))
117 verbose_name
= _(u
"inscription")
118 verbose_name_plural
= _(u
"inscriptions")
119 unique_together
= ('user', 'option')