gestioCOF/bda/management/commands/manage_reventes.py

44 lines
1.6 KiB
Python
Raw Normal View History

2016-09-21 15:30:41 +02:00
# -*- coding: utf-8 -*-
"""
Gestion en ligne de commande des reventes.
"""
2016-09-21 15:30:41 +02:00
from __future__ import unicode_literals
from datetime import timedelta
2016-09-21 15:30:41 +02:00
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"
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:
# Check si < 24h
if (revente.attribution.spectacle.date <=
revente.date + timedelta(days=1)) and \
now >= revente.date + timedelta(minutes=15) and \
2016-09-21 15:30:41 +02:00
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.mail_shotgun()
2016-09-26 15:31:09 +02:00
self.stdout.write("Mail de disponibilité immédiate envoyé")
2016-09-21 15:30:41 +02:00
# Check si délai de retrait dépassé
elif (now >= revente.date + timedelta(hours=1) 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()
2016-09-26 15:31:09 +02:00
self.stdout.write("Mail d'inscription à une revente envoyé")
2016-09-21 15:30:41 +02:00
# Check si tirage à faire
2016-11-14 15:52:02 +01:00
elif (now >= revente.date_tirage and
not revente.tirage_done):
2016-10-03 16:47:22 +02:00
self.stdout.write(str(now))
2016-09-21 15:30:41 +02:00
revente.tirage()
2016-09-26 15:31:09 +02:00
self.stdout.write("Tirage effectué, mails envoyés")