2016-11-20 16:39:26 +01:00
|
|
|
"""
|
|
|
|
Gestion en ligne de commande des mails de rappel.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from datetime import timedelta
|
2018-10-06 12:35:49 +02:00
|
|
|
|
2016-07-12 20:35:42 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.utils import timezone
|
2018-10-06 12:35:49 +02:00
|
|
|
|
2016-07-12 20:35:42 +02:00
|
|
|
from bda.models import Spectacle
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2018-10-06 12:35:49 +02:00
|
|
|
help = "Envoie les mails de rappel des spectacles dont la date " "approche.\nNe renvoie pas les mails déjà envoyés."
|
2016-11-12 11:09:40 +01:00
|
|
|
leave_locale_alone = True
|
2016-07-12 20:35:42 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
now = timezone.now()
|
2016-07-15 02:20:58 +02:00
|
|
|
delay = timedelta(days=4)
|
2018-10-06 12:35:49 +02:00
|
|
|
shows = (
|
|
|
|
Spectacle.objects.filter(date__range=(now, now + delay))
|
|
|
|
.filter(tirage__active=True)
|
|
|
|
.filter(rappel_sent__isnull=True)
|
2016-07-12 20:35:42 +02:00
|
|
|
.all()
|
2018-10-06 12:35:49 +02:00
|
|
|
)
|
2016-07-12 20:35:42 +02:00
|
|
|
for show in shows:
|
|
|
|
show.send_rappel()
|
2018-10-06 12:35:49 +02:00
|
|
|
self.stdout.write("Mails de rappels pour %s envoyés avec succès." % show)
|
2016-07-12 20:35:42 +02:00
|
|
|
if not shows:
|
2018-10-06 12:35:49 +02:00
|
|
|
self.stdout.write("Aucun mail à envoyer.")
|