]> git.0d.be Git - panikweb-studioneau.git/commitdiff
link homepage recent shows to episode pages
authorFrédéric Péters <fpeters@0d.be>
Thu, 7 Apr 2022 07:57:37 +0000 (09:57 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 7 Apr 2022 07:57:37 +0000 (09:57 +0200)
panikweb_studioneau/templates/home.html
panikweb_studioneau/templates/includes/home-show.html [new file with mode: 0644]
panikweb_studioneau/views.py

index ae97c0d0311bb2b2ee6f8a6ac385fde0aba2193d..345d31b739f9b226f615c7d0905a3766a4bb2ef7 100644 (file)
@@ -21,9 +21,9 @@
   <h2>{% trans "Recent Shows" %}</h2>
 
 <ul class="collection">
-{% for emission in shows %}
+{% for episode in shows %}
     <li>
-    {% emission_resume %}
+      {% include "includes/home-show.html" with episode=episode %}
     </li>
 {% endfor %}
 {% include "includes/end-of-list-of-threes.html" with count=shows|length %}
diff --git a/panikweb_studioneau/templates/includes/home-show.html b/panikweb_studioneau/templates/includes/home-show.html
new file mode 100644 (file)
index 0000000..b2d2bd8
--- /dev/null
@@ -0,0 +1,17 @@
+{% load thumbnail staticfiles %}
+<div class="emission-resume">
+  <a href="{% url 'episode-view' slug=episode.slug emission_slug=episode.emission.slug %}"><div class="image"
+    {% if episode.image %}
+    {% thumbnail episoden.image "350x200" crop="50% 25%" as im %}
+    style="background-image: url({{im.url}})"
+    {% endthumbnail %}
+    {% elif episode.emission.image %}
+    {% thumbnail episode.emission.image "350x200" crop="50% 25%" as im %}
+    style="background-image: url({{im.url}})"
+    {% endthumbnail %}
+    {% endif %}>
+  </div></a>
+  {% include "includes/tags.html" with object=episode.emission %}
+  <h3><a href="{% url 'episode-view' slug=episode.slug emission_slug=episode.emission.slug %}">{{ episode.emission.title }}{% if episode.emission.subtitle %}<br>{{ episode.emission.subtitle }}{% endif %}</a></h3>
+</div>
+
index 9d7044bcfe540ebf102fc883f478d5f27a54231f..7d8709ba5ef8ee64c4ea2dc3c2a59e967b0ebfcc 100644 (file)
@@ -4,7 +4,6 @@ import random
 import panikweb.utils
 import panikweb.views
 from django.conf import settings
-from django.db.models.expressions import RawSQL
 from django.utils.timezone import now
 from django.utils.translation import ugettext_lazy as _
 from django.views.generic.base import TemplateView
@@ -16,27 +15,21 @@ class Home(panikweb.views.Home):
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         # get shows with a recent sound
-        context['shows'] = (
-            Emission.objects.filter(archived=False)
-            .exclude(categories__slug='collection')
-            .annotate(
-                latest_soundfile_timestamp=RawSQL(
-                    '''SELECT MAX(emissions_soundfile.creation_timestamp)
-                         FROM emissions_soundfile,
-                              emissions_episode
-                        WHERE emissions_soundfile.episode_id = emissions_episode.id
-                          AND emissions_episode.emission_id = emissions_emission.id''',
-                    (),
-                )
-            )
-            .exclude(latest_soundfile_timestamp__isnull=True)
-            .order_by('-latest_soundfile_timestamp')
-            .distinct()
-        )
-
-        if context['shows'].count() > settings.HOME_EMISSIONS_COUNT:
-            context['shows'] = context['shows'][:12]
-            context['shows_display_more'] = True
+        context['shows'] = shows = []
+        emissions_seen = set()
+        for episode in (
+            Episode.objects.filter(emission__archived=False, soundfile__isnull=False)
+            .order_by('-soundfile__creation_timestamp')
+            .select_related('emission')
+        ):
+            if episode.emission_id in emissions_seen:
+                continue
+            emissions_seen.add(episode.emission_id)
+            shows.append(episode)
+            if len(shows) > settings.HOME_EMISSIONS_COUNT:
+                context['shows'] = shows[:12]
+                context['shows_display_more'] = True
+                break
 
         context['collections'] = Emission.objects.filter(archived=False).filter(
             categories__slug='collection'