forked from rc/aircox
code quality
This commit is contained in:
@ -1,43 +1,45 @@
|
||||
from collections import OrderedDict
|
||||
import datetime
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import ListView
|
||||
|
||||
from ..filters import EpisodeFilters
|
||||
from ..models import Diffusion, Episode, Program, StaticPage, Sound
|
||||
from ..models import Diffusion, Episode, Program, StaticPage
|
||||
from .base import BaseView
|
||||
from .program import ProgramPageDetailView
|
||||
from .mixins import AttachedToMixin, GetDateMixin
|
||||
from .page import PageListView
|
||||
from .mixins import AttachedToMixin, GetDateMixin, ParentMixin
|
||||
from .program import ProgramPageDetailView
|
||||
|
||||
|
||||
__all__ = ['EpisodeDetailView', 'EpisodeListView', 'DiffusionListView', 'SoundListView']
|
||||
__all__ = (
|
||||
"EpisodeDetailView",
|
||||
"EpisodeListView",
|
||||
"DiffusionListView",
|
||||
)
|
||||
|
||||
|
||||
class EpisodeDetailView(ProgramPageDetailView):
|
||||
model = Episode
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
if not 'tracks' in kwargs:
|
||||
kwargs['tracks'] = self.object.track_set.order_by('position')
|
||||
if "tracks" not in kwargs:
|
||||
kwargs["tracks"] = self.object.track_set.order_by("position")
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class EpisodeListView(PageListView):
|
||||
model = Episode
|
||||
filterset_class = EpisodeFilters
|
||||
item_template_name = 'aircox/widgets/episode_item.html'
|
||||
item_template_name = "aircox/widgets/episode_item.html"
|
||||
has_headline = True
|
||||
parent_model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_EPISODES
|
||||
|
||||
|
||||
class DiffusionListView(GetDateMixin, AttachedToMixin, BaseView, ListView):
|
||||
""" View for timetables """
|
||||
"""View for timetables."""
|
||||
|
||||
model = Diffusion
|
||||
has_filters = True
|
||||
redirect_date_url = 'diffusion-list'
|
||||
redirect_date_url = "diffusion-list"
|
||||
attach_to_value = StaticPage.ATTACH_TO_DIFFUSIONS
|
||||
|
||||
def get_date(self):
|
||||
@ -45,10 +47,9 @@ class DiffusionListView(GetDateMixin, AttachedToMixin, BaseView, ListView):
|
||||
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')
|
||||
return super().get_queryset().date(self.date).order_by("start")
|
||||
|
||||
def get_context_data(self, **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)
|
||||
|
||||
|
Reference in New Issue
Block a user