Add notif time

In case of a gestioCOF bug, we keep the notification time in memory to
still do the drawing 1-3 days after.
This commit is contained in:
Ludovic Stephan 2017-10-23 20:52:25 +02:00
parent 684603709e
commit 6a6549e0d7
5 changed files with 61 additions and 20 deletions

View file

@ -225,7 +225,7 @@ class SpectacleReventeAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['answered_mail'].queryset = (
self.fields['confirmed_entry'].queryset = (
Participant.objects
.select_related('user', 'tirage')
)
@ -292,8 +292,8 @@ class SpectacleReventeAdmin(admin.ModelAdmin):
revente.soldTo = None
revente.notif_sent = False
revente.tirage_done = False
if revente.answered_mail:
revente.answered_mail.clear()
if revente.confirmed_entry:
revente.confirmed_entry.clear()
revente.save()
self.message_user(
request,

View file

@ -110,7 +110,7 @@ class ReventeTirageAnnulForm(forms.Form):
def __init__(self, participant, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['reventes'].queryset = (
participant.wanted.filter(soldTo__isnull=True)
participant.entered.filter(soldTo__isnull=True)
.select_related('attribution__spectacle')
)
@ -130,7 +130,7 @@ class ReventeTirageForm(forms.Form):
notif_sent=True,
shotgun=False,
tirage_done=False
).exclude(answered_mail=participant)
).exclude(confirmed_entry=participant)
.select_related('attribution__spectacle')
)

View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bda', '0011_tirage_appear_catalogue'),
]
operations = [
migrations.RemoveField(
model_name='spectaclerevente',
name='answered_mail',
),
migrations.AddField(
model_name='spectaclerevente',
name='confirmed_entry',
field=models.ManyToManyField(blank=True, related_name='entered', to='bda.Participant'),
),
migrations.AddField(
model_name='spectaclerevente',
name='notif_time',
field=models.DateTimeField(blank=True, verbose_name="Moment d'envoi de la notification", null=True),
),
]

View file

@ -218,9 +218,9 @@ class SpectacleRevente(models.Model):
related_name="revente")
date = models.DateTimeField("Date de mise en vente",
default=timezone.now)
answered_mail = models.ManyToManyField(Participant,
related_name="wanted",
blank=True)
confirmed_entry = models.ManyToManyField(Participant,
related_name="entered",
blank=True)
seller = models.ForeignKey(Participant,
related_name="original_shows",
verbose_name="Vendeur")
@ -229,8 +229,13 @@ class SpectacleRevente(models.Model):
notif_sent = models.BooleanField("Notification envoyée",
default=False)
notif_time = models.DateTimeField("Moment d'envoi de la notification",
blank=True, null=True)
tirage_done = models.BooleanField("Tirage effectué",
default=False)
shotgun = models.BooleanField("Disponible immédiatement",
default=False)
####
@ -248,17 +253,23 @@ class SpectacleRevente(models.Model):
max_wait_time = timedelta(days=3)
min_wait_time = timedelta(days=1)
@property
def real_notif_time(self):
if self.notif_time:
return self.notif_time
else:
return self.date + self.remorse_time
@property
def date_tirage(self):
"""Renvoie la date du tirage au sort de la revente."""
notif_time = self.date + self.remorse_time
remaining_time = (self.attribution.spectacle.date
- notif_time - self.min_margin)
- self.real_notif_time - self.min_margin)
delay = min(remaining_time, self.max_wait_time)
return notif_time + delay
return self.real_notif_time + delay
@property
def is_urgent(self):
@ -285,7 +296,7 @@ class SpectacleRevente(models.Model):
"""Réinitialise la revente pour permettre une remise sur le marché"""
self.seller = self.attribution.participant
self.date = timezone.now()
self.answered_mail.clear()
self.confirmed_entry.clear()
self.soldTo = None
self.notif_sent = False
self.tirage_done = False
@ -311,6 +322,7 @@ class SpectacleRevente(models.Model):
]
send_mass_custom_mail(datatuple)
self.notif_sent = True
self.notif_time = timezone.now()
self.save()
def mail_shotgun(self):
@ -332,6 +344,7 @@ class SpectacleRevente(models.Model):
]
send_mass_custom_mail(datatuple)
self.notif_sent = True
self.notif_time = timezone.now()
# Flag inutile, sauf si l'horloge interne merde
self.tirage_done = True
self.shotgun = True
@ -343,7 +356,7 @@ class SpectacleRevente(models.Model):
parmis les personnes intéressées par le spectacle. Les personnes sont
ensuites prévenues par mail du résultat du tirage.
"""
inscrits = list(self.answered_mail.all())
inscrits = list(self.confirmed_entry.all())
spectacle = self.attribution.spectacle
seller = self.seller

View file

@ -420,8 +420,8 @@ def revente_manage(request, tirage_id):
revente.notif_sent = False
revente.tirage_done = False
revente.shotgun = False
if revente.answered_mail:
revente.answered_mail.clear()
if revente.confirmed_entry:
revente.confirmed_entry.clear()
revente.save()
overdue = participant.attribution_set.filter(
@ -454,7 +454,7 @@ def revente_tirages(request, tirage_id):
sub = 0
reventes = subform.cleaned_data['reventes']
for revente in reventes:
revente.answered_mail.add(participant)
revente.confirmed_entry.add(participant)
sub += 1
if sub > 0:
plural = "s" if sub > 1 else ""
@ -470,7 +470,7 @@ def revente_tirages(request, tirage_id):
unsub = 0
reventes = annulform.cleaned_data['reventes']
for revente in reventes:
revente.answered_mail.remove(participant)
revente.confirmed_entry.remove(participant)
unsub += 1
if unsub > 0:
plural = "s" if unsub > 1 else ""
@ -493,7 +493,7 @@ def revente_confirm(request, revente_id):
return render(request, "bda/revente/wrongtime.html",
{"revente": revente})
revente.answered_mail.add(participant)
revente.confirmed_entry.add(participant)
return render(request, "bda/revente/confirmed.html",
{"spectacle": revente.attribution.spectacle,
"date": revente.date_tirage})
@ -526,12 +526,12 @@ def revente_subscribe(request, tirage_id):
# la revente ayant le moins d'inscrits
min_resell = (
qset.filter(shotgun=False)
.annotate(nb_subscribers=Count('answered_mail'))
.annotate(nb_subscribers=Count('confirmed_entry'))
.order_by('nb_subscribers')
.first()
)
if min_resell is not None:
min_resell.answered_mail.add(participant)
min_resell.confirmed_entry.add(participant)
inscrit_revente.append(spectacle)
success = True
else: