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
|
||||
|
|
8
bda/templates/mail-shotgun.txt
Normal file
8
bda/templates/mail-shotgun.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
Bonjour {{ user.get_full_name }}
|
||||
|
||||
Une place pour le spectacle {{ spectacle.title }} ({{spectacle.date_no_seconds}}) a été postée sur BdA-Revente.
|
||||
|
||||
Puisque ce spectacle a lieu dans moins de 24h, il n'y a pas de tirage au sort pour cette place : elle est disponible immédiatement à l'addresse {{url "bda-buy-revente" spectacle.id}}, à la disposition de tous.
|
||||
|
||||
Chaleureusement,
|
||||
Le BdA
|
11
bda/views.py
11
bda/views.py
|
@ -12,7 +12,8 @@ from django.db import models
|
|||
from django.db.models import Count, Q
|
||||
from django.core import serializers
|
||||
from django.forms.models import inlineformset_factory
|
||||
from django.http import HttpResponseBadRequest
|
||||
from django.http import HttpResponseBadRequest, HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
import hashlib
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
@ -325,7 +326,7 @@ def revente(request, tirage_id):
|
|||
elif 'reinit' in request.POST:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
annulform = AnnulForm(participant, prefix='annul')
|
||||
revente_id = request.POST['transfer'][0]
|
||||
revente_id = request.POST['reinit'][0]
|
||||
rev = SpectacleRevente.objects.filter(soldTo__isnull=False,
|
||||
id=revente_id)
|
||||
if rev.exists():
|
||||
|
@ -333,7 +334,6 @@ def revente(request, tirage_id):
|
|||
revente.date = timezone.now() - timedelta(hours=1)
|
||||
revente.soldTo = None
|
||||
revente.interested = None
|
||||
# schedule job
|
||||
|
||||
else:
|
||||
resellform = ResellForm(participant, prefix='resell')
|
||||
|
@ -430,6 +430,11 @@ def buy_revente(request, spectacle_id):
|
|||
reventes = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle,
|
||||
soldTo__isnull=True)
|
||||
if reventes.filter(seller=participant).exists():
|
||||
revente = reventes.filter(seller=participant)[0]
|
||||
revente.delete()
|
||||
return HttpResponseRedirect(reverse("bda-liste-revente",
|
||||
args=[tirage.id]))
|
||||
|
||||
if not reventes.exists():
|
||||
return render(request, "bda-no-revente.html", {})
|
||||
|
|
Loading…
Reference in a new issue