forked from rc/aircox
update home page + sidebar items sizing
This commit is contained in:
@ -1,33 +1,32 @@
|
||||
import datetime
|
||||
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(PageListView):
|
||||
class HomeView(BaseView, ListView):
|
||||
template_name = 'aircox/home.html'
|
||||
model = Page
|
||||
queryset = Page.objects.select_subclasses()
|
||||
paginate_by = 10
|
||||
list_count = 40
|
||||
model = Diffusion
|
||||
attach_to_value = StaticPage.ATTACH_TO_HOME
|
||||
queryset = Diffusion.objects.on_air().select_related('episode')
|
||||
logs_count = 5
|
||||
has_filters = False
|
||||
attach_to_value = StaticPage.ATTACH_TO_HOME
|
||||
|
||||
def get_logs(self):
|
||||
today = datetime.date.today()
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().date(date.today())
|
||||
|
||||
def get_logs(self, diffusions):
|
||||
today = date.today()
|
||||
logs = Log.objects.on_air().date(today).filter(track__isnull=False)
|
||||
diffs = Diffusion.objects.on_air().date(today)
|
||||
return Log.merge_diffusions(logs, diffs, self.logs_count)
|
||||
# diffs = Diffusion.objects.on_air().date(today)
|
||||
return Log.merge_diffusions(logs, diffusions, self.logs_count)
|
||||
|
||||
def get_sidebar_queryset(self):
|
||||
today = datetime.date.today()
|
||||
return Diffusion.objects.on_air().date(today)
|
||||
|
||||
def get_top_diffs(self):
|
||||
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)
|
||||
@ -37,10 +36,14 @@ class HomeView(PageListView):
|
||||
diffs = next_diffs[:3]
|
||||
return diffs
|
||||
|
||||
def get_last_publications(self):
|
||||
return Page.objects.select_subclasses().published() \
|
||||
.order_by('-pub_date')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['logs'] = self.get_logs()
|
||||
kwargs['top_diffs'] = self.get_top_diffs()
|
||||
return super().get_context_data(**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
|
||||
|
||||
|
Reference in New Issue
Block a user