gestioCOF/bda/models.py

93 lines
3.1 KiB
Python
Raw Normal View History

2012-07-11 17:39:20 +02:00
# coding: utf-8
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 _
from django.db.models.signals import post_save
class Salle (models.Model):
name = models.CharField ("Nom", max_length = 300)
address = models.TextField ("Adresse")
def __unicode__ (self):
return self.name
2012-07-11 17:39:20 +02:00
class Spectacle (models.Model):
title = models.CharField ("Titre", max_length = 300)
date = models.DateTimeField ("Date & heure")
location = models.ForeignKey(Salle)
2012-07-11 17:39:20 +02:00
description = models.TextField ("Description", blank = True)
2013-10-01 15:27:19 +02:00
slots_description = models.TextField ("Description des places", blank = True)
price = models.FloatField("Prix d'une place", blank = True)
2012-07-11 17:39:20 +02:00
slots = models.IntegerField ("Places")
priority = models.IntegerField ("Priorité", default = 1000)
class Meta:
verbose_name = "Spectacle"
ordering = ("priority", "date","title",)
def __repr__ (self):
return u"[%s]" % self.__unicode__()
def timestamp(self):
return "%d" % calendar.timegm(self.date.utctimetuple())
def date_no_seconds(self):
return self.date.strftime('%d %b %Y %H:%M')
2012-07-11 17:39:20 +02:00
def __unicode__ (self):
return u"%s - %s, %s, %.02f" % (self.title, self.date_no_seconds(), self.location, self.price)
PAYMENT_TYPES = (
("cash",u"Cash"),
("cb","CB"),
("cheque",u"Chèque"),
("autre",u"Autre"),
)
2012-07-11 17:39:20 +02:00
class Participant (models.Model):
user = models.ForeignKey(User, unique = True)
choices = models.ManyToManyField(Spectacle, through = "ChoixSpectacle", related_name = "chosen_by")
attributions = models.ManyToManyField(Spectacle, through = "Attribution", related_name = "attributed_to")
paid = models.BooleanField (u"A payé", default = False)
paymenttype = models.CharField(u"Moyen de paiement", max_length = 6, choices = PAYMENT_TYPES, blank = True)
2012-07-11 17:39:20 +02:00
def __unicode__ (self):
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"),
)
2012-07-11 17:39:20 +02:00
class ChoixSpectacle (models.Model):
participant = models.ForeignKey(Participant)
spectacle = models.ForeignKey(Spectacle, related_name = "participants")
priority = models.PositiveIntegerField("Priorité")
2015-09-13 18:23:47 +02:00
double_choice = models.CharField("Nombre de places", default = "1", choices = DOUBLE_CHOICES, max_length = 10)
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",)
unique_together = (("participant", "spectacle",),)
2012-07-11 17:39:20 +02:00
verbose_name = "voeu"
verbose_name_plural = "voeux"
class Attribution (models.Model):
participant = models.ForeignKey(Participant)
spectacle = models.ForeignKey(Spectacle, related_name = "attribues")
given = models.BooleanField(u"Donnée", default = False)
def __unicode__ (self):
return u"%s -- %s" % (self.participant, self.spectacle)