2016-09-21 15:30:41 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-11-20 16:39:26 +01:00
|
|
|
"""
|
|
|
|
Gestion en ligne de commande des reventes.
|
|
|
|
"""
|
|
|
|
|
2016-09-21 15:30:41 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.core.management import BaseCommand
|
|
|
|
from django.utils import timezone
|
|
|
|
from bda.models import SpectacleRevente
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Envoie les mails de notification et effectue " \
|
|
|
|
"les tirages au sort des reventes"
|
2016-11-12 11:09:40 +01:00
|
|
|
leave_locale_alone = True
|
2016-09-21 15:30:41 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
now = timezone.now()
|
|
|
|
reventes = SpectacleRevente.objects.all()
|
|
|
|
for revente in reventes:
|
2017-10-23 20:30:11 +02:00
|
|
|
# Le spectacle est bientôt et on a pas encore envoyé de mail :
|
|
|
|
# on met la place au shotgun et on prévient.
|
|
|
|
if revente.is_urgent and not revente.notif_sent:
|
|
|
|
if revente.can_notif:
|
|
|
|
self.stdout.write(str(now))
|
|
|
|
revente.mail_shotgun()
|
|
|
|
self.stdout.write(
|
|
|
|
"Mails de disponibilité immédiate envoyés "
|
|
|
|
"pour la revente [%s]" % revente
|
|
|
|
)
|
|
|
|
|
|
|
|
# Le spectacle est dans plus longtemps : on prévient
|
|
|
|
elif (revente.can_notif and not revente.notif_sent):
|
2016-10-03 16:47:22 +02:00
|
|
|
self.stdout.write(str(now))
|
2016-09-21 15:30:41 +02:00
|
|
|
revente.send_notif()
|
2017-10-23 20:30:11 +02:00
|
|
|
self.stdout.write(
|
|
|
|
"Mails d'inscription à la revente [%s] envoyés"
|
|
|
|
% revente
|
|
|
|
)
|
|
|
|
|
|
|
|
# On fait le tirage
|
|
|
|
elif (now >= revente.date_tirage and not revente.tirage_done):
|
2016-10-03 16:47:22 +02:00
|
|
|
self.stdout.write(str(now))
|
2017-10-23 20:30:11 +02:00
|
|
|
winner = revente.tirage()
|
|
|
|
self.stdout.write(
|
|
|
|
"Tirage effectué pour la revente [%s]"
|
|
|
|
% revente
|
|
|
|
)
|
|
|
|
|
|
|
|
if winner:
|
|
|
|
self.stdout.write("Gagnant : %s" % winner.user)
|
|
|
|
else:
|
|
|
|
self.stdout.write("Pas de gagnant ; place au shotgun")
|