forked from rc/aircox
fix errors in streamer; filter out diff in station.on_air
This commit is contained in:
parent
dcee776c03
commit
97e5945b7d
|
@ -49,8 +49,7 @@ class TrackInline(GenericTabularInline):
|
||||||
ct_fk_field = 'related_id'
|
ct_fk_field = 'related_id'
|
||||||
model = Track
|
model = Track
|
||||||
extra = 0
|
extra = 0
|
||||||
fields = ('artist', 'title', 'info', 'position')
|
fields = ('artist', 'title', 'info', 'position', 'in_seconds', 'tags')
|
||||||
readonly_fields = ('position',)
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Sound)
|
@admin.register(Sound)
|
||||||
|
|
|
@ -15,6 +15,7 @@ from django.conf import settings as main_settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.utils import timezone as tz
|
from django.utils import timezone as tz
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
from aircox.models import Station, Diffusion, Track, Sound, Log #, DiffusionLog, SoundLog
|
from aircox.models import Station, Diffusion, Track, Sound, Log #, DiffusionLog, SoundLog
|
||||||
|
|
||||||
|
@ -56,8 +57,8 @@ class Monitor:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _last_log(self, **kwargs):
|
def get_last_log(self, *args, **kwargs):
|
||||||
return Log.objects.station(self.station, **kwargs) \
|
return Log.objects.station(self.station, *args, **kwargs) \
|
||||||
.select_related('diffusion', 'sound') \
|
.select_related('diffusion', 'sound') \
|
||||||
.order_by('date').last()
|
.order_by('date').last()
|
||||||
|
|
||||||
|
@ -66,14 +67,14 @@ class Monitor:
|
||||||
"""
|
"""
|
||||||
Last log of monitored station
|
Last log of monitored station
|
||||||
"""
|
"""
|
||||||
return self._last_log()
|
return self.get_last_log()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_sound(self):
|
def last_sound(self):
|
||||||
"""
|
"""
|
||||||
Last sound log of monitored station that occurred on_air
|
Last sound log of monitored station that occurred on_air
|
||||||
"""
|
"""
|
||||||
return self._last_log(type = Log.Type.on_air,
|
return self.get_last_log(type = Log.Type.on_air,
|
||||||
sound__isnull = False)
|
sound__isnull = False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -81,7 +82,7 @@ class Monitor:
|
||||||
"""
|
"""
|
||||||
Log of last triggered item (sound or diffusion)
|
Log of last triggered item (sound or diffusion)
|
||||||
"""
|
"""
|
||||||
return self._last_log(type = Log.Type.start,
|
return self.get_last_log(type = Log.Type.start,
|
||||||
diffusion__isnull = False)
|
diffusion__isnull = False)
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,9 +130,11 @@ class Monitor:
|
||||||
current_sound = self.streamer.current_sound
|
current_sound = self.streamer.current_sound
|
||||||
current_source = self.streamer.current_source
|
current_source = self.streamer.current_source
|
||||||
if not current_sound or not current_source:
|
if not current_sound or not current_source:
|
||||||
|
print('no source / no sound', current_sound, current_source)
|
||||||
return
|
return
|
||||||
|
|
||||||
log = self.last_log
|
log = self.get_last_log(models.Q(diffusion__isnull = False) |
|
||||||
|
models.Q(sound__isnull = False))
|
||||||
|
|
||||||
# sound on air changed
|
# sound on air changed
|
||||||
if log.source != current_source.id or \
|
if log.source != current_source.id or \
|
||||||
|
@ -167,6 +170,7 @@ class Monitor:
|
||||||
Log tracks for the given sound log (for streamed programs).
|
Log tracks for the given sound log (for streamed programs).
|
||||||
Called by self.trace
|
Called by self.trace
|
||||||
"""
|
"""
|
||||||
|
# TODO take restart in account
|
||||||
tracks = Track.objects.get_for(object = log.sound) \
|
tracks = Track.objects.get_for(object = log.sound) \
|
||||||
.filter(in_seconds = True)
|
.filter(in_seconds = True)
|
||||||
if not tracks.exists():
|
if not tracks.exists():
|
||||||
|
|
|
@ -235,7 +235,7 @@ class Station(Nameable):
|
||||||
"""
|
"""
|
||||||
return Log.objects.on_air(self, *args, **kwargs)
|
return Log.objects.on_air(self, *args, **kwargs)
|
||||||
|
|
||||||
def on_air(self, date = None, count = 0):
|
def on_air(self, date = None, count = 0, no_cache = False):
|
||||||
"""
|
"""
|
||||||
Return a queryset of what happened on air, based on logs and
|
Return a queryset of what happened on air, based on logs and
|
||||||
diffusions informations. The queryset is sorted by -date.
|
diffusions informations. The queryset is sorted by -date.
|
||||||
|
@ -261,16 +261,18 @@ class Station(Nameable):
|
||||||
if date and date > datetime.date.today():
|
if date and date > datetime.date.today():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
now = tz.now()
|
||||||
if date:
|
if date:
|
||||||
logs = Log.objects.at(self, date)
|
logs = Log.objects.at(self, date)
|
||||||
diffs = Diffusion.objects \
|
diffs = Diffusion.objects \
|
||||||
.at(self, date,
|
.at(self, date, type = Diffusion.Type.normal) \
|
||||||
type = Diffusion.Type.normal) \
|
.filter(start__lte = now) \
|
||||||
.order_by('-start')
|
.order_by('-start')
|
||||||
else:
|
else:
|
||||||
logs = Log.objects
|
logs = Log.objects
|
||||||
diffs = Diffusion.objects.filter(type = Diffusion.Type.normal,
|
diffs = Diffusion.objects \
|
||||||
start__lte = tz.now()) \
|
.filter(type = Diffusion.Type.normal,
|
||||||
|
start__lte = now) \
|
||||||
.order_by('-start')[:count]
|
.order_by('-start')[:count]
|
||||||
|
|
||||||
q = models.Q(diffusion__isnull = False) | \
|
q = models.Q(diffusion__isnull = False) | \
|
||||||
|
@ -1199,24 +1201,22 @@ class Port (models.Model):
|
||||||
|
|
||||||
|
|
||||||
class LogManager(models.Manager):
|
class LogManager(models.Manager):
|
||||||
def station(self, station, qs = None, **kwargs):
|
def station(self, station, *args, **kwargs):
|
||||||
qs = self if qs is None else qs
|
return self.filter(*args, station = station, **kwargs)
|
||||||
return qs.filter(station = station, **kwargs)
|
|
||||||
|
|
||||||
def _at(self, date = None, qs = None, **kwargs):
|
def _at(self, date = None, *args, **kwargs):
|
||||||
start, end = utils.date_range(date)
|
start, end = utils.date_range(date)
|
||||||
qs = self if qs is None else qs
|
|
||||||
# return qs.filter(models.Q(end__gte = start) |
|
# return qs.filter(models.Q(end__gte = start) |
|
||||||
# models.Q(date__lte = end))
|
# models.Q(date__lte = end))
|
||||||
return qs.filter(date__gte = start, date__lte = end, **kwargs)
|
return self.filter(*args, date__gte = start, date__lte = end, **kwargs)
|
||||||
|
|
||||||
def at(self, station = None, date = None, qs = None, **kwargs):
|
def at(self, station = None, date = None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return a queryset of logs that have the given date
|
Return a queryset of logs that have the given date
|
||||||
in their range.
|
in their range.
|
||||||
"""
|
"""
|
||||||
qs = self._at(date, qs, **kwargs)
|
qs = self._at(date, *args, **kwargs)
|
||||||
return self.station(station, qs) if station else qs
|
return qs.filter(station = station) if station else qs
|
||||||
|
|
||||||
# TODO: rename on_air + rename Station.on_air into sth like regular_on_air
|
# TODO: rename on_air + rename Station.on_air into sth like regular_on_air
|
||||||
def on_air(self, station, date = None, **kwargs):
|
def on_air(self, station, date = None, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user