2014-08-19 12:54:22 +02:00
|
|
|
import calendar
|
2016-09-04 11:14:09 +02:00
|
|
|
import random
|
2016-09-21 15:39:01 +02:00
|
|
|
from datetime import timedelta
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.auth.models import User
|
2016-10-03 20:06:33 +02:00
|
|
|
from django.contrib.sites.models import Site
|
2017-11-24 06:53:31 +01:00
|
|
|
from django.core import mail
|
2020-09-15 11:49:05 +02:00
|
|
|
from django.core.mail import EmailMessage, send_mass_mail
|
2012-07-11 17:39:20 +02:00
|
|
|
from django.db import models
|
2019-06-08 14:59:45 +02:00
|
|
|
from django.db.models import Count, Exists
|
2020-09-15 11:49:05 +02:00
|
|
|
from django.template import loader
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.utils import formats, timezone
|
2017-11-24 06:53:31 +01:00
|
|
|
|
2017-06-18 17:52:53 +02:00
|
|
|
|
|
|
|
def get_generic_user():
|
|
|
|
generic, _ = User.objects.get_or_create(
|
|
|
|
username="bda_generic",
|
2018-10-06 12:35:49 +02:00
|
|
|
defaults={"email": "bda@ens.fr", "first_name": "Bureau des arts"},
|
2017-06-18 17:52:53 +02:00
|
|
|
)
|
|
|
|
return generic
|
2017-06-02 18:25:04 +02:00
|
|
|
|
2016-07-10 13:19:10 +02:00
|
|
|
|
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")
|
2016-07-08 00:18:58 +02:00
|
|
|
tokens = models.TextField("Graine(s) du tirage", blank=True)
|
2016-06-07 23:07:28 +02:00
|
|
|
active = models.BooleanField("Tirage actif", default=False)
|
2017-04-05 21:42:50 +02:00
|
|
|
appear_catalogue = models.BooleanField(
|
2018-10-06 12:35:49 +02:00
|
|
|
"Tirage à afficher dans le catalogue", default=False
|
2017-04-05 21:42:50 +02:00
|
|
|
)
|
2018-10-06 12:35:49 +02:00
|
|
|
enable_do_tirage = models.BooleanField("Le tirage peut être lancé", default=False)
|
2020-10-21 18:21:40 +02:00
|
|
|
archived = models.BooleanField("Archivé", default=False)
|
2016-06-04 17:57:06 +02:00
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2018-10-06 12:35:49 +02:00
|
|
|
return "%s - %s" % (
|
|
|
|
self.title,
|
|
|
|
formats.localize(timezone.template_localtime(self.fermeture)),
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-07-09 22:31:56 +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-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2013-09-05 22:20:52 +02:00
|
|
|
return self.name
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-08-26 05:28:04 +02:00
|
|
|
class CategorieSpectacle(models.Model):
|
2018-10-06 12:35:49 +02:00
|
|
|
name = models.CharField("Nom", max_length=100, unique=True)
|
2016-08-26 05:28:04 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Catégorie"
|
|
|
|
|
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Spectacle(models.Model):
|
|
|
|
title = models.CharField("Titre", max_length=300)
|
2017-11-19 18:41:39 +01:00
|
|
|
category = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
CategorieSpectacle, on_delete=models.CASCADE, blank=True, null=True
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-06-07 22:36:43 +02:00
|
|
|
date = models.DateTimeField("Date & heure")
|
2017-11-19 18:41:39 +01:00
|
|
|
location = models.ForeignKey(Salle, on_delete=models.CASCADE)
|
2018-10-06 12:35:49 +02:00
|
|
|
vips = models.TextField("Personnalités", blank=True)
|
2016-06-07 22:36:43 +02:00
|
|
|
description = models.TextField("Description", blank=True)
|
|
|
|
slots_description = models.TextField("Description des places", blank=True)
|
2018-10-06 12:35:49 +02:00
|
|
|
image = models.ImageField("Image", blank=True, null=True, upload_to="imgs/shows/")
|
|
|
|
ext_link = models.CharField(
|
|
|
|
"Lien vers le site du spectacle", blank=True, max_length=500
|
|
|
|
)
|
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")
|
2017-11-19 18:41:39 +01:00
|
|
|
tirage = models.ForeignKey(Tirage, on_delete=models.CASCADE)
|
2016-06-10 02:00:50 +02:00
|
|
|
listing = models.BooleanField("Les places sont sur listing")
|
2018-10-06 12:35:49 +02:00
|
|
|
rappel_sent = models.DateTimeField("Mail de rappel envoyé", blank=True, null=True)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Spectacle"
|
2018-10-06 12:35:49 +02:00
|
|
|
ordering = ("date", "title")
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
def timestamp(self):
|
|
|
|
return "%d" % calendar.timegm(self.date.utctimetuple())
|
|
|
|
|
2016-05-26 22:44:10 +02:00
|
|
|
def __str__(self):
|
2016-11-08 10:24:17 +01:00
|
|
|
return "%s - %s, %s, %.02f€" % (
|
|
|
|
self.title,
|
|
|
|
formats.localize(timezone.template_localtime(self.date)),
|
|
|
|
self.location,
|
2018-10-06 12:35:49 +02:00
|
|
|
self.price,
|
2016-11-08 10:24:17 +01:00
|
|
|
)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2017-03-31 03:47:32 +02:00
|
|
|
def getImgUrl(self):
|
|
|
|
"""
|
|
|
|
Cette fonction permet d'obtenir l'URL de l'image, si elle existe
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return self.image.url
|
2018-10-06 12:47:19 +02:00
|
|
|
except Exception:
|
2017-03-31 03:47:32 +02:00
|
|
|
return None
|
|
|
|
|
2016-06-10 23:53:29 +02:00
|
|
|
def send_rappel(self):
|
2016-11-20 16:39:26 +01:00
|
|
|
"""
|
|
|
|
Envoie un mail de rappel à toutes les personnes qui ont une place pour
|
|
|
|
ce spectacle.
|
|
|
|
"""
|
2017-06-18 17:52:53 +02:00
|
|
|
# On récupère la liste des participants + le BdA
|
|
|
|
members = list(
|
2018-10-06 12:35:49 +02:00
|
|
|
User.objects.filter(participant__attributions=self)
|
|
|
|
.annotate(nb_attr=Count("id"))
|
|
|
|
.order_by()
|
2017-06-18 17:52:53 +02:00
|
|
|
)
|
2017-06-02 18:25:04 +02:00
|
|
|
bda_generic = get_generic_user()
|
2017-06-18 17:52:53 +02:00
|
|
|
bda_generic.nb_attr = 1
|
|
|
|
members.append(bda_generic)
|
|
|
|
# On écrit un mail personnalisé à chaque participant
|
2020-09-15 11:49:05 +02:00
|
|
|
mails = [
|
2018-10-06 12:35:49 +02:00
|
|
|
(
|
2020-09-15 11:49:05 +02:00
|
|
|
str(self),
|
|
|
|
loader.render_to_string(
|
|
|
|
"bda/mails/rappel.txt",
|
|
|
|
context={"member": member, "nb_attr": member.nb_attr, "show": self},
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
settings.MAIL_DATA["rappels"]["FROM"],
|
|
|
|
[member.email],
|
|
|
|
)
|
2017-06-18 17:52:53 +02:00
|
|
|
for member in members
|
2016-12-22 02:00:10 +01:00
|
|
|
]
|
2020-09-15 11:49:05 +02:00
|
|
|
send_mass_mail(mails)
|
2016-07-10 14:19:19 +02:00
|
|
|
# On enregistre le fait que l'envoi a bien eu lieu
|
|
|
|
self.rappel_sent = timezone.now()
|
|
|
|
self.save()
|
2016-06-10 23:53:29 +02:00
|
|
|
# On renvoie la liste des destinataires
|
2017-06-18 17:52:53 +02:00
|
|
|
return members
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2017-02-10 19:58:22 +01:00
|
|
|
@property
|
|
|
|
def is_past(self):
|
|
|
|
return self.date < timezone.now()
|
2016-08-26 05:28:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Quote(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
spectacle = models.ForeignKey(Spectacle, on_delete=models.CASCADE)
|
2018-10-06 12:35:49 +02:00
|
|
|
text = models.TextField("Citation")
|
|
|
|
author = models.CharField("Auteur", max_length=200)
|
2016-08-26 05:28:04 +02:00
|
|
|
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
PAYMENT_TYPES = (
|
2016-07-10 10:46:45 +02:00
|
|
|
("cash", "Cash"),
|
2016-07-09 21:19:37 +02:00
|
|
|
("cb", "CB"),
|
2016-07-10 10:46:45 +02:00
|
|
|
("cheque", "Chèque"),
|
|
|
|
("autre", "Autre"),
|
2013-09-05 22:20:52 +02:00
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2019-06-08 14:48:18 +02:00
|
|
|
class Attribution(models.Model):
|
|
|
|
participant = models.ForeignKey("Participant", on_delete=models.CASCADE)
|
|
|
|
spectacle = models.ForeignKey(
|
|
|
|
Spectacle, on_delete=models.CASCADE, related_name="attribues"
|
|
|
|
)
|
|
|
|
given = models.BooleanField("Donnée", default=False)
|
|
|
|
paid = models.BooleanField("Payée", default=False)
|
|
|
|
paymenttype = models.CharField(
|
|
|
|
"Moyen de paiement", max_length=6, choices=PAYMENT_TYPES, blank=True
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s -- %s, %s" % (
|
|
|
|
self.participant.user,
|
|
|
|
self.spectacle.title,
|
|
|
|
self.spectacle.date,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-17 21:36:09 +02:00
|
|
|
class ParticipantPaidQueryset(models.QuerySet):
|
2019-06-08 14:59:45 +02:00
|
|
|
"""
|
2020-08-28 18:00:54 +02:00
|
|
|
Un manager qui annote le queryset avec un champ `paid`,
|
|
|
|
indiquant si un participant a payé toutes ses attributions.
|
2019-06-08 14:59:45 +02:00
|
|
|
"""
|
|
|
|
|
2019-06-17 21:36:09 +02:00
|
|
|
def annotate_paid(self):
|
2019-06-17 21:40:32 +02:00
|
|
|
# OuterRef permet de se référer à un champ d'un modèle non encore fixé
|
|
|
|
# Voir:
|
|
|
|
# https://docs.djangoproject.com/en/2.2/ref/models/expressions/#django.db.models.OuterRef
|
2019-06-08 14:59:45 +02:00
|
|
|
unpaid = Attribution.objects.filter(
|
|
|
|
participant=models.OuterRef("pk"), paid=False
|
|
|
|
)
|
2019-06-17 21:36:09 +02:00
|
|
|
return self.annotate(paid=~Exists(unpaid))
|
2019-06-08 14:59:45 +02:00
|
|
|
|
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class Participant(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
2018-10-06 12:35:49 +02:00
|
|
|
choices = models.ManyToManyField(
|
|
|
|
Spectacle, through="ChoixSpectacle", related_name="chosen_by"
|
|
|
|
)
|
|
|
|
attributions = models.ManyToManyField(
|
|
|
|
Spectacle, through="Attribution", related_name="attributed_to"
|
|
|
|
)
|
2020-10-21 18:22:05 +02:00
|
|
|
tirage = models.ForeignKey(
|
|
|
|
Tirage, on_delete=models.CASCADE, limit_choices_to={"archived": False}
|
|
|
|
)
|
2019-09-18 19:34:56 +02:00
|
|
|
accepte_charte = models.BooleanField("A accepté la charte BdA", default=False)
|
2018-10-06 12:35:49 +02:00
|
|
|
choicesrevente = models.ManyToManyField(
|
|
|
|
Spectacle, related_name="subscribed", blank=True
|
|
|
|
)
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2019-06-17 21:36:09 +02:00
|
|
|
objects = ParticipantPaidQueryset.as_manager()
|
2019-06-08 14:59:45 +02:00
|
|
|
|
2016-07-09 12:52:53 +02:00
|
|
|
def __str__(self):
|
2016-07-15 20:01:45 +02:00
|
|
|
return "%s - %s" % (self.user, self.tirage.title)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2020-10-21 18:22:05 +02:00
|
|
|
class Meta:
|
|
|
|
ordering = ("-tirage", "user__last_name", "user__first_name")
|
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(fields=("tirage", "user"), name="unique_tirage"),
|
|
|
|
]
|
|
|
|
|
2017-10-26 12:40:11 +02:00
|
|
|
|
2015-09-13 18:23:47 +02:00
|
|
|
DOUBLE_CHOICES = (
|
|
|
|
("1", "1 place"),
|
2018-04-09 22:43:25 +02:00
|
|
|
("double", "2 places si possible, 1 sinon"),
|
|
|
|
("autoquit", "2 places sinon rien"),
|
2015-09-13 18:23:47 +02:00
|
|
|
)
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-06-07 22:36:43 +02:00
|
|
|
class ChoixSpectacle(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
participant = models.ForeignKey(Participant, on_delete=models.CASCADE)
|
|
|
|
spectacle = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
Spectacle, on_delete=models.CASCADE, related_name="participants"
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
priority = models.PositiveIntegerField("Priorité")
|
2018-10-06 12:35:49 +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"
|
2018-10-06 12:35:49 +02:00
|
|
|
|
2015-09-13 18:23:47 +02:00
|
|
|
double = property(get_double)
|
|
|
|
|
|
|
|
def get_autoquit(self):
|
|
|
|
return self.double_choice == "autoquit"
|
2018-10-06 12:35:49 +02:00
|
|
|
|
2015-09-13 18:23:47 +02:00
|
|
|
autoquit = property(get_autoquit)
|
|
|
|
|
2016-07-15 20:01:45 +02:00
|
|
|
def __str__(self):
|
|
|
|
return "Vœux de %s pour %s" % (
|
2018-10-06 12:35:49 +02:00
|
|
|
self.participant.user.get_full_name(),
|
|
|
|
self.spectacle.title,
|
|
|
|
)
|
2016-07-15 20:01:45 +02:00
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
class Meta:
|
|
|
|
ordering = ("priority",)
|
2022-06-30 10:38:25 +02:00
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(
|
|
|
|
fields=["participant", "spectacle"], name="unique_participation"
|
|
|
|
)
|
|
|
|
]
|
2012-07-11 17:39:20 +02:00
|
|
|
verbose_name = "voeu"
|
2013-09-05 22:20:52 +02:00
|
|
|
verbose_name_plural = "voeux"
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2016-07-22 22:48:09 +02:00
|
|
|
class SpectacleRevente(models.Model):
|
2017-11-19 18:41:39 +01:00
|
|
|
attribution = models.OneToOneField(
|
2018-10-06 12:35:49 +02:00
|
|
|
Attribution, on_delete=models.CASCADE, related_name="revente"
|
|
|
|
)
|
|
|
|
date = models.DateTimeField("Date de mise en vente", default=timezone.now)
|
|
|
|
confirmed_entry = models.ManyToManyField(
|
|
|
|
Participant, related_name="entered", blank=True
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
|
|
|
seller = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
Participant,
|
|
|
|
on_delete=models.CASCADE,
|
2017-11-19 18:41:39 +01:00
|
|
|
verbose_name="Vendeur",
|
|
|
|
related_name="original_shows",
|
|
|
|
)
|
|
|
|
soldTo = models.ForeignKey(
|
2018-10-06 12:35:49 +02:00
|
|
|
Participant,
|
|
|
|
on_delete=models.CASCADE,
|
2017-11-19 18:41:39 +01:00
|
|
|
verbose_name="Vendue à",
|
2018-10-06 12:35:49 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
2017-11-19 18:41:39 +01:00
|
|
|
)
|
2016-07-22 22:48:09 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
notif_sent = models.BooleanField("Notification envoyée", default=False)
|
2017-10-23 20:52:25 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
notif_time = models.DateTimeField(
|
|
|
|
"Moment d'envoi de la notification", blank=True, null=True
|
|
|
|
)
|
2017-10-23 20:52:25 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
tirage_done = models.BooleanField("Tirage effectué", default=False)
|
2017-10-23 20:52:25 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
shotgun = models.BooleanField("Disponible immédiatement", default=False)
|
2017-10-23 20:30:11 +02:00
|
|
|
####
|
|
|
|
# Some class attributes
|
|
|
|
###
|
|
|
|
# TODO : settings ?
|
|
|
|
|
|
|
|
# Temps minimum entre le tirage et le spectacle
|
|
|
|
min_margin = timedelta(days=5)
|
|
|
|
|
|
|
|
# Temps entre la création d'une revente et l'envoi du mail
|
|
|
|
remorse_time = timedelta(hours=1)
|
|
|
|
|
|
|
|
# Temps min/max d'attente avant le tirage
|
|
|
|
max_wait_time = timedelta(days=3)
|
|
|
|
min_wait_time = timedelta(days=1)
|
2016-09-21 15:39:01 +02:00
|
|
|
|
2017-10-23 20:52:25 +02:00
|
|
|
@property
|
|
|
|
def real_notif_time(self):
|
|
|
|
if self.notif_time:
|
|
|
|
return self.notif_time
|
|
|
|
else:
|
|
|
|
return self.date + self.remorse_time
|
2016-09-21 15:39:01 +02:00
|
|
|
|
2016-09-26 20:44:22 +02:00
|
|
|
@property
|
2016-11-14 15:52:02 +01:00
|
|
|
def date_tirage(self):
|
|
|
|
"""Renvoie la date du tirage au sort de la revente."""
|
2017-10-23 20:30:11 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
remaining_time = (
|
|
|
|
self.attribution.spectacle.date - self.real_notif_time - self.min_margin
|
|
|
|
)
|
2017-10-23 20:30:11 +02:00
|
|
|
|
|
|
|
delay = min(remaining_time, self.max_wait_time)
|
|
|
|
|
2017-10-23 20:52:25 +02:00
|
|
|
return self.real_notif_time + delay
|
2017-10-23 20:30:11 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_urgent(self):
|
|
|
|
"""
|
|
|
|
Renvoie True iff la revente doit être mise au shotgun directement.
|
|
|
|
Plus précisément, on doit avoir min_margin + min_wait_time de marge.
|
|
|
|
"""
|
|
|
|
spectacle_date = self.attribution.spectacle.date
|
2018-10-06 12:35:49 +02:00
|
|
|
return spectacle_date <= timezone.now() + self.min_margin + self.min_wait_time
|
2017-10-23 20:30:11 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def can_notif(self):
|
2018-10-06 12:35:49 +02:00
|
|
|
return timezone.now() >= self.date + self.remorse_time
|
2016-07-22 22:48:09 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2018-10-06 12:35:49 +02:00
|
|
|
return "%s -- %s" % (self.seller, self.attribution.spectacle.title)
|
2016-07-29 01:50:08 +02:00
|
|
|
|
2016-09-05 03:10:06 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = "Revente"
|
|
|
|
|
2017-10-26 12:40:11 +02:00
|
|
|
def reset(self, new_date=timezone.now()):
|
2017-10-23 18:59:30 +02:00
|
|
|
"""Réinitialise la revente pour permettre une remise sur le marché"""
|
|
|
|
self.seller = self.attribution.participant
|
2017-10-26 12:40:11 +02:00
|
|
|
self.date = new_date
|
2017-10-23 20:52:25 +02:00
|
|
|
self.confirmed_entry.clear()
|
2017-10-23 18:59:30 +02:00
|
|
|
self.soldTo = None
|
|
|
|
self.notif_sent = False
|
2017-12-19 12:50:20 +01:00
|
|
|
self.notif_time = None
|
2017-10-23 18:59:30 +02:00
|
|
|
self.tirage_done = False
|
|
|
|
self.shotgun = False
|
2017-10-26 12:40:11 +02:00
|
|
|
self.save()
|
2017-10-23 18:59:30 +02:00
|
|
|
|
2016-07-29 01:50:08 +02:00
|
|
|
def send_notif(self):
|
2016-12-22 02:00:10 +01:00
|
|
|
"""
|
|
|
|
Envoie une notification pour indiquer la mise en vente d'une place sur
|
|
|
|
BdA-Revente à tous les intéressés.
|
|
|
|
"""
|
2018-10-06 12:35:49 +02:00
|
|
|
inscrits = self.attribution.spectacle.subscribed.select_related("user")
|
2020-09-15 11:49:05 +02:00
|
|
|
mails = [
|
2018-10-06 12:35:49 +02:00
|
|
|
(
|
2020-09-15 11:49:05 +02:00
|
|
|
"BdA-Revente : {}".format(self.attribution.spectacle.title),
|
|
|
|
loader.render_to_string(
|
|
|
|
"bda/mails/revente-new.txt",
|
|
|
|
context={
|
|
|
|
"member": participant.user,
|
|
|
|
"show": self.attribution.spectacle,
|
|
|
|
"revente": self,
|
|
|
|
"site": Site.objects.get_current(),
|
|
|
|
},
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
settings.MAIL_DATA["revente"]["FROM"],
|
|
|
|
[participant.user.email],
|
|
|
|
)
|
2016-12-22 02:00:10 +01:00
|
|
|
for participant in inscrits
|
|
|
|
]
|
2020-09-15 11:49:05 +02:00
|
|
|
send_mass_mail(mails)
|
2016-09-21 15:39:01 +02:00
|
|
|
self.notif_sent = True
|
2017-10-23 20:52:25 +02:00
|
|
|
self.notif_time = timezone.now()
|
2016-09-26 20:41:59 +02:00
|
|
|
self.save()
|
2016-09-21 15:39:01 +02:00
|
|
|
|
|
|
|
def mail_shotgun(self):
|
2016-11-20 16:39:26 +01:00
|
|
|
"""
|
|
|
|
Envoie un mail à toutes les personnes intéréssées par le spectacle pour
|
|
|
|
leur indiquer qu'il est désormais disponible au shotgun.
|
|
|
|
"""
|
2018-10-06 12:35:49 +02:00
|
|
|
inscrits = self.attribution.spectacle.subscribed.select_related("user")
|
2020-09-15 11:49:05 +02:00
|
|
|
mails = [
|
2018-10-06 12:35:49 +02:00
|
|
|
(
|
2020-09-15 11:49:05 +02:00
|
|
|
"BdA-Revente : {}".format(self.attribution.spectacle.title),
|
|
|
|
loader.render_to_string(
|
|
|
|
"bda/mails/revente-shotgun.txt",
|
|
|
|
context={
|
|
|
|
"member": participant.user,
|
|
|
|
"show": self.attribution.spectacle,
|
|
|
|
"site": Site.objects.get_current(),
|
|
|
|
},
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
settings.MAIL_DATA["revente"]["FROM"],
|
|
|
|
[participant.user.email],
|
|
|
|
)
|
2016-12-22 02:00:10 +01:00
|
|
|
for participant in inscrits
|
|
|
|
]
|
2020-09-15 11:49:05 +02:00
|
|
|
send_mass_mail(mails)
|
2016-09-21 15:39:01 +02:00
|
|
|
self.notif_sent = True
|
2017-10-23 20:52:25 +02:00
|
|
|
self.notif_time = timezone.now()
|
2016-10-27 16:38:14 +02:00
|
|
|
# Flag inutile, sauf si l'horloge interne merde
|
|
|
|
self.tirage_done = True
|
2016-10-10 16:56:31 +02:00
|
|
|
self.shotgun = True
|
2016-09-26 20:41:59 +02:00
|
|
|
self.save()
|
2016-09-04 11:14:09 +02:00
|
|
|
|
2017-12-19 11:40:02 +01:00
|
|
|
def tirage(self, send_mails=True):
|
2016-11-20 16:39:26 +01:00
|
|
|
"""
|
|
|
|
Lance le tirage au sort associé à la revente. Un gagnant est choisi
|
|
|
|
parmis les personnes intéressées par le spectacle. Les personnes sont
|
|
|
|
ensuites prévenues par mail du résultat du tirage.
|
|
|
|
"""
|
2017-10-23 20:52:25 +02:00
|
|
|
inscrits = list(self.confirmed_entry.all())
|
2016-09-04 11:14:09 +02:00
|
|
|
spectacle = self.attribution.spectacle
|
2016-09-05 02:29:49 +02:00
|
|
|
seller = self.seller
|
2017-11-01 17:29:38 +01:00
|
|
|
winner = None
|
2016-09-04 11:14:09 +02:00
|
|
|
|
2016-11-05 20:04:25 +01:00
|
|
|
if inscrits:
|
|
|
|
# Envoie un mail au gagnant et au vendeur
|
|
|
|
winner = random.choice(inscrits)
|
|
|
|
self.soldTo = winner
|
2017-12-19 11:40:02 +01:00
|
|
|
if send_mails:
|
2018-01-10 20:00:34 +01:00
|
|
|
mails = []
|
|
|
|
|
2017-12-19 11:40:02 +01:00
|
|
|
context = {
|
2018-10-06 12:35:49 +02:00
|
|
|
"acheteur": winner.user,
|
|
|
|
"vendeur": seller.user,
|
|
|
|
"show": spectacle,
|
2017-12-19 11:40:02 +01:00
|
|
|
}
|
2018-01-10 20:00:34 +01:00
|
|
|
|
2020-09-15 11:49:05 +02:00
|
|
|
subject = "BdA-Revente : {}".format(spectacle.title)
|
2018-01-10 20:00:34 +01:00
|
|
|
|
|
|
|
mails.append(
|
2020-09-15 11:49:05 +02:00
|
|
|
EmailMessage(
|
|
|
|
subject=subject,
|
|
|
|
body=loader.render_to_string(
|
|
|
|
"bda/mails/revente-tirage-winner.txt",
|
|
|
|
context=context,
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
from_email=settings.MAIL_DATA["revente"]["FROM"],
|
2018-01-10 20:00:34 +01:00
|
|
|
to=[winner.user.email],
|
|
|
|
)
|
2017-11-24 06:53:31 +01:00
|
|
|
)
|
2018-01-10 20:00:34 +01:00
|
|
|
mails.append(
|
2020-09-15 11:49:05 +02:00
|
|
|
EmailMessage(
|
|
|
|
subject=subject,
|
|
|
|
body=loader.render_to_string(
|
|
|
|
"bda/mails/revente-tirage-seller.txt",
|
|
|
|
context=context,
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
from_email=settings.MAIL_DATA["revente"]["FROM"],
|
2018-01-10 20:00:34 +01:00
|
|
|
to=[seller.user.email],
|
|
|
|
reply_to=[winner.user.email],
|
2020-09-15 11:49:05 +02:00
|
|
|
),
|
2017-11-24 06:53:31 +01:00
|
|
|
)
|
2017-12-19 11:40:02 +01:00
|
|
|
|
|
|
|
# Envoie un mail aux perdants
|
|
|
|
for inscrit in inscrits:
|
|
|
|
if inscrit != winner:
|
|
|
|
new_context = dict(context)
|
2018-10-06 12:35:49 +02:00
|
|
|
new_context["acheteur"] = inscrit.user
|
2017-10-23 20:30:11 +02:00
|
|
|
|
2018-01-10 20:00:34 +01:00
|
|
|
mails.append(
|
2020-09-15 11:49:05 +02:00
|
|
|
EmailMessage(
|
|
|
|
subject=subject,
|
|
|
|
body=loader.render_to_string(
|
|
|
|
"bda/mails/revente-tirage-loser.txt",
|
|
|
|
context=new_context,
|
|
|
|
),
|
2018-10-06 12:35:49 +02:00
|
|
|
from_email=settings.MAIL_DATA["revente"]["FROM"],
|
2018-01-10 20:00:34 +01:00
|
|
|
to=[inscrit.user.email],
|
2020-09-15 11:49:05 +02:00
|
|
|
),
|
2017-11-24 06:53:31 +01:00
|
|
|
)
|
|
|
|
|
2018-01-10 20:00:34 +01:00
|
|
|
mail_conn = mail.get_connection()
|
|
|
|
mail_conn.send_messages(mails)
|
2016-11-13 00:48:03 +01:00
|
|
|
# Si personne ne veut de la place, elle part au shotgun
|
|
|
|
else:
|
2016-10-27 16:56:54 +02:00
|
|
|
self.shotgun = True
|
2016-09-21 15:39:01 +02:00
|
|
|
self.tirage_done = True
|
2016-09-26 20:41:59 +02:00
|
|
|
self.save()
|
2017-10-26 12:40:11 +02:00
|
|
|
return winner
|