2016-07-12 20:35:42 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.utils import timezone
|
|
|
|
from datetime import timedelta
|
|
|
|
from bda.models import Spectacle
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
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)
|
2016-07-12 20:35:42 +02:00
|
|
|
shows = Spectacle.objects \
|
|
|
|
.filter(date__range=(now, now+delay)) \
|
|
|
|
.filter(tirage__active=True) \
|
|
|
|
.filter(rappel_sent__isnull=True) \
|
|
|
|
.all()
|
|
|
|
for show in shows:
|
|
|
|
show.send_rappel()
|
|
|
|
self.stdout.write(
|
|
|
|
'Mails de rappels pour %s envoyés avec succès.' % show)
|
|
|
|
if not shows:
|
|
|
|
self.stdout.write('Aucun mail à envoyer.')
|