Commit 971914fd authored by fred's avatar fred

add recurring random directory occcurences

parent 8b94d05d
......@@ -2,7 +2,12 @@ import datetime
from django.core.management.base import BaseCommand
from nonstop.models import RecurringStreamDiffusion, RecurringStreamOccurence
from nonstop.models import (
RecurringStreamDiffusion,
RecurringStreamOccurence,
RecurringRandomDirectoryDiffusion,
RecurringRandomDirectoryOccurence,
)
from emissions.models import Absence
......@@ -11,11 +16,28 @@ class Command(BaseCommand):
for diffusion in RecurringStreamDiffusion.objects.filter(is_active=True):
next_planned_date = diffusion.schedule.get_next_planned_date(since=datetime.datetime.now())
try:
occurence = RecurringStreamOccurence.objects.get(diffusion=diffusion, datetime=next_planned_date)
occurence = RecurringStreamOccurence.objects.get(
diffusion=diffusion, datetime=next_planned_date
)
except RecurringStreamOccurence.DoesNotExist:
occurence = RecurringStreamOccurence(diffusion=diffusion, datetime=next_planned_date)
if occurence.id and Absence.objects.filter(
emission=diffusion.schedule.emission, datetime=next_planned_date).exists():
if (
occurence.id
and Absence.objects.filter(
emission=diffusion.schedule.emission, datetime=next_planned_date
).exists()
):
occurence.delete()
elif not occurence.id:
occurence.save()
for diffusion in RecurringRandomDirectoryDiffusion.objects.filter(is_active=True):
next_planned_date = diffusion.schedule.get_next_planned_date(since=datetime.datetime.now())
try:
occurence = RecurringRandomDirectoryOccurence.objects.get(
diffusion=diffusion, datetime=next_planned_date
)
except RecurringRandomDirectoryOccurence.DoesNotExist:
occurence = RecurringRandomDirectoryOccurence(diffusion=diffusion, datetime=next_planned_date)
if not occurence.id:
occurence.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment