From 621d8a0c4ffcf60cf367e0d6d17f933ddc2d5071 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 8 May 2022 15:37:52 +0200 Subject: [PATCH] Fix next/previous in playlist tag --- frontend/templatetags/playlists.py | 9 ++++++--- templates/frontend/video.html | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/templatetags/playlists.py b/frontend/templatetags/playlists.py index 995b752..aeb610a 100644 --- a/frontend/templatetags/playlists.py +++ b/frontend/templatetags/playlists.py @@ -9,7 +9,7 @@ register = template.Library() @register.simple_tag -def other_videos(playlist, video, count=4): +def other_videos(playlist, video): videos = playlist.videos.all().order_by("-published") older = sorted( @@ -17,8 +17,11 @@ def other_videos(playlist, video, count=4): newer = sorted( list(videos.filter(published__gt=video.published)), key=lambda x: x.published) - newer_out = newer[:count-1] - older_out = older[-count+len(newer_out):] + len_newer = min(3 if older else 4, len(newer)) + len_older = min(4 - len_newer, len(older)) + + newer_out = newer[:len_newer] + older_out = older[-len_older:] return sorted(older_out + newer_out, key=lambda x: x.published) diff --git a/templates/frontend/video.html b/templates/frontend/video.html index f7cfdf0..4e48537 100644 --- a/templates/frontend/video.html +++ b/templates/frontend/video.html @@ -47,7 +47,7 @@ {% other_videos playlist object as suggestions %} {% for video in suggestions %}
-
{% endfor %}