code quality

This commit is contained in:
bkfox
2023-03-13 17:47:00 +01:00
parent 934817da8a
commit 112770eddf
162 changed files with 4798 additions and 4069 deletions

View File

@ -1,19 +1,17 @@
from datetime import date
from django.utils.translation import gettext as _
from django.utils import timezone as tz
from django.views.generic import ListView
from ..models import Diffusion, Log, Page, StaticPage
from .base import BaseView
from .page import PageListView
class HomeView(BaseView, ListView):
template_name = 'aircox/home.html'
template_name = "aircox/home.html"
model = Diffusion
attach_to_value = StaticPage.ATTACH_TO_HOME
queryset = Diffusion.objects.on_air().select_related('episode')
queryset = Diffusion.objects.on_air().select_related("episode")
logs_count = 5
publications_count = 5
has_filters = False
@ -32,15 +30,16 @@ class HomeView(BaseView, ListView):
current_diff = Diffusion.objects.on_air().now(now).first()
next_diffs = Diffusion.objects.on_air().after(now)
if current_diff:
diffs = [current_diff] + list(next_diffs.exclude(pk=current_diff.pk)[:2])
diffs = [current_diff] + list(
next_diffs.exclude(pk=current_diff.pk)[:2]
)
else:
diffs = next_diffs[:3]
return diffs
def get_last_publications(self):
# note: with postgres db, possible to use distinct()
qs = Page.objects.select_subclasses().published() \
.order_by('-pub_date')
qs = Page.objects.select_subclasses().published().order_by("-pub_date")
parents = set()
items = []
for publication in qs:
@ -54,8 +53,7 @@ class HomeView(BaseView, ListView):
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]
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