forked from DGNum/gestioCOF
end
This commit is contained in:
parent
051a979a9b
commit
6b63f0f30f
3 changed files with 59 additions and 11 deletions
|
@ -5,8 +5,8 @@ from __future__ import print_function
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import calendar
|
||||
import datetime
|
||||
import random
|
||||
from datetime import timedelta
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
@ -229,15 +229,29 @@ class SpectacleRevente(models.Model):
|
|||
soldTo = models.ForeignKey(Participant, blank=True, null=True,
|
||||
verbose_name="Vendue à")
|
||||
|
||||
notif_sent = models.BooleanField("Notification envoyée",
|
||||
default=False)
|
||||
tirage_done = models.BooleanField("Tirage effectué",
|
||||
default=False)
|
||||
|
||||
def get_expiration_time(self):
|
||||
remaining_time = (self.attribution.spectacle.date - self.date)
|
||||
delay = max(datetime.timedelta(hours=2),
|
||||
min(remaining_time//2, datetime.timedelta(days=2)))
|
||||
return self.date + delay + datetime.timedelta(hours=1)
|
||||
# L'acheteur doit être connu au plus 12h avant le spectacle
|
||||
remaining_time = (self.attribution.spectacle.date
|
||||
- self.date - timedelta(hours=13))
|
||||
# Au minimum, on attend 2 jours avant le tirage
|
||||
delay = min(remaining_time, timedelta(days=2))
|
||||
# On a aussi 1h pour changer d'avis
|
||||
return self.date + delay + timedelta(hours=1)
|
||||
expiration_time = property(get_expiration_time)
|
||||
|
||||
def get_shotgun(self):
|
||||
return timezone.now() > self.expiration_time
|
||||
# Soit on a dépassé le délai du tirage, soit il reste peu de
|
||||
# temps avant le spectacle
|
||||
# On se laisse 5min de marge pour cron
|
||||
return (timezone.now() > self.expiration_time + timedelta(minutes=5) or
|
||||
(self.attribution.spectacle.date <= timezone.now() +
|
||||
timedelta(days=1))) and (timezone.now() >= self.date +
|
||||
timedelta(minutes=15))
|
||||
shotgun = property(get_shotgun)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -248,7 +262,6 @@ class SpectacleRevente(models.Model):
|
|||
verbose_name = "Revente"
|
||||
|
||||
def send_notif(self):
|
||||
# On récupère la liste des inscrits
|
||||
inscrits = self.attribution.spectacle.revente.select_related('user')
|
||||
|
||||
mails_to_send = []
|
||||
|
@ -260,12 +273,33 @@ class SpectacleRevente(models.Model):
|
|||
'revente': self})
|
||||
mail_tot = mail.EmailMessage(
|
||||
mail_object, mail_body,
|
||||
settings.REVENTE_FROM, [participant.email],
|
||||
settings.REVENTE_FROM, [participant.user.email],
|
||||
[], headers={'Reply-To': settings.REVENTE_REPLY_TO})
|
||||
mails_to_send.append(mail_tot)
|
||||
|
||||
connection = mail.get_connection()
|
||||
connection.send_messages(mails_to_send)
|
||||
self.notif_sent = True
|
||||
|
||||
def mail_shotgun(self):
|
||||
inscrits = self.attribution.spectacle.revente.select_related('user')
|
||||
|
||||
mails_to_send = []
|
||||
mail_object = "%s" % (self.attribution.spectacle)
|
||||
for participant in inscrits:
|
||||
mail_body = render_template('mail-shotgun.txt', {
|
||||
'user': participant.user,
|
||||
'spectacle': self.spectacle,
|
||||
'mail': self.attribution.participant.user.email})
|
||||
mail_tot = mail.EmailMessage(
|
||||
mail_object, mail_body,
|
||||
settings.REVENTE_FROM, [participant.user.email],
|
||||
[], headers={'Reply-To': settings.REVENTE_REPLY_TO})
|
||||
mails_to_send.append(mail_tot)
|
||||
|
||||
connection = mail.get_connection()
|
||||
connection.send_messages(mails_to_send)
|
||||
self.notif_sent = True
|
||||
|
||||
def tirage(self):
|
||||
inscrits = self.interested
|
||||
|
@ -296,3 +330,4 @@ Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email)
|
|||
mail.send_mail("BdA-Revente : %s" % spectacle.title,
|
||||
mail_seller, "bda@ens.fr", [seller.email],
|
||||
fail_silently=False)
|
||||
self.tirage_done = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue