forked from DGNum/gestioCOF
31 lines
980 B
Python
31 lines
980 B
Python
|
# -*- 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.'
|
||
|
|
||
|
def handle(self, *args, **options):
|
||
|
now = timezone.now()
|
||
|
delay = timedelta(4)
|
||
|
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()
|
||
|
show.rappel_sent = now
|
||
|
show.save()
|
||
|
self.stdout.write(
|
||
|
'Mails de rappels pour %s envoyés avec succès.' % show)
|
||
|
if not shows:
|
||
|
self.stdout.write('Aucun mail à envoyer.')
|