work on design: items, components
This commit is contained in:
@ -8,6 +8,7 @@ __all__ = ("BaseView", "BaseAPIView")
|
||||
|
||||
|
||||
class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
header_template_name = "aircox/widgets/header.html"
|
||||
has_sidebar = True
|
||||
"""Show side navigation."""
|
||||
has_filters = False
|
||||
@ -38,6 +39,7 @@ class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
kwargs.setdefault("station", self.station)
|
||||
kwargs.setdefault("page", self.get_page())
|
||||
kwargs.setdefault("has_filters", self.has_filters)
|
||||
kwargs.setdefault("header_template_name", self.header_template_name)
|
||||
|
||||
has_sidebar = kwargs.setdefault("has_sidebar", self.has_sidebar)
|
||||
if has_sidebar and "sidebar_object_list" not in kwargs:
|
||||
|
@ -27,14 +27,15 @@ class HomeView(BaseView, ListView):
|
||||
|
||||
def get_next_diffs(self):
|
||||
now = tz.now()
|
||||
current_diff = Diffusion.objects.on_air().now(now).first()
|
||||
next_diffs = Diffusion.objects.on_air().after(now)
|
||||
query = Diffusion.objects.on_air().select_related("episode")
|
||||
current_diff = query.now(now).first()
|
||||
next_diffs = query.after(now)
|
||||
if current_diff:
|
||||
diffs = [current_diff] + list(
|
||||
next_diffs.exclude(pk=current_diff.pk)[:2]
|
||||
next_diffs.exclude(pk=current_diff.pk)[:9]
|
||||
)
|
||||
else:
|
||||
diffs = next_diffs[:3]
|
||||
diffs = next_diffs[:10]
|
||||
return diffs
|
||||
|
||||
def get_last_publications(self):
|
||||
@ -52,8 +53,16 @@ class HomeView(BaseView, ListView):
|
||||
return items
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["logs"] = self.get_logs(context["object_list"])
|
||||
context["next_diffs"] = self.get_next_diffs()
|
||||
context["last_publications"] = self.get_last_publications()[:5]
|
||||
return context
|
||||
next_diffs = self.get_next_diffs()
|
||||
current_diff = next_diffs and next_diffs[0]
|
||||
|
||||
kwargs.update(
|
||||
{
|
||||
"object": current_diff.episode,
|
||||
"diffusion": current_diff,
|
||||
"logs": self.get_logs(self.object_list),
|
||||
"next_diffs": next_diffs,
|
||||
"last_publications": self.get_last_publications()[:5],
|
||||
}
|
||||
)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
Reference in New Issue
Block a user