From ce03a28b4be3ae2d2b4e7f40d5ef5756f3179425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Tue, 12 Jul 2016 20:35:42 +0200 Subject: [PATCH 1/2] Ajoute une commande pour les mails de rappel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les mails de rappel pour les spectacles à venir (dans les 4 jours) peuvent être envoyés à l'aide de la commande `python manage.py sendrappels` Il suffit donc de mettre un cron qui lance cette commande à un intervalle régulier pour ne plus avoir à se soucier des mails de rappel. Fixes #1 --- bda/management/__init__.py | 0 bda/management/commands/__init__.py | 0 bda/management/commands/sendrappels.py | 30 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 bda/management/__init__.py create mode 100644 bda/management/commands/__init__.py create mode 100644 bda/management/commands/sendrappels.py diff --git a/bda/management/__init__.py b/bda/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bda/management/commands/__init__.py b/bda/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bda/management/commands/sendrappels.py b/bda/management/commands/sendrappels.py new file mode 100644 index 00000000..e66b0b23 --- /dev/null +++ b/bda/management/commands/sendrappels.py @@ -0,0 +1,30 @@ +# -*- 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.') From c3631e2cd59d34429a76f8e3f3cebd46e627513b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Fri, 15 Jul 2016 02:20:58 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Am=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bda/management/commands/sendrappels.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bda/management/commands/sendrappels.py b/bda/management/commands/sendrappels.py index e66b0b23..1e8da240 100644 --- a/bda/management/commands/sendrappels.py +++ b/bda/management/commands/sendrappels.py @@ -14,7 +14,7 @@ class Command(BaseCommand): def handle(self, *args, **options): now = timezone.now() - delay = timedelta(4) + delay = timedelta(days=4) shows = Spectacle.objects \ .filter(date__range=(now, now+delay)) \ .filter(tirage__active=True) \ @@ -22,8 +22,6 @@ class Command(BaseCommand): .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: