diff --git a/frontend/templatetags/playlists.py b/frontend/templatetags/playlists.py new file mode 100644 index 0000000..bede324 --- /dev/null +++ b/frontend/templatetags/playlists.py @@ -0,0 +1,20 @@ +from random import choices + +from django import template + +from backend.models import Playlist + + +register = template.Library() + +@register.simple_tag +def other_videos(playlist, video, count=4): + videos = playlist.videos.all().order_by("-published") + + older = list(videos.filter(published__lt=video.published)) + newer = list(videos.filter(published__gt=video.published)) + + newer_out = newer[:count] + older_out = older[-count-len(newer_out):] + + return sorted(older_out + newer_out, key=lambda x: x.published) \ No newline at end of file diff --git a/templates/frontend/playlist.html b/templates/frontend/playlist.html index 2331915..239274b 100644 --- a/templates/frontend/playlist.html +++ b/templates/frontend/playlist.html @@ -40,7 +40,8 @@ {% if page_obj.has_next %}
  • - {{page_obj.next_page_number}}
  • + {{page_obj.next_page_number}} +
  • Last
  • diff --git a/templates/frontend/video.html b/templates/frontend/video.html index 1d9b600..b6afe97 100644 --- a/templates/frontend/video.html +++ b/templates/frontend/video.html @@ -1,40 +1,57 @@ {% extends "frontend/base.html" %} {% load random %} +{% load playlists %} {% block content %} -
    -
    -
    -

    {{object.title}}

    +
    +
    +
    +

    {{object.title}}

    +
    +
    +
    +
    +

    Description

    +

    {{object.description|linebreaksbr}}

    +
    +
    +
    Tags + {% for tag in object.tags %} + {{tag}} + {% endfor %}
    -
    -
    -
    -

    Description

    -

    {{object.description|linebreaksbr}}

    -
    -
    -
    Tags - {% for tag in object.tags %} - {{tag}} - {% endfor %} -
    -
    -
    Date - {{ object.published.date }} -
    -
    -
    -
    -

    Random Videos

    - +
    +
    Date + {{ object.published.date }}
    -
    - {% endblock %} \ No newline at end of file +
    + {% for playlist in object.playlist_set.all %} +
    +

    Other videos in {{playlist.title}}

    + +
    + {% endfor %} +
    +

    Random Videos

    + +
    +
    +
    +{% endblock %} \ No newline at end of file