forked from rc/aircox
create aircox_streamer as separate application
This commit is contained in:
@ -4,7 +4,7 @@ from .program import Program, Stream, Schedule
|
||||
from .episode import Episode, Diffusion
|
||||
from .log import Log
|
||||
from .sound import Sound, Track
|
||||
from .station import Station, Port
|
||||
from .station import Station
|
||||
|
||||
from . import signals
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -44,8 +44,8 @@ def program_post_save(sender, instance, created, *args, **kwargs):
|
||||
Clean-up later diffusions when a program becomes inactive
|
||||
"""
|
||||
if not instance.active:
|
||||
Diffusion.objects.program(instance).after(tz.now()).delete()
|
||||
Episode.object.program(instance).filter(diffusion__isnull=True) \
|
||||
Diffusion.object.program(instance).after(tz.now()).delete()
|
||||
Episode.object.parent(instance).filter(diffusion__isnull=True) \
|
||||
.delete()
|
||||
|
||||
|
||||
@ -94,7 +94,6 @@ def schedule_pre_delete(sender, instance, *args, **kwargs):
|
||||
@receiver(signals.post_delete, sender=Diffusion)
|
||||
def diffusion_post_delete(sender, instance, *args, **kwargs):
|
||||
Episode.objects.filter(diffusion__isnull=True, content__isnull=True,
|
||||
sound__isnull=True) \
|
||||
.delete()
|
||||
sound__isnull=True).delete()
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import os
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from filer.fields.image import FilerImageField
|
||||
@ -9,7 +8,7 @@ from filer.fields.image import FilerImageField
|
||||
from .. import settings
|
||||
|
||||
|
||||
__all__ = ['Station', 'StationQuerySet', 'Port']
|
||||
__all__ = ['Station', 'StationQuerySet']
|
||||
|
||||
|
||||
class StationQuerySet(models.QuerySet):
|
||||
@ -22,6 +21,9 @@ class StationQuerySet(models.QuerySet):
|
||||
return self.order_by('-default', 'pk').first()
|
||||
return self.filter(pk=station).first()
|
||||
|
||||
def active(self):
|
||||
return self.filter(active=True)
|
||||
|
||||
|
||||
class Station(models.Model):
|
||||
"""
|
||||
@ -44,7 +46,12 @@ class Station(models.Model):
|
||||
default = models.BooleanField(
|
||||
_('default station'),
|
||||
default=True,
|
||||
help_text=_('if checked, this station is used as the main one')
|
||||
help_text=_('use this station as the main one.')
|
||||
)
|
||||
active = models.BooleanField(
|
||||
_('active'),
|
||||
default=True,
|
||||
help_text=_('whether this station is still active or not.')
|
||||
)
|
||||
logo = FilerImageField(
|
||||
on_delete=models.SET_NULL, null=True, blank=True,
|
||||
@ -79,6 +86,20 @@ class Station(models.Model):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class PortQuerySet(models.QuerySet):
|
||||
def active(self, value=True):
|
||||
""" Active ports """
|
||||
return self.filter(active=value)
|
||||
|
||||
def output(self):
|
||||
""" Filter in output ports """
|
||||
return self.filter(direction=Port.DIRECTION_OUTPUT)
|
||||
|
||||
def input(self):
|
||||
""" Fitler in input ports """
|
||||
return self.filter(direction=Port.DIRECTION_INPUT)
|
||||
|
||||
|
||||
class Port(models.Model):
|
||||
"""
|
||||
Represent an audio input/output for the audio stream
|
||||
@ -126,6 +147,14 @@ class Port(models.Model):
|
||||
blank=True, null=True
|
||||
)
|
||||
|
||||
objects = PortQuerySet.as_manager()
|
||||
|
||||
def __str__(self):
|
||||
return "{direction}: {type} #{id}".format(
|
||||
direction=self.get_direction_display(),
|
||||
type=self.get_type_display(), id=self.pk or ''
|
||||
)
|
||||
|
||||
def is_valid_type(self):
|
||||
"""
|
||||
Return True if the type is available for the given direction.
|
||||
@ -148,11 +177,3 @@ class Port(models.Model):
|
||||
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return "{direction}: {type} #{id}".format(
|
||||
direction=self.get_direction_display(),
|
||||
type=self.get_type_display(),
|
||||
id=self.pk or ''
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user