From 15ff2e4efd509a422d582645eef95f1682673ae6 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 6 Jan 2023 11:44:31 -0500 Subject: [PATCH] [#1] Add now playing section to homepage --- vrobbler/apps/scrobbles/views.py | 9 +++++++++ vrobbler/templates/scrobbles/scrobble_list.html | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 300c2de..e05e023 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -15,6 +15,7 @@ from scrobbles.models import Scrobble from scrobbles.serializers import ScrobbleSerializer from videos.models import Series, Video from vrobbler.settings import DELETE_STALE_SCROBBLES +from django.utils import timezone logger = logging.getLogger(__name__) @@ -34,6 +35,14 @@ TRUTHY_VALUES = [ class RecentScrobbleList(ListView): model = Scrobble + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + last_five_minutes = timezone.now() - timedelta(minutes=5) + data['now_playing_list'] = Scrobble.objects.filter( + in_progress=True, modified__lte=last_five_minutes + ) + return data + def get_queryset(self): return Scrobble.objects.filter(in_progress=False).order_by( '-timestamp' diff --git a/vrobbler/templates/scrobbles/scrobble_list.html b/vrobbler/templates/scrobbles/scrobble_list.html index ce67fac..86c2e42 100644 --- a/vrobbler/templates/scrobbles/scrobble_list.html +++ b/vrobbler/templates/scrobbles/scrobble_list.html @@ -1,8 +1,17 @@ {% extends "base.html" %} -{% block title %}Last watched{% endblock %} +{% block title %}{% endblock %} {% block content %} + {% if now_playing_list %} +

Now playing

+ + {% endif %} +

Last scrobbles