add pdocasts
This commit is contained in:
@ -8,6 +8,7 @@ __all__ = ("BaseView", "BaseAPIView")
|
||||
|
||||
class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
header_template_name = "aircox/widgets/header.html"
|
||||
related_count = 7
|
||||
|
||||
@property
|
||||
def station(self):
|
||||
@ -16,6 +17,14 @@ class BaseView(TemplateResponseMixin, ContextMixin):
|
||||
# def get_queryset(self):
|
||||
# return super().get_queryset().station(self.station)
|
||||
|
||||
def get_related_queryset(self):
|
||||
"""Return a queryset of related pages or None."""
|
||||
return None
|
||||
|
||||
def get_related_url(self):
|
||||
"""Return an url to the list of related pages."""
|
||||
return None
|
||||
|
||||
def get_page(self):
|
||||
return None
|
||||
|
||||
|
@ -33,3 +33,11 @@ class EpisodeListView(PageListView):
|
||||
filterset_class = EpisodeFilters
|
||||
parent_model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_EPISODES
|
||||
|
||||
|
||||
class PodcastListView(PageListView):
|
||||
model = Episode
|
||||
filterset_class = EpisodeFilters
|
||||
parent_model = Program
|
||||
attach_to_value = StaticPage.ATTACH_TO_PODCASTS
|
||||
queryset = Episode.objects.published().with_podcasts().order_by("-pub_date")
|
||||
|
@ -1,9 +1,9 @@
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
from django.utils import timezone as tz
|
||||
from django.views.generic import ListView
|
||||
|
||||
from ..models import Diffusion, Log, Page, StaticPage
|
||||
from ..models import Diffusion, Episode, Log, Page, StaticPage
|
||||
from .base import BaseView
|
||||
from .mixins import AttachedToMixin
|
||||
|
||||
@ -13,22 +13,24 @@ class HomeView(AttachedToMixin, BaseView, ListView):
|
||||
attach_to_value = StaticPage.ATTACH_TO_HOME
|
||||
model = Diffusion
|
||||
queryset = Diffusion.objects.on_air().select_related("episode").order_by("-start")
|
||||
diffusion_count = 7
|
||||
publications_count = 7
|
||||
log_diffusion_count = 3
|
||||
|
||||
publications_queryset = Page.objects.select_subclasses().published().order_by("-pub_date")
|
||||
podcasts_queryset = Episode.objects.published().with_podcasts().order_by("-pub_date")
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().date(date.today())
|
||||
return super().get_queryset().before(datetime.now() - timedelta(hours=12))
|
||||
|
||||
def get_logs(self, diffusions):
|
||||
today = date.today()
|
||||
# diffs = Diffusion.objects.on_air().date(today)
|
||||
object_list = self.object_list
|
||||
diffs = list(object_list[: self.diffusion_count])
|
||||
diffs = list(object_list[: self.related_count - 3])
|
||||
logs = Log.objects.on_air().date(today).filter(track__isnull=False)
|
||||
if diffs:
|
||||
min_date = diffs[-1].start - timedelta(hours=1)
|
||||
logs = logs.after(min_date)
|
||||
return Log.merge_diffusions(logs, object_list, diff_count=self.diffusion_count)
|
||||
return Log.merge_diffusions(logs, object_list, diff_count=self.log_diffusion_count)
|
||||
|
||||
def get_next_diffs(self):
|
||||
now = tz.now()
|
||||
@ -38,12 +40,12 @@ class HomeView(AttachedToMixin, BaseView, ListView):
|
||||
if current_diff:
|
||||
diffs = [current_diff] + list(next_diffs.exclude(pk=current_diff.pk)[:9])
|
||||
else:
|
||||
diffs = next_diffs[: self.diffusion_count]
|
||||
diffs = next_diffs[: self.related_count]
|
||||
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 = self.publications_queryset.all()
|
||||
parents = set()
|
||||
items = []
|
||||
for publication in qs:
|
||||
@ -51,10 +53,13 @@ class HomeView(AttachedToMixin, BaseView, ListView):
|
||||
if parent_id is not None and parent_id in parents:
|
||||
continue
|
||||
items.append(publication)
|
||||
if len(items) == self.publications_count:
|
||||
if len(items) == self.related_count:
|
||||
break
|
||||
return items
|
||||
|
||||
def get_last_podcasts(self):
|
||||
return self.podcasts_queryset.all()[: self.related_count]
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
next_diffs = self.get_next_diffs()
|
||||
current_diff = next_diffs and next_diffs[0]
|
||||
@ -66,6 +71,7 @@ class HomeView(AttachedToMixin, BaseView, ListView):
|
||||
"logs": self.get_logs(self.object_list),
|
||||
"next_diffs": next_diffs,
|
||||
"last_publications": self.get_last_publications(),
|
||||
"last_podcasts": self.get_last_podcasts(),
|
||||
}
|
||||
)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
@ -133,16 +133,6 @@ class PageDetailView(BasePageDetailView):
|
||||
template_name = None
|
||||
context_object_name = "page"
|
||||
|
||||
related_count = 7
|
||||
|
||||
def get_related_queryset(self):
|
||||
"""Return a queryset of related pages or None."""
|
||||
return None
|
||||
|
||||
def get_related_url(self):
|
||||
"""Return an url to the list of related pages."""
|
||||
return None
|
||||
|
||||
def get_template_names(self):
|
||||
return super().get_template_names() + ["aircox/page_detail.html"]
|
||||
|
||||
|
@ -39,8 +39,8 @@ class ProgramDetailView(BaseProgramMixin, PageDetailView):
|
||||
return reverse("program-list") + f"?category__id={self.object.category_id}"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
episodes = Episode.objects.program(self.object).published().order_by("-pub_date")
|
||||
articles = Article.objects.parent(self.object).published().order_by("-pub_date")
|
||||
episodes = Episode.objects.program(self.object).published().order_by("-pub_date")[: self.related_count]
|
||||
articles = Article.objects.parent(self.object).published().order_by("-pub_date")[: self.related_count]
|
||||
return super().get_context_data(articles=articles, episodes=episodes, **kwargs)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user