add pdocasts

This commit is contained in:
bkfox 2023-11-28 02:16:40 +01:00
parent ed9affbef6
commit 712ab223ba
9 changed files with 91 additions and 24 deletions

View File

@ -0,0 +1,32 @@
# Generated by Django 4.2.1 on 2023-11-28 01:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("aircox", "0015_alter_schedule_timezone_alter_staticpage_attach_to"),
]
operations = [
migrations.AlterField(
model_name="staticpage",
name="attach_to",
field=models.SmallIntegerField(
blank=True,
choices=[
(0, "Home page"),
(1, "Diffusions page"),
(2, "Logs page"),
(3, "Programs list"),
(4, "Episodes list"),
(5, "Articles list"),
(6, "Publications list"),
(7, "Podcasts list"),
],
help_text="display this page content to related element",
null=True,
verbose_name="attach to",
),
),
]

View File

@ -246,6 +246,7 @@ class StaticPage(BasePage):
ATTACH_TO_EPISODES = 0x04
ATTACH_TO_ARTICLES = 0x05
ATTACH_TO_PAGES = 0x06
ATTACH_TO_PODCASTS = 0x07
ATTACH_TO_CHOICES = (
(ATTACH_TO_HOME, _("Home page")),
@ -255,6 +256,7 @@ class StaticPage(BasePage):
(ATTACH_TO_EPISODES, _("Episodes list")),
(ATTACH_TO_ARTICLES, _("Articles list")),
(ATTACH_TO_PAGES, _("Publications list")),
(ATTACH_TO_PODCASTS, _("Podcasts list")),
)
VIEWS = {
ATTACH_TO_HOME: "home",

View File

@ -48,6 +48,26 @@
</section>
{% endif %}
{% if last_podcasts %}
<section class="container">
<h2 class="title is-3 p-2">{% translate "Last podcasts" %}</h2>
<a-carousel>
{% for object in last_podcasts %}
{% page_widget "card" object open=True %}
{% endfor %}
</a-carousel>
<nav class="nav-urls">
<a href="{% url "episode-list" %}?podcast=true"
aria-label="{% translate "Show all podcasts" %}">
{% translate "All podcasts" %}
</a>
</nav>
</section>
{% endif %}
{% if last_publications %}
<section class="container">
<h2 class="title is-3 p-2">{% translate "Last publications" %}</h2>

View File

@ -11,7 +11,7 @@
<section class="container">
<h3 class="title is-3">{% translate "Last Episodes" %}</h3>
<a-carousel section-class="card-grid">
{% for object in episodes|slice:":3" %}
{% for object in episodes %}
{% page_widget "card" object %}
{% endfor %}
</a-carousel>
@ -30,7 +30,7 @@
<h3 class="title is-3">{% translate "Last Articles" %}</h3>
<a-carousel section-class="card-grid">
{% for object in articles|slice:3 %}
{% for object in articles %}
{% page_widget "card" object %}
{% endfor %}
</a-carousel>

View File

@ -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

View File

@ -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")

View File

@ -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)

View File

@ -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"]

View File

@ -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)