소스 검색

[#1] Add now playing section to homepage

Colin Powell 2 년 전
부모
커밋
15ff2e4efd
2개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 0
      vrobbler/apps/scrobbles/views.py
  2. 10 1
      vrobbler/templates/scrobbles/scrobble_list.html

+ 9 - 0
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'

+ 10 - 1
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 %}
+    <h2>Now playing</h2>
+    <ul>
+        {% for scrobble in now_playing_list %}
+        <li>{{scrobble.timestamp|date:"D, M j Y"}}: <a href="https://www.imdb.com/title/{{scrobble.video.imdb_id}}">{{scrobble.video}}</a></li>
+        {% endfor %}
+    </ul>
+    {% endif %}
+    <h2>Last scrobbles</h2>
     <ul>
         {% for scrobble in object_list %}
         <li>{{scrobble.timestamp|date:"D, M j Y"}}: <a href="https://www.imdb.com/title/{{scrobble.video.imdb_id}}">{{scrobble.video}}</a></li>