Browse Source

[views] Fix showing only a users scrobbles

Colin Powell 3 tuần trước cách đây
mục cha
commit
685de842ea

+ 10 - 9
vrobbler/apps/scrobbles/views.py

@@ -64,15 +64,16 @@ class ScrobbleableListView(ListView):
 
     def get_queryset(self):
         queryset = super().get_queryset()
+        user_filter = Q()
         if not self.request.user.is_anonymous:
-            queryset = queryset.annotate(
+            user_filter = Q(scrobble__user=self.request.user)
+        queryset = (
+            queryset.annotate(
                 scrobble_count=Count("scrobble"),
-                filter=Q(scrobble__user=self.request.user),
-            ).order_by("-scrobble_count")
-        else:
-            queryset = queryset.annotate(
-                scrobble_count=Count("scrobble")
-            ).order_by("-scrobble_count")
+            )
+            .filter(user_filter, scrobble_count__gt=0)
+            .order_by("-scrobble_count")
+        )
         return queryset
 
 
@@ -86,7 +87,7 @@ class ScrobbleableDetailView(DetailView):
         if not self.request.user.is_anonymous:
             context_data["scrobbles"] = self.object.scrobble_set.filter(
                 user=self.request.user
-            )
+            ).order_by("-timestamp")
         return context_data
 
 
@@ -201,7 +202,7 @@ class RecentScrobbleList(ListView):
                 processed_finished__isnull=True,
                 user=self.request.user,
             )
-            data["counts"] = [] #scrobble_counts(user)
+            data["counts"] = []  # scrobble_counts(user)
         else:
             data["weekly_data"] = week_of_scrobbles()
             data["counts"] = scrobble_counts()

+ 2 - 2
vrobbler/templates/beers/beer_detail.html

@@ -39,7 +39,7 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
+    <p>{{scrobbles.count}} scrobbles</p>
     <p>
         <a href="{{object.start_url}}">Drink again</a>
     </p>
@@ -55,7 +55,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                     </tr>

+ 2 - 2
vrobbler/templates/boardgames/boardgame_detail.html

@@ -42,7 +42,7 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
+    <p>{{scrobbles.count}} scrobbles</p>
     <p>
         <a href="{{object.start_url}}">Play again</a>
     </p>
@@ -60,7 +60,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                         <td>{{scrobble.media_obj.publisher}}</td>

+ 4 - 4
vrobbler/templates/books/book_detail.html

@@ -26,10 +26,10 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
-    <p>Read {{object.scrobble_set.last.book_pages_read}} pages{% if object.scrobble_set.last.long_play_complete %} and completed{% else %}{% endif %}</p>
+    <p>{{scrobbles.count}} scrobbles</p>
+    <p>Read {{scrobbles.last.book_pages_read}} pages{% if scrobbles.last.long_play_complete %} and completed{% else %}{% endif %}</p>
     <p>
-        {% if object.scrobble_set.last.long_play_complete == True %}
+        {% if scrobbles.last.long_play_complete == True %}
         <a href="">Read again</a>
         {% else %}
         <a href="">Resume reading</a>
@@ -50,7 +50,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                         <td>{% if scrobble.long_play_complete == True %}Yes{% endif %}</td>

+ 2 - 2
vrobbler/templates/locations/geolocation_detail.html

@@ -48,7 +48,7 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
+    <p>{{scrobbles.count}} scrobbles</p>
 <div class="row">
     <div class="col-md">
         <h3>Last scrobbles</h3>
@@ -60,7 +60,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local_timestamp|naturaltime}}</td>
                     </tr>

+ 1 - 1
vrobbler/templates/moods/mood_detail.html

@@ -26,7 +26,7 @@
                 </tr>
             </thead>
             <tbody>
-                {% for scrobble in object.scrobble_set.all %}
+                {% for scrobble in scrobbles.all %}
                 <tr>
                     <td>{{scrobble.local_timestamp}}</td>
                 </tr>

+ 2 - 2
vrobbler/templates/music/track_detail.html

@@ -9,7 +9,7 @@
     {% endif %}
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
+    <p>{{scrobbles.count}} scrobbles</p>
     {% if charts %}
     <p>{% for chart in charts %}<em><a href="{{chart.link}}">{{chart}}</a></em>{% if forloop.last %}{% else %} | {% endif %}{% endfor %}</p>
     {% endif %}
@@ -26,7 +26,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all %}
+                    {% for scrobble in scrobbles.all %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                         <td><a href="{{scrobble.track.get_absolute_url}}">{{scrobble.track.title}}</a></td>

+ 1 - 1
vrobbler/templates/sports/sportevent_detail.html

@@ -18,7 +18,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all %}
+                    {% for scrobble in scrobbles.all %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                         <td>{{scrobble.media_obj.round.season.name}}</td>

+ 2 - 2
vrobbler/templates/tasks/task_detail.html

@@ -39,7 +39,7 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
+    <p>{{scrobbles.count}} scrobbles</p>
     <p>
         <a href="{{object.start_url}}">Play again</a>
     </p>
@@ -57,7 +57,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                         <td><a href="{{scrobble.get_media_source_url}}">{{scrobble.logdata.description}}</a></td>

+ 5 - 5
vrobbler/templates/videogames/videogame_detail.html

@@ -59,12 +59,12 @@
     </div>
 </div>
 <div class="row">
-    <p>{{object.scrobble_set.count}} scrobbles</p>
-    {% if object.scrobble_set.last.long_play_seconds %}
-    <p>{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}</p>
+    <p>{{scrobbles.count}} scrobbles</p>
+    {% if scrobbles.last.long_play_seconds %}
+    <p>{{scrobbles.last.long_play_seconds|natural_duration}}{% if scrobbles.last.long_play_complete %} and completed{% else %} spent playing{% endif %}</p>
     {% endif  %}
     <p>
-        {% if object.scrobble_set.last.long_play_complete == True %}
+        {% if scrobbles.last.long_play_complete == True %}
         <a href="">Play again</a>
         {% else %}
         <a href="{{object.start_url}}">Resume playing</a>
@@ -86,7 +86,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
+                    {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.local-timestamp}}</td>
                         <td>{% if scrobble.long_play_complete == True %}Yes{% else %}Not yet{% endif %}</td>

+ 1 - 1
vrobbler/templates/videos/video_detail.html

@@ -85,7 +85,7 @@ dd {
                     </tr>
                 </thead>
                 <tbody>
-                    {% for scrobble in object.scrobble_set.all %}
+                    {% for scrobble in scrobbles.all %}
                     <tr>
                         <td>{{scrobble.local_timestamp}}</td>
                     </tr>

+ 1 - 1
vrobbler/templates/webpages/webpage_detail.html

@@ -51,7 +51,7 @@
                 </tr>
             </thead>
             <tbody>
-                {% for scrobble in object.scrobble_set.all %}
+                {% for scrobble in scrobbles.all %}
                 <tr>
                     <td>{{scrobble.local_timestamp}}</td>
                 </tr>