forked from rc/aircox
cfr #121 Co-authored-by: Christophe Siraut <d@tobald.eu.org> Co-authored-by: bkfox <thomas bkfox net> Co-authored-by: Thomas Kairos <thomas@bkfox.net> Reviewed-on: rc/aircox#131 Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be> Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
@ -1,30 +1,57 @@
|
||||
import datetime
|
||||
|
||||
from django.urls import reverse
|
||||
from django.views.generic import ListView
|
||||
|
||||
from aircox.models import Diffusion, StaticPage
|
||||
from aircox.models import Diffusion, Log, StaticPage
|
||||
from .base import BaseView
|
||||
from .mixins import AttachedToMixin, GetDateMixin
|
||||
from .page import attach
|
||||
|
||||
__all__ = ("DiffusionListView",)
|
||||
__all__ = ("DiffusionListView", "TimeTableView")
|
||||
|
||||
|
||||
class DiffusionListView(GetDateMixin, AttachedToMixin, BaseView, ListView):
|
||||
class BaseDiffusionListView(AttachedToMixin, BaseView, ListView):
|
||||
model = Diffusion
|
||||
queryset = Diffusion.objects.on_air().order_by("-start")
|
||||
|
||||
|
||||
class DiffusionListView(BaseDiffusionListView):
|
||||
"""View for timetables."""
|
||||
|
||||
model = Diffusion
|
||||
has_filters = True
|
||||
redirect_date_url = "diffusion-list"
|
||||
attach_to_value = StaticPage.ATTACH_TO_DIFFUSIONS
|
||||
|
||||
|
||||
@attach
|
||||
class TimeTableView(GetDateMixin, BaseDiffusionListView):
|
||||
model = Diffusion
|
||||
redirect_date_url = "timetable-list"
|
||||
attach_to_value = StaticPage.Target.TIMETABLE
|
||||
template_name = "aircox/timetable_list.html"
|
||||
|
||||
def get_date(self):
|
||||
date = super().get_date()
|
||||
return date if date is not None else datetime.date.today()
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().date(self.date).order_by("start")
|
||||
def get_logs(self, date):
|
||||
return Log.objects.on_air().date(self.date).filter(track__isnull=False)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().date(self.date)
|
||||
|
||||
@classmethod
|
||||
def get_secondary_nav(cls):
|
||||
date = datetime.date.today()
|
||||
start = date - datetime.timedelta(days=date.weekday())
|
||||
dates = [start + datetime.timedelta(days=i) for i in range(0, 7)]
|
||||
return tuple((date.strftime("%A %d"), reverse("timetable-list", kwargs={"date": date})) for date in dates)
|
||||
|
||||
def get_context_data(self, object_list=None, **kwargs):
|
||||
start = self.date - datetime.timedelta(days=self.date.weekday())
|
||||
dates = [start + datetime.timedelta(days=i) for i in range(0, 7)]
|
||||
return super().get_context_data(date=self.date, dates=dates, **kwargs)
|
||||
|
||||
if object_list is None:
|
||||
logs = self.get_logs(self.date)
|
||||
object_list = Log.merge_diffusions(logs, self.object_list, group_logs=True)
|
||||
object_list = list(reversed(object_list))
|
||||
return super().get_context_data(date=self.date, dates=dates, object_list=object_list, **kwargs)
|
||||
|
Reference in New Issue
Block a user