Rename EventDescription to EventPart
[xnet] / xnet / events / models.py
index f61cc12..ae2f08a 100644 (file)
@@ -1,6 +1,9 @@
 # -*- coding: utf-8 -*-
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
+
+from django_xworkflows import models as xwf_models
+
 import xnet.accounts.models as accounts_models
 
 class Event(models.Model):
@@ -10,18 +13,23 @@ class Event(models.Model):
     NOTIFICATION_RECIPIENT_NONE = 'none'
 
     NOTIFICATION_RECIPIENT_CHOICES = (
-        (NOTIFICATION_RECIPIENT_CREATOR, _(u"créateur")),
-        (NOTIFICATION_RECIPIENT_ANIM, _(u"animateurs")),
-        (NOTIFICATION_RECIPIENT_BOTH, _(u"les deux")),
-        (NOTIFICATION_RECIPIENT_NONE, _(u"personne")),
+        (NOTIFICATION_RECIPIENT_CREATOR, _(u"Le créateur de l'événement")),
+        (NOTIFICATION_RECIPIENT_ANIM, _(u"Les animateurs du groupe")),
+        (NOTIFICATION_RECIPIENT_BOTH, _(u"Le créateur et les animateurs")),
+        (NOTIFICATION_RECIPIENT_NONE, _(u"Personne")),
     )
 
-    short = models.SlugField(max_length=40, verbose_name=_(u"nom raccourci"))
-    main_description = models.OneToOneField('events.EventDescription', null=True, blank=True,
-            verbose_name=_(u"description principale"), related_name=_(u"+"))
-    simple = models.BooleanField(verbose_name=_(u"simple"))
-    creator = models.ForeignKey(accounts_models.Account, verbose_name=_(u"créateur"), related_name=_(u"created_events"))
-
+    short = models.SlugField(max_length=40, unique=True, verbose_name=_(u"nom raccourci"),
+        help_text=_(u"Texte court utilisé dans les URLs."))
+    main_description = models.OneToOneField('events.EventPart', null=True, blank=True,
+            verbose_name=_(u"description principale"), related_name='+')
+    group = models.ForeignKey(accounts_models.XGroup, verbose_name=_(u"groupe"), related_name='events')
+    creator = models.ForeignKey(accounts_models.Account, verbose_name=_(u"créateur"), related_name='created_events')
+    simple = models.BooleanField(verbose_name=_(u"simple"),
+        help_text=_(u"Un événement simple a un seul composant. Permet une mise en page plus légère."))
+
+    registration_begin = models.DateTimeField(blank=True, null=True,
+            verbose_name=_(u"date d'ouverture des inscriptions"))
     registration_end = models.DateTimeField(null=True, blank=True,
             verbose_name=_(u"date limite d'inscription"))
     notification_recipient = models.CharField(max_length=10, choices=NOTIFICATION_RECIPIENT_CHOICES,
@@ -29,7 +37,7 @@ class Event(models.Model):
     show_registered = models.BooleanField(verbose_name=_(u"montrer les inscriptions aux membres"))
     allow_non_members = models.BooleanField(verbose_name=_(u"autoriser les non-membres"))
     allow_guests = models.BooleanField(verbose_name=_(u"autoriser les invités"))
-    registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
+    registration_limit = models.PositiveIntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
 
     start_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de début"))
     end_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de fin"))
@@ -42,12 +50,15 @@ class Event(models.Model):
         verbose_name_plural = _(u"événements")
 
 
-class EventDescription(models.Model):
+class EventPart(models.Model):
+    """A component of an event."""
+
     name = models.CharField(max_length=100, verbose_name=_(u"nom"))
     description = models.CharField(max_length=1000, verbose_name=_(u"description"))
-    event = models.ForeignKey(Event, verbose_name=_(u"événement parent"), related_name=_(u"descriptions"))
+    event = models.ForeignKey(Event, verbose_name=_(u"événement parent"), related_name='descriptions')
     registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits"))
-    main = models.BooleanField(verbose_name=_(u"principale"))
+    main = models.BooleanField(verbose_name=_(u"principale"),
+            help_text=_(u"S'il s'agit du composant principal de l'événement"))
 
     def __unicode__(self):
         return self.name
@@ -55,13 +66,14 @@ class EventDescription(models.Model):
     class Meta:
         verbose_name = _(u"description d'événement")
         verbose_name_plural = _(u"descriptions d'événements")
+        unique_together = ('event', 'name')
 
 
 class PriceOption(models.Model):
     name = models.CharField(max_length=100, verbose_name=_(u"nom"))
     amount = models.IntegerField(verbose_name=_(u"montant (centimes)"))
-    event_description = models.ForeignKey(EventDescription, verbose_name=_(u"description associée"),
-            related_name=_(u"price_options"))
+    event_description = models.ForeignKey(EventPart, verbose_name=_(u"description associée"),
+            related_name='price_options')
 
     def __unicode__(self):
         return self.name
@@ -69,32 +81,38 @@ class PriceOption(models.Model):
     class Meta:
         verbose_name = _(u"option de paiement")
         verbose_name_plural = _(u"options de paiement")
+        unique_together = ('event_description', 'name')
 
 
-class Registration(models.Model):
-    STATUS_PENDING = 'pending'
-    STATUS_ACCEPTED = 'accepted'
-    STATUS_CANCELLED = 'cancelled'
-
-    STATUS_CHOICES = (
-        (STATUS_PENDING, _(u"en attente")),
-        (STATUS_ACCEPTED, _(u"accepté")),
-        (STATUS_CANCELLED, _(u"annulé")),
+class RegistrationWorkflow(xwf_models.Workflow):
+    states = (
+        ('pending', u"En attente"),
+        ('accepted', u"Accepté"),
+        ('cancelled', u"Annulé"),
+    )
+    transitions = (
+        ('accept', ['pending'], 'accepted'),
+        ('cancel', ['pending', 'accepted'], 'cancelled'),
     )
+    initial_state = 'pending'
 
+    log_model = ''  # We don't want logs
+
+
+class Registration(models.Model):
     user = models.ForeignKey(accounts_models.Account, verbose_name=_(u"utilisateur enregistré"),
-            related_name=_(u"event_registrations"))
-    dn_event = models.ForeignKey(EventDescription, verbose_name=_(u"événement associé"),
-            related_name=_(u"registrations"))
+            related_name='event_registrations')
+    dn_event = models.ForeignKey(EventPart, verbose_name=_(u"événement associé"),
+            related_name='registrations', editable=False)
     option = models.ForeignKey(PriceOption, verbose_name=_(u"options associées"),
-            related_name=_(u"registrations"))
+            related_name='registrations')
     date_registered = models.DateTimeField(verbose_name=_(u"date d'enregistrement"))
-    status = models.CharField(max_length=10, choices=STATUS_CHOICES, verbose_name=_(u"statut"))
+    state = xwf_models.StateField(RegistrationWorkflow, verbose_name=u"état")
 
     def __unicode__(self):
-        return "%s, %s, %s".format(unicode(user), unicode(event), unicode(option))
+        return "%s, %s, %s".format(unicode(self.user), unicode(self.event), unicode(self.option))
 
     class Meta:
-        verbose_name = _(u"option de paiement")
-        verbose_name_plural = _(u"options de paiement")
-
+        verbose_name = _(u"inscription")
+        verbose_name_plural = _(u"inscriptions")
+        unique_together = ('user', 'option')