Commit 83930040 authored by fred's avatar fred

add model for concrete stream occurences

parent e0368dcf
import datetime
from django.core.management.base import BaseCommand
from nonstop.models import RecurringStreamDiffusion, RecurringStreamOccurence
from emissions.models import Absence
class Command(BaseCommand):
def handle(self, verbosity, **kwargs):
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)
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():
occurence.delete()
elif not occurence.id:
occurence.save()
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-05-21 09:00
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('nonstop', '0023_recurringstreamdiffusion'),
]
operations = [
migrations.CreateModel(
name='RecurringStreamOccurence',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('datetime', models.DateTimeField(db_index=True, verbose_name='Date/time')),
('diffusion', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='nonstop.RecurringStreamDiffusion')),
],
),
]
......@@ -282,6 +282,14 @@ class RecurringStreamDiffusion(models.Model):
stream = models.ForeignKey(Stream)
is_active = models.BooleanField('Active', default=True)
def __str__(self):
return _('Recurring Stream for %s') % self.schedule
class RecurringStreamOccurence(models.Model):
diffusion = models.ForeignKey(RecurringStreamDiffusion, on_delete=models.CASCADE)
datetime = models.DateTimeField(_('Date/time'), db_index=True)
@receiver(post_delete)
def remove_soundfile(sender, instance=None, **kwargs):
......
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