sounds_monitor can matches diffusion by time -- based on local timezone
This commit is contained in:
parent
81318e5bd8
commit
28dab0185a
|
@ -105,14 +105,18 @@ class DiffusionAdmin(admin.ModelAdmin):
|
|||
return obj.conflicts.count()
|
||||
return ''
|
||||
|
||||
def end_time(self, obj):
|
||||
return obj.end.strftime('%H:%M')
|
||||
end_time.short_description = _('end')
|
||||
def start_date(self, obj):
|
||||
return obj.local_date.strftime('%Y/%m/%d %H:%M')
|
||||
start_date.short_description = _('start')
|
||||
|
||||
def end_date(self, obj):
|
||||
return obj.local_end.strftime('%H:%M')
|
||||
end_date.short_description = _('end')
|
||||
|
||||
def first(self, obj):
|
||||
return obj.initial.start if obj.initial else ''
|
||||
|
||||
list_display = ('id', 'program', 'start', 'end_time', 'type', 'first', 'archives', 'conflicts_')
|
||||
list_display = ('id', 'program', 'start_date', 'end_date', 'type', 'first', 'archives', 'conflicts_')
|
||||
list_filter = ('type', 'start', 'program')
|
||||
list_editable = ('type',)
|
||||
ordering = ('-start', 'id')
|
||||
|
|
|
@ -21,18 +21,20 @@ To check quality of files, call the command sound_quality_check using the
|
|||
parameters given by the setting AIRCOX_SOUND_QUALITY. This script requires
|
||||
Sox (and soxi).
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import logging
|
||||
import subprocess
|
||||
from argparse import RawTextHelpFormatter
|
||||
import atexit
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler, FileModifiedEvent
|
||||
|
||||
from django.conf import settings as main_settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone as tz
|
||||
|
||||
from aircox.models import *
|
||||
import aircox.settings as settings
|
||||
|
@ -162,21 +164,19 @@ class SoundInfo:
|
|||
if self.year == None or not self.sound or self.sound.diffusion:
|
||||
return;
|
||||
|
||||
diffusion = Diffusion.objects.filter(
|
||||
if self.hour is None:
|
||||
date = datetime.date(self.year, self.month, self.day)
|
||||
else:
|
||||
date = datetime.datetime(self.year, self.month, self.day,
|
||||
self.hour or 0, self.minute or 0)
|
||||
date = tz.get_current_timezone().localize(date)
|
||||
|
||||
diffusion = Diffusion.objects.after(
|
||||
program.station,
|
||||
date,
|
||||
program = program,
|
||||
initial__isnull = True,
|
||||
start__year = self.year,
|
||||
start__month = self.month,
|
||||
start__day = self.day,
|
||||
)
|
||||
|
||||
if self.hour is not None:
|
||||
diffusion = diffusion.filter(
|
||||
hour = self.hour,
|
||||
minute = self.minute
|
||||
)
|
||||
|
||||
diffusion = diffusion.first()
|
||||
).first()
|
||||
if not diffusion:
|
||||
return
|
||||
|
||||
|
|
|
@ -772,26 +772,23 @@ class DiffusionManager(models.Manager):
|
|||
qs = qs.filter(filters, **kwargs)
|
||||
return self.station(station, qs).order_by('start').distinct()
|
||||
|
||||
def after(self, station, date = None, qs = None):
|
||||
def after(self, station, date = None, **kwargs):
|
||||
"""
|
||||
Return a queryset of diffusions that happen after the given
|
||||
date.
|
||||
"""
|
||||
date = utils.date_or_default(date)
|
||||
return self.station(station, qs).filter(
|
||||
start__gte = date,
|
||||
).order_by('start')
|
||||
date = utils.date_or_default(date, keep_type = True)
|
||||
return self.station(station, start__gte = date, **kwargs)\
|
||||
.order_by('start')
|
||||
|
||||
def before(self, station, date = None, qs = None):
|
||||
def before(self, station, date = None, **kwargs):
|
||||
"""
|
||||
Return a queryset of diffusions that finish before the given
|
||||
date.
|
||||
"""
|
||||
date = utils.date_or_default(date)
|
||||
qs = self if qs is None else qs
|
||||
return self.station(station, qs).filter(
|
||||
end__lte = date,
|
||||
).order_by('start')
|
||||
return self.station(station, end__lte = date, **kwargs) \
|
||||
.order_by('start')
|
||||
|
||||
|
||||
class Diffusion(models.Model):
|
||||
|
@ -861,8 +858,34 @@ class Diffusion(models.Model):
|
|||
|
||||
@property
|
||||
def date(self):
|
||||
"""
|
||||
Alias to self.start
|
||||
"""
|
||||
return self.start
|
||||
|
||||
@property
|
||||
def local_date(self):
|
||||
"""
|
||||
Return a version of self.date that is localized to self.timezone;
|
||||
This is needed since datetime are stored as UTC date and we want
|
||||
to get it as local time.
|
||||
"""
|
||||
if not hasattr(self, '_local_date'):
|
||||
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
|
||||
return self._local_date
|
||||
|
||||
@property
|
||||
def local_end(self):
|
||||
"""
|
||||
Return a version of self.date that is localized to self.timezone;
|
||||
This is needed since datetime are stored as UTC date and we want
|
||||
to get it as local time.
|
||||
"""
|
||||
if not hasattr(self, '_local_end'):
|
||||
self._local_end = tz.localtime(self.end, tz.get_current_timezone())
|
||||
return self._local_end
|
||||
|
||||
|
||||
@property
|
||||
def playlist(self):
|
||||
"""
|
||||
|
@ -943,7 +966,7 @@ class Diffusion(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return '{self.program.name} {date} #{self.pk}'.format(
|
||||
self=self, date=self.date.strftime('%Y-%m-%d %H:%M')
|
||||
self=self, date=self.local_date.strftime('%Y/%m/%d %H:%M%z')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -1487,6 +1510,17 @@ class Log(models.Model):
|
|||
def related(self):
|
||||
return self.diffusion or self.sound or self.track
|
||||
|
||||
@property
|
||||
def local_date(self):
|
||||
"""
|
||||
Return a version of self.date that is localized to self.timezone;
|
||||
This is needed since datetime are stored as UTC date and we want
|
||||
to get it as local time.
|
||||
"""
|
||||
if not hasattr(self, '_local_date'):
|
||||
self._local_date = tz.localtime(self.date, tz.get_current_timezone())
|
||||
return self._local_date
|
||||
|
||||
def is_expired(self, date = None):
|
||||
"""
|
||||
Return True if the log is expired. Note that it only check
|
||||
|
@ -1522,7 +1556,7 @@ class Log(models.Model):
|
|||
self.pk,
|
||||
self.get_type_display(),
|
||||
self.source,
|
||||
self.date.strftime('%Y/%m/%d %H:%M'),
|
||||
self.local_date.strftime('%Y/%m/%d %H:%M%z'),
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
|
@ -59,7 +59,8 @@ def schedule_post_saved(sender, instance, created, *args, **kwargs):
|
|||
delta = instance.date - old_sched.date
|
||||
|
||||
# update diffusions...
|
||||
qs = models.Diffusion.objects.after(instance.program.station).filter(
|
||||
qs = models.Diffusion.objects.after(
|
||||
instance.program.station,
|
||||
program = instance.program
|
||||
)
|
||||
for diff in qs:
|
||||
|
|
Loading…
Reference in New Issue
Block a user