forked from DGNum/gestioCOF
added cron management
This commit is contained in:
parent
9e438fac11
commit
051a979a9b
1 changed files with 32 additions and 0 deletions
32
bda/management/commands/manage_reventes.py
Normal file
32
bda/management/commands/manage_reventes.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
from django.utils import timezone
|
||||||
|
from datetime import timedelta
|
||||||
|
from bda.models import SpectacleRevente
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Envoie les mails de notification et effectue " \
|
||||||
|
"les tirages au sort des reventes"
|
||||||
|
|
||||||
|
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 \
|
||||||
|
not revente.notif_sent:
|
||||||
|
revente.mail_shotgun()
|
||||||
|
# Check si délai de retrait dépassé
|
||||||
|
elif (now >= revente.date + timedelta(hours=1) and
|
||||||
|
not revente.notif_sent):
|
||||||
|
revente.send_notif()
|
||||||
|
# Check si tirage à faire
|
||||||
|
elif (now >= revente.expiration_time and
|
||||||
|
not revente.tirage_done):
|
||||||
|
revente.tirage()
|
Loading…
Reference in a new issue