[podcasts] Add aggregation to templates
All checks were successful
build & deploy / test (push) Successful in 1m40s
build & deploy / deploy (push) Successful in 20s

This commit is contained in:
2026-03-18 11:07:45 -04:00
parent 28db747b59
commit 8e8d25aa1d
3 changed files with 13 additions and 32 deletions

View File

@ -1,15 +1,15 @@
import datetime import datetime
from django.utils import timezone from django.utils import timezone
from django.views import generic from django.views import generic
from podcasts.models import Podcast from podcasts.models import Podcast, PodcastEpisode
from scrobbles.models import Scrobble from scrobbles.models import Scrobble
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
class PodcastListView(generic.ListView): class PodcastListView(ScrobbleableListView):
model = Podcast model = PodcastEpisode
paginate_by = 20 template_name = "podcasts/podcast_list.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs) context_data = super().get_context_data(**kwargs)
@ -36,10 +36,7 @@ class PodcastListView(generic.ListView):
if podcast: if podcast:
podcasts_this_week[podcast.id] = { podcasts_this_week[podcast.id] = {
"podcast": podcast, "podcast": podcast,
"count": podcasts_this_week.get(podcast.id, {}).get( "count": podcasts_this_week.get(podcast.id, {}).get("count", 0) + 1,
"count", 0
)
+ 1,
} }
podcasts_this_month = {} podcasts_this_month = {}
@ -48,9 +45,7 @@ class PodcastListView(generic.ListView):
if podcast: if podcast:
podcasts_this_month[podcast.id] = { podcasts_this_month[podcast.id] = {
"podcast": podcast, "podcast": podcast,
"count": podcasts_this_month.get(podcast.id, {}).get( "count": podcasts_this_month.get(podcast.id, {}).get("count", 0)
"count", 0
)
+ 1, + 1,
} }

View File

@ -6,6 +6,9 @@
<tr> <tr>
<th scope="col">Latest</th> <th scope="col">Latest</th>
<th scope="col">Title</th> <th scope="col">Title</th>
{% if podcast_list or object_list.0.podcast %}
<th scope="col">Podcast</th>
{% endif %}
<th scope="col">Scrobbles</th> <th scope="col">Scrobbles</th>
<th scope="col">Start</th> <th scope="col">Start</th>
</tr> </tr>
@ -16,6 +19,9 @@
<tr> <tr>
<td><a href="{{obj.scrobble_set.last.get_absolute_url}}">{{obj.scrobble_set.last.local_timestamp}} <td><a href="{{obj.scrobble_set.last.get_absolute_url}}">{{obj.scrobble_set.last.local_timestamp}}
<td><a href="{{obj.get_absolute_url}}">{{obj}}</a></td> <td><a href="{{obj.get_absolute_url}}">{{obj}}</a></td>
{% if podcast_list or obj.podcast %}
<td>{% if obj.podcast %}<a href="{{obj.podcast.get_absolute_url}}">{{obj.podcast}}</a>{% endif %}</td>
{% endif %}
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<td>{{obj.scrobble_count}}</td> <td>{{obj.scrobble_count}}</td>
<td><a type="button" class="btn btn-sm btn-primary" href="{{obj.start_url}}">Scrobble</a></td> <td><a type="button" class="btn btn-sm btn-primary" href="{{obj.start_url}}">Scrobble</a></td>

View File

@ -52,27 +52,7 @@
<div class="row"> <div class="row">
<div class="col-md"> <div class="col-md">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sm"> {% include "_scrobblable_list.html" %}
<thead>
<tr>
<th scope="col">Episode</th>
<th scope="col">Podcast</th>
<th scope="col">Scrobbles</th>
</tr>
</thead>
<tbody>
{% for obj in object_list.all %}
{{obj.episodes}}
{% for episode in obj.podcastepisode_set.all %}
<tr>
<td><a href="{{episode.get_absolute_url}}">{{episode}}</a></td>
<td><a href="{{obj.get_absolute_url}}">{{obj}}</a></td>
<td>{{episode.scrobble_set.count}}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>