forked from rc/aircox
logs
This commit is contained in:
parent
ade97c9a30
commit
d4f06c8a8f
|
@ -4,16 +4,6 @@ Manage diffusions using schedules, to update, clean up or check diffusions.
|
||||||
A generated diffusion can be unconfirmed, that means that the user must confirm
|
A generated diffusion can be unconfirmed, that means that the user must confirm
|
||||||
it by changing its type to "normal". The behaviour is controlled using
|
it by changing its type to "normal". The behaviour is controlled using
|
||||||
--approval.
|
--approval.
|
||||||
|
|
||||||
Different actions are available:
|
|
||||||
- "update" is the process that is used to generated them using programs
|
|
||||||
schedules for the (given) month.
|
|
||||||
|
|
||||||
- "clean" will remove all diffusions that are still unconfirmed and have been
|
|
||||||
planified before the (given) month.
|
|
||||||
|
|
||||||
- "check" will remove all diffusions that are unconfirmed and have been planified
|
|
||||||
from the (given) month and later.
|
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -64,13 +64,14 @@ class DiffusionQuerySet(BaseRerunQuerySet):
|
||||||
""" On air diffusions """
|
""" On air diffusions """
|
||||||
return self.filter(type=Diffusion.TYPE_ON_AIR)
|
return self.filter(type=Diffusion.TYPE_ON_AIR)
|
||||||
|
|
||||||
|
# TODO: rename to `datetime`
|
||||||
def now(self, now=None, order=True):
|
def now(self, now=None, order=True):
|
||||||
""" Diffusions occuring now """
|
""" Diffusions occuring now """
|
||||||
now = now or tz.now()
|
now = now or tz.now()
|
||||||
qs = self.filter(start__lte=now, end__gte=now).distinct()
|
qs = self.filter(start__lte=now, end__gte=now).distinct()
|
||||||
return qs.order_by('start') if order else qs
|
return qs.order_by('start') if order else qs
|
||||||
|
|
||||||
def today(self, today=None, order=True):
|
def date(self, today=None, order=True):
|
||||||
""" Diffusions occuring today. """
|
""" Diffusions occuring today. """
|
||||||
today = today or datetime.date.today()
|
today = today or datetime.date.today()
|
||||||
start = tz.datetime.combine(today, datetime.time())
|
start = tz.datetime.combine(today, datetime.time())
|
||||||
|
|
|
@ -24,7 +24,7 @@ class LogQuerySet(models.QuerySet):
|
||||||
return self.filter(station=station) if id is None else \
|
return self.filter(station=station) if id is None else \
|
||||||
self.filter(station_id=id)
|
self.filter(station_id=id)
|
||||||
|
|
||||||
def today(self, date):
|
def date(self, date):
|
||||||
return self.filter(date__date=date)
|
return self.filter(date__date=date)
|
||||||
|
|
||||||
def after(self, date):
|
def after(self, date):
|
||||||
|
@ -133,7 +133,7 @@ class LogQuerySet(models.QuerySet):
|
||||||
if os.path.exists(path) and not force:
|
if os.path.exists(path) and not force:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
qs = self.station(station).today(date)
|
qs = self.station(station).date(date)
|
||||||
|
|
||||||
if not qs.exists():
|
if not qs.exists():
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -17,13 +17,13 @@ class HomeView(PageListView):
|
||||||
|
|
||||||
def get_logs(self):
|
def get_logs(self):
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
logs = Log.objects.on_air().today(today).filter(track__isnull=False)
|
logs = Log.objects.on_air().date(today).filter(track__isnull=False)
|
||||||
diffs = Diffusion.objects.on_air().today(today)
|
diffs = Diffusion.objects.on_air().date(today)
|
||||||
return Log.merge_diffusions(logs, diffs, self.logs_count)
|
return Log.merge_diffusions(logs, diffs, self.logs_count)
|
||||||
|
|
||||||
def get_sidebar_queryset(self):
|
def get_sidebar_queryset(self):
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
return Diffusion.objects.on_air().today(today)
|
return Diffusion.objects.on_air().date(today)
|
||||||
|
|
||||||
def get_top_diffs(self):
|
def get_top_diffs(self):
|
||||||
now = tz.now()
|
now = tz.now()
|
||||||
|
|
|
@ -19,11 +19,12 @@ __all__ = ['LogListMixin', 'LogListView']
|
||||||
|
|
||||||
class LogListMixin(GetDateMixin):
|
class LogListMixin(GetDateMixin):
|
||||||
model = Log
|
model = Log
|
||||||
|
min_date = None
|
||||||
|
|
||||||
def get_date(self):
|
def get_date(self):
|
||||||
date, today = super().get_date(), datetime.date.today()
|
date = super().get_date()
|
||||||
if date is not None and not self.request.user.is_staff:
|
if date is not None and not self.request.user.is_staff:
|
||||||
return min(date, today)
|
return min(date, datetime.date.today())
|
||||||
return date
|
return date
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
@ -31,13 +32,13 @@ class LogListMixin(GetDateMixin):
|
||||||
# by the diffusions' queryset.
|
# by the diffusions' queryset.
|
||||||
qs = super().get_queryset().on_air().filter(track__isnull=False) \
|
qs = super().get_queryset().on_air().filter(track__isnull=False) \
|
||||||
.filter(date__lte=tz.now())
|
.filter(date__lte=tz.now())
|
||||||
return qs.today(self.date) if self.date is not None else \
|
return qs.date(self.date) if self.date is not None else \
|
||||||
qs.after(self.min_date) if self.min_date is not None else qs
|
qs.after(self.min_date) if self.min_date is not None else qs
|
||||||
|
|
||||||
def get_diffusions_queryset(self):
|
def get_diffusions_queryset(self):
|
||||||
qs = Diffusion.objects.station(self.station).on_air() \
|
qs = Diffusion.objects.station(self.station).on_air() \
|
||||||
.filter(start__lte=tz.now())
|
.filter(start__lte=tz.now())
|
||||||
return qs.today(self.date) if self.date is not None else \
|
return qs.date(self.date) if self.date is not None else \
|
||||||
qs.after(self.min_date) if self.min_date is not None else qs
|
qs.after(self.min_date) if self.min_date is not None else qs
|
||||||
|
|
||||||
def get_object_list(self, logs, full=False):
|
def get_object_list(self, logs, full=False):
|
||||||
|
@ -60,17 +61,19 @@ class LogListView(BaseView, LogListMixin, ListView):
|
||||||
has_filters = True
|
has_filters = True
|
||||||
|
|
||||||
def get_date(self):
|
def get_date(self):
|
||||||
date, today = super().get_date(), datetime.date.today()
|
date = super().get_date()
|
||||||
return today if date is None else min(date, today)
|
return datetime.date.today() if date is None else date
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
|
kwargs = super().get_context_data(**kwargs)
|
||||||
|
print('objects:', self.date, self.get_queryset(), kwargs['object_list'])
|
||||||
kwargs.update({
|
kwargs.update({
|
||||||
'date': self.date,
|
'date': self.date,
|
||||||
'dates': (today - datetime.timedelta(days=i) for i in range(0, 7)),
|
'dates': (today - datetime.timedelta(days=i) for i in range(0, 7)),
|
||||||
'object_list': self.get_object_list(self.object_list),
|
'object_list': self.get_object_list(self.object_list),
|
||||||
})
|
})
|
||||||
return super().get_context_data(**kwargs)
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
# Logs are accessible through API only with this list view
|
# Logs are accessible through API only with this list view
|
||||||
|
@ -86,11 +89,11 @@ class LogListAPIView(LogListMixin, BaseAPIView, ListAPIView):
|
||||||
serializer_class = LogInfoSerializer
|
serializer_class = LogInfoSerializer
|
||||||
queryset = Log.objects.all()
|
queryset = Log.objects.all()
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get_date(self):
|
||||||
self.date = self.get_date()
|
date = super().get_date()
|
||||||
if self.date is None:
|
if date is None:
|
||||||
self.min_date = tz.now() - tz.timedelta(minutes=30)
|
self.min_date = tz.now() - tz.timedelta(minutes=30)
|
||||||
return super().get(*args, **kwargs)
|
return date
|
||||||
|
|
||||||
def get_object_list(self, logs, full):
|
def get_object_list(self, logs, full):
|
||||||
return [LogInfo(obj) for obj in super().get_object_list(logs, full)]
|
return [LogInfo(obj) for obj in super().get_object_list(logs, full)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user