diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 1b005d1..83ed8b6 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/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() diff --git a/vrobbler/templates/beers/beer_detail.html b/vrobbler/templates/beers/beer_detail.html index 7bc1b39..7bde048 100644 --- a/vrobbler/templates/beers/beer_detail.html +++ b/vrobbler/templates/beers/beer_detail.html @@ -39,7 +39,7 @@
-

{{object.scrobble_set.count}} scrobbles

+

{{scrobbles.count}} scrobbles

Drink again

@@ -55,7 +55,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local_timestamp}} diff --git a/vrobbler/templates/boardgames/boardgame_detail.html b/vrobbler/templates/boardgames/boardgame_detail.html index b277ce7..27fe741 100644 --- a/vrobbler/templates/boardgames/boardgame_detail.html +++ b/vrobbler/templates/boardgames/boardgame_detail.html @@ -42,7 +42,7 @@
-

{{object.scrobble_set.count}} scrobbles

+

{{scrobbles.count}} scrobbles

Play again

@@ -60,7 +60,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local_timestamp}} {{scrobble.media_obj.publisher}} diff --git a/vrobbler/templates/books/book_detail.html b/vrobbler/templates/books/book_detail.html index 30efa93..0fbc114 100644 --- a/vrobbler/templates/books/book_detail.html +++ b/vrobbler/templates/books/book_detail.html @@ -26,10 +26,10 @@
-

{{object.scrobble_set.count}} scrobbles

-

Read {{object.scrobble_set.last.book_pages_read}} pages{% if object.scrobble_set.last.long_play_complete %} and completed{% else %}{% endif %}

+

{{scrobbles.count}} scrobbles

+

Read {{scrobbles.last.book_pages_read}} pages{% if scrobbles.last.long_play_complete %} and completed{% else %}{% endif %}

- {% if object.scrobble_set.last.long_play_complete == True %} + {% if scrobbles.last.long_play_complete == True %} Read again {% else %} Resume reading @@ -50,7 +50,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local_timestamp}} {% if scrobble.long_play_complete == True %}Yes{% endif %} diff --git a/vrobbler/templates/locations/geolocation_detail.html b/vrobbler/templates/locations/geolocation_detail.html index 2d6cfb8..5ae079d 100644 --- a/vrobbler/templates/locations/geolocation_detail.html +++ b/vrobbler/templates/locations/geolocation_detail.html @@ -48,7 +48,7 @@

-

{{object.scrobble_set.count}} scrobbles

+

{{scrobbles.count}} scrobbles

Last scrobbles

@@ -60,7 +60,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local_timestamp|naturaltime}} diff --git a/vrobbler/templates/moods/mood_detail.html b/vrobbler/templates/moods/mood_detail.html index 764bad9..59162c4 100644 --- a/vrobbler/templates/moods/mood_detail.html +++ b/vrobbler/templates/moods/mood_detail.html @@ -26,7 +26,7 @@ - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %} {{scrobble.local_timestamp}} diff --git a/vrobbler/templates/music/track_detail.html b/vrobbler/templates/music/track_detail.html index 6fdacb9..65a0508 100644 --- a/vrobbler/templates/music/track_detail.html +++ b/vrobbler/templates/music/track_detail.html @@ -9,7 +9,7 @@ {% endif %}
-

{{object.scrobble_set.count}} scrobbles

+

{{scrobbles.count}} scrobbles

{% if charts %}

{% for chart in charts %}{{chart}}{% if forloop.last %}{% else %} | {% endif %}{% endfor %}

{% endif %} @@ -26,7 +26,7 @@ - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %} {{scrobble.local_timestamp}} {{scrobble.track.title}} diff --git a/vrobbler/templates/sports/sportevent_detail.html b/vrobbler/templates/sports/sportevent_detail.html index b2c74b5..25fc06b 100644 --- a/vrobbler/templates/sports/sportevent_detail.html +++ b/vrobbler/templates/sports/sportevent_detail.html @@ -18,7 +18,7 @@ - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %} {{scrobble.local_timestamp}} {{scrobble.media_obj.round.season.name}} diff --git a/vrobbler/templates/tasks/task_detail.html b/vrobbler/templates/tasks/task_detail.html index dde5c21..66e35ac 100644 --- a/vrobbler/templates/tasks/task_detail.html +++ b/vrobbler/templates/tasks/task_detail.html @@ -39,7 +39,7 @@
-

{{object.scrobble_set.count}} scrobbles

+

{{scrobbles.count}} scrobbles

Play again

@@ -57,7 +57,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local_timestamp}} {{scrobble.logdata.description}} diff --git a/vrobbler/templates/videogames/videogame_detail.html b/vrobbler/templates/videogames/videogame_detail.html index 7b09519..cc48778 100644 --- a/vrobbler/templates/videogames/videogame_detail.html +++ b/vrobbler/templates/videogames/videogame_detail.html @@ -59,12 +59,12 @@
-

{{object.scrobble_set.count}} scrobbles

- {% if object.scrobble_set.last.long_play_seconds %} -

{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}

+

{{scrobbles.count}} scrobbles

+ {% if scrobbles.last.long_play_seconds %} +

{{scrobbles.last.long_play_seconds|natural_duration}}{% if scrobbles.last.long_play_complete %} and completed{% else %} spent playing{% endif %}

{% endif %}

- {% if object.scrobble_set.last.long_play_complete == True %} + {% if scrobbles.last.long_play_complete == True %} Play again {% else %} Resume playing @@ -86,7 +86,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {{scrobble.local-timestamp}} {% if scrobble.long_play_complete == True %}Yes{% else %}Not yet{% endif %} diff --git a/vrobbler/templates/videos/video_detail.html b/vrobbler/templates/videos/video_detail.html index d49276f..b887162 100644 --- a/vrobbler/templates/videos/video_detail.html +++ b/vrobbler/templates/videos/video_detail.html @@ -85,7 +85,7 @@ dd { - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %} {{scrobble.local_timestamp}} diff --git a/vrobbler/templates/webpages/webpage_detail.html b/vrobbler/templates/webpages/webpage_detail.html index f77fe89..3b12ab1 100644 --- a/vrobbler/templates/webpages/webpage_detail.html +++ b/vrobbler/templates/webpages/webpage_detail.html @@ -51,7 +51,7 @@ - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %} {{scrobble.local_timestamp}}