瀏覽代碼

Split long plays up a bit

Colin Powell 2 年之前
父節點
當前提交
5fcc314fd0
共有 2 個文件被更改,包括 21 次插入15 次删除
  1. 16 12
      vrobbler/apps/scrobbles/utils.py
  2. 5 3
      vrobbler/templates/scrobbles/long_plays_in_progress.html

+ 16 - 12
vrobbler/apps/scrobbles/utils.py

@@ -6,6 +6,7 @@ from django.apps import apps
 from django.conf import settings
 from django.contrib.auth import get_user_model
 from django.db import models
+from vrobbler.apps.profiles.utils import now_user_timezone
 
 from vrobbler.apps.scrobbles.constants import LONG_PLAY_MEDIA
 
@@ -121,21 +122,24 @@ def get_scrobbles_for_media(media_obj, user: User) -> models.QuerySet:
     return Scrobble.objects.filter(media_query, user=user)
 
 
-def get_long_plays_in_progress(user: User) -> list:
+def get_long_plays_in_progress(user: User) -> dict:
     """Find all books where the last scrobble is not marked complete"""
-    media_list = []
+    media_dict = {
+        "active": [],
+        "inactive": [],
+    }
+    now = now_user_timezone(user.profile)
     for app, model in LONG_PLAY_MEDIA.items():
         media_obj = apps.get_model(app_label=app, model_name=model)
         for media in media_obj.objects.all().order_by("-scrobble__timestamp"):
-            if (
-                media.scrobble_set.all()
-                and media.scrobble_set.filter(user=user)
-                .last()
-                .long_play_complete
-                == False
-            ):
-                media_list.append(media)
-    return media_list
+            last_scrobble = media.scrobble_set.filter(user=user).last()
+            if last_scrobble and last_scrobble.long_play_complete == False:
+                days_past = (now - last_scrobble.timestamp).days
+                if days_past > 7:
+                    media_dict["inactive"].append(media)
+                else:
+                    media_dict["active"].append(media)
+    return media_dict
 
 
 def get_long_plays_completed(user: User) -> list:
@@ -143,7 +147,7 @@ def get_long_plays_completed(user: User) -> list:
     media_list = []
     for app, model in LONG_PLAY_MEDIA.items():
         media_obj = apps.get_model(app_label=app, model_name=model)
-        for media in media_obj.objects.all().order_by("-scrobble__timestamp"):
+        for media in media_obj.objects.all():
             if (
                 media.scrobble_set.all()
                 and media.scrobble_set.filter(user=user)

+ 5 - 3
vrobbler/templates/scrobbles/long_plays_in_progress.html

@@ -14,10 +14,11 @@
 {% block lists %}
 <div class="row">
 
-    <h2>In progress</h2>
     {% if view == 'grid' %}
-    <div>
-        {% for media in in_progress %}
+    {% for period, medias in in_progress.items %}
+    <h2>{% if period == "active" %}Recently played{% else %}More than a week ago{% endif %}</h2>
+    <div class="col-md">
+        {% for media in medias %}
         <dl>
             <dt><a href="{{media.get_absolute_url}}">{{media.title}}</a></dt>
             {% if media.hltb_cover %}
@@ -32,6 +33,7 @@
         </dl>
         {% endfor %}
     </div>
+    {% endfor %}
     {% else %}
     <div class="col-md">
         <div class="table-responsive">