| 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, verbose_name=_(u"nom raccourci")) |
| 23 | main_description = models.OneToOneField('events.EventDescription', null=True, blank=True, |
| 24 | verbose_name=_(u"description principale"), related_name='+') |
| 25 | group = models.ForeignKey(accounts_models.XGroup, verbose_name=_(u"groupe"), related_name='events') |
| 26 | creator = models.ForeignKey(accounts_models.Account, verbose_name=_(u"créateur"), related_name='created_events') |
| 27 | simple = models.BooleanField(verbose_name=_(u"simple")) |
| 28 | |
| 29 | registration_end = models.DateTimeField(null=True, blank=True, |
| 30 | verbose_name=_(u"date limite d'inscription")) |
| 31 | notification_recipient = models.CharField(max_length=10, choices=NOTIFICATION_RECIPIENT_CHOICES, |
| 32 | verbose_name=_(u"destinataire(s) des notifications")) |
| 33 | show_registered = models.BooleanField(verbose_name=_(u"montrer les inscriptions aux membres")) |
| 34 | allow_non_members = models.BooleanField(verbose_name=_(u"autoriser les non-membres")) |
| 35 | allow_guests = models.BooleanField(verbose_name=_(u"autoriser les invités")) |
| 36 | registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits")) |
| 37 | |
| 38 | start_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de début")) |
| 39 | end_date = models.DateTimeField(null=True, blank=True, verbose_name=_(u"date de fin")) |
| 40 | |
| 41 | def __unicode__(self): |
| 42 | return self.short |
| 43 | |
| 44 | class Meta: |
| 45 | verbose_name = _(u"événement") |
| 46 | verbose_name_plural = _(u"événements") |
| 47 | |
| 48 | |
| 49 | class EventDescription(models.Model): |
| 50 | name = models.CharField(max_length=100, verbose_name=_(u"nom")) |
| 51 | description = models.CharField(max_length=1000, verbose_name=_(u"description")) |
| 52 | event = models.ForeignKey(Event, verbose_name=_(u"événement parent"), related_name='descriptions') |
| 53 | registration_limit = models.IntegerField(verbose_name=_(u"limites du nombre d'inscrits")) |
| 54 | main = models.BooleanField(verbose_name=_(u"principale")) |
| 55 | |
| 56 | def __unicode__(self): |
| 57 | return self.name |
| 58 | |
| 59 | class Meta: |
| 60 | verbose_name = _(u"description d'événement") |
| 61 | verbose_name_plural = _(u"descriptions d'événements") |
| 62 | |
| 63 | |
| 64 | class PriceOption(models.Model): |
| 65 | name = models.CharField(max_length=100, verbose_name=_(u"nom")) |
| 66 | amount = models.IntegerField(verbose_name=_(u"montant (centimes)")) |
| 67 | event_description = models.ForeignKey(EventDescription, verbose_name=_(u"description associée"), |
| 68 | related_name='price_options') |
| 69 | |
| 70 | def __unicode__(self): |
| 71 | return self.name |
| 72 | |
| 73 | class Meta: |
| 74 | verbose_name = _(u"option de paiement") |
| 75 | verbose_name_plural = _(u"options de paiement") |
| 76 | |
| 77 | |
| 78 | class RegistrationWorkflow(xwf_models.Workflow): |
| 79 | states = ( |
| 80 | ('pending', u"En attente"), |
| 81 | ('accepted', u"Accepté"), |
| 82 | ('cancelled', u"Annulé"), |
| 83 | ) |
| 84 | transitions = ( |
| 85 | ('accept', ['pending'], 'accepted'), |
| 86 | ('cancel', ['pending', 'accepted'], 'cancelled'), |
| 87 | ) |
| 88 | initial_state = 'pending' |
| 89 | |
| 90 | log_model = '' # We don't want logs |
| 91 | |
| 92 | |
| 93 | class Registration(models.Model): |
| 94 | user = models.ForeignKey(accounts_models.Account, verbose_name=_(u"utilisateur enregistré"), |
| 95 | related_name='event_registrations') |
| 96 | dn_event = models.ForeignKey(EventDescription, verbose_name=_(u"événement associé"), |
| 97 | related_name='registrations') |
| 98 | option = models.ForeignKey(PriceOption, verbose_name=_(u"options associées"), |
| 99 | related_name='registrations') |
| 100 | date_registered = models.DateTimeField(verbose_name=_(u"date d'enregistrement")) |
| 101 | state = xwf_models.StateField(RegistrationWorkflow, verbose_name=u"état") |
| 102 | |
| 103 | def __unicode__(self): |
| 104 | return "%s, %s, %s".format(unicode(self.user), unicode(self.event), unicode(self.option)) |
| 105 | |
| 106 | class Meta: |
| 107 | verbose_name = _(u"inscription") |
| 108 | verbose_name_plural = _(u"inscriptions") |