2012-07-11 17:39:20 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
import calendar
|
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2016-06-04 17:57:06 +02:00
|
|
|
class Tirage(models.Model):
|
|
|
|
title = models.CharField("Titre", max_length=300)
|
|
|
|
ouverture = models.DateTimeField("Date et heure d'ouverture du tirage")
|
|
|
|
fermeture = models.DateTimeField("Date et heure de fermerture du tirage")
|
|
|
|
token = models.TextField("Graine du tirage", blank=True)
|
2016-06-07 23:07:28 +02:00
|
|
|
active = models.BooleanField("Tirage actif", default=False)
|
2016-06-04 17:57:06 +02:00
|
|
|
|
|
|
|
def date_no_seconds(self):
|
|
|
|
return self.fermeture.strftime('%d %b %Y %H:%M')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2016-06-06 13:21:16 +02:00
|
|
|
return u"%s - %s" % (self.title, self.date_no_seconds())
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Salle(models.Model):
|
2016-07-09 21:19:37 +02:00
|
|
|
name = models.CharField("Nom", max_length=300)
|
2016-06-07 22:36:43 +02:00
|
|
|
address = models.TextField("Adresse")
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
def __unicode__(self):
|
2013-09-05 22:20:52 +02:00
|
|
|
return self.name
|
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Spectacle(models.Model):
|
|
|
|
title = models.CharField("Titre", max_length=300)
|
|
|
|
date = models.DateTimeField("Date & heure")
|
2013-09-05 22:20:52 +02:00
|
|
|
location = models.ForeignKey(Salle)
|
2016-06-07 22:36:43 +02:00
|
|
|
description = models.TextField("Description", blank=True)
|
|
|
|
slots_description = models.TextField("Description des places", blank=True)
|
2016-06-07 22:34:23 +02:00
|
|
|
price = models.FloatField("Prix d'une place")
|
2016-06-07 22:36:43 +02:00
|
|
|
slots = models.IntegerField("Places")
|
|
|
|
priority = models.IntegerField("Priorité", default=1000)
|
|
|
|
tirage = models.ForeignKey(Tirage)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Spectacle"
|
2016-07-09 21:19:37 +02:00
|
|
|
ordering = ("priority", "date", "title",)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
def __repr__(self):
|
2012-07-11 17:39:20 +02:00
|
|
|
return u"[%s]" % self.__unicode__()
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
def timestamp(self):
|
|
|
|
return "%d" % calendar.timegm(self.date.utctimetuple())
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def date_no_seconds(self):
|
|
|
|
return self.date.strftime('%d %b %Y %H:%M')
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
def __unicode__(self):
|
2016-06-04 17:57:06 +02:00
|
|
|
return u"%s - %s, %s, %.02f€" % (self.title, self.date_no_seconds(),
|
|
|
|
self.location, self.price)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
PAYMENT_TYPES = (
|
2016-07-09 21:19:37 +02:00
|
|
|
("cash", u"Cash"),
|
|
|
|
("cb", "CB"),
|
|
|
|
("cheque", u"Chèque"),
|
|
|
|
("autre", u"Autre"),
|
2013-09-05 22:20:52 +02:00
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Participant(models.Model):
|
2016-06-04 17:57:06 +02:00
|
|
|
user = models.ForeignKey(User)
|
|
|
|
choices = models.ManyToManyField(Spectacle,
|
|
|
|
through="ChoixSpectacle",
|
|
|
|
related_name="chosen_by")
|
|
|
|
attributions = models.ManyToManyField(Spectacle,
|
|
|
|
through="Attribution",
|
|
|
|
related_name="attributed_to")
|
2016-07-09 21:19:37 +02:00
|
|
|
paid = models.BooleanField(u"A payé", default=False)
|
2016-06-04 17:57:06 +02:00
|
|
|
paymenttype = models.CharField(u"Moyen de paiement",
|
|
|
|
max_length=6, choices=PAYMENT_TYPES, blank=True)
|
|
|
|
tirage = models.ForeignKey(Tirage)
|
2016-07-09 21:19:37 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-07-11 17:39:20 +02:00
|
|
|
return u"%s" % (self.user)
|
|
|
|
|
2015-09-13 18:23:47 +02:00
|
|
|
DOUBLE_CHOICES = (
|
|
|
|
("1", "1 place"),
|
|
|
|
("autoquit", "2 places si possible, 1 sinon"),
|
|
|
|
("double", "2 places sinon rien"),
|
|
|
|
)
|
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class ChoixSpectacle(models.Model):
|
2012-07-11 17:39:20 +02:00
|
|
|
participant = models.ForeignKey(Participant)
|
2016-06-04 17:57:06 +02:00
|
|
|
spectacle = models.ForeignKey(Spectacle, related_name="participants")
|
2012-07-11 17:39:20 +02:00
|
|
|
priority = models.PositiveIntegerField("Priorité")
|
2016-06-04 17:57:06 +02:00
|
|
|
double_choice = models.CharField("Nombre de places",
|
|
|
|
default="1", choices=DOUBLE_CHOICES, max_length=10)
|
2015-09-13 18:23:47 +02:00
|
|
|
|
|
|
|
def get_double(self):
|
|
|
|
return self.double_choice != "1"
|
|
|
|
double = property(get_double)
|
|
|
|
|
|
|
|
def get_autoquit(self):
|
|
|
|
return self.double_choice == "autoquit"
|
|
|
|
autoquit = property(get_autoquit)
|
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
class Meta:
|
|
|
|
ordering = ("priority",)
|
2013-09-05 22:20:52 +02:00
|
|
|
unique_together = (("participant", "spectacle",),)
|
2012-07-11 17:39:20 +02:00
|
|
|
verbose_name = "voeu"
|
2013-09-05 22:20:52 +02:00
|
|
|
verbose_name_plural = "voeux"
|
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Attribution(models.Model):
|
2013-09-05 22:20:52 +02:00
|
|
|
participant = models.ForeignKey(Participant)
|
2016-06-04 17:57:06 +02:00
|
|
|
spectacle = models.ForeignKey(Spectacle, related_name="attribues")
|
|
|
|
given = models.BooleanField(u"Donnée", default=False)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
def __unicode__(self):
|
2013-09-05 22:20:52 +02:00
|
|
|
return u"%s -- %s" % (self.participant, self.spectacle)
|