From 1d95d59d8d4158c9c7727b54d3a5a6f75f2c9ecb Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 23 Mar 2023 00:16:20 -0400 Subject: [PATCH] Add podcast pages --- vrobbler/apps/podcasts/models.py | 12 ++-- vrobbler/apps/podcasts/urls.py | 14 +++++ vrobbler/apps/podcasts/views.py | 18 ++++++ .../templates/podcasts/podcast_detail.html | 57 +++++++++++++++++++ vrobbler/templates/podcasts/podcast_list.html | 32 +++++++++++ vrobbler/urls.py | 2 + 6 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 vrobbler/apps/podcasts/urls.py create mode 100644 vrobbler/apps/podcasts/views.py create mode 100644 vrobbler/templates/podcasts/podcast_detail.html create mode 100644 vrobbler/templates/podcasts/podcast_list.html diff --git a/vrobbler/apps/podcasts/models.py b/vrobbler/apps/podcasts/models.py index dae01fb..3e28a88 100644 --- a/vrobbler/apps/podcasts/models.py +++ b/vrobbler/apps/podcasts/models.py @@ -7,6 +7,7 @@ from django.apps import apps from django.conf import settings from django.core.files.base import ContentFile from django.db import models +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django_extensions.db.models import TimeStampedModel from podcasts.scrapers import scrape_data_from_google_podcasts @@ -39,11 +40,14 @@ class Podcast(TimeStampedModel): def __str__(self): return f"{self.name}" - def scrobbles(self): + def get_absolute_url(self): + return reverse("podcasts:podcast_detail", kwargs={"slug": self.uuid}) + + def scrobbles(self, user): Scrobble = apps.get_model("scrobbles", "Scrobble") - return Scrobble.objects.filter(podcast_episode__podcast=self).order_by( - "-timestamp" - ) + return Scrobble.objects.filter( + user=user, podcast_episode__podcast=self + ).order_by("-timestamp") def scrape_google_podcasts(self, force=False): podcast_dict = {} diff --git a/vrobbler/apps/podcasts/urls.py b/vrobbler/apps/podcasts/urls.py new file mode 100644 index 0000000..48fe1a5 --- /dev/null +++ b/vrobbler/apps/podcasts/urls.py @@ -0,0 +1,14 @@ +from django.urls import path +from podcasts import views + +app_name = "podcasts" + + +urlpatterns = [ + path("podcasts/", views.PodcastListView.as_view(), name="podcast_list"), + path( + "podcasts//", + views.PodcastDetailView.as_view(), + name="podcast_detail", + ), +] diff --git a/vrobbler/apps/podcasts/views.py b/vrobbler/apps/podcasts/views.py new file mode 100644 index 0000000..79486e8 --- /dev/null +++ b/vrobbler/apps/podcasts/views.py @@ -0,0 +1,18 @@ +from django.views import generic +from podcasts.models import Podcast + + +class PodcastListView(generic.ListView): + model = Podcast + paginate_by = 20 + + +class PodcastDetailView(generic.DetailView): + model = Podcast + slug_field = "uuid" + + def get_context_data(self, **kwargs): + user = self.request.user + context_data = super().get_context_data(**kwargs) + context_data["scrobbles"] = self.object.scrobbles(user) + return context_data diff --git a/vrobbler/templates/podcasts/podcast_detail.html b/vrobbler/templates/podcasts/podcast_detail.html new file mode 100644 index 0000000..182350b --- /dev/null +++ b/vrobbler/templates/podcasts/podcast_detail.html @@ -0,0 +1,57 @@ +{% extends "base_list.html" %} +{% load static %} + +{% block title %}{{object.name}}{% endblock %} + +{% block head_extra %} + +{% endblock %} + +{% block lists %} + +
+
+ +
+
+ {% if object.description %}

{{object.description|safe|linebreaks|truncatewords:160}}

{% endif %} +
+ {% if object.google_podcast_url %} +

+ +

+ {% endif %} + +
+
+
+
+
+
+

Last scrobbles

+
+ + + + + + + + + {% for scrobble in scrobbles.all %} + + + + + {% endfor %} + +
DateEpisode
{{scrobble.timestamp}}{{scrobble.podcast_episode}}
+
+
+
+{% endblock %} diff --git a/vrobbler/templates/podcasts/podcast_list.html b/vrobbler/templates/podcasts/podcast_list.html new file mode 100644 index 0000000..f966f42 --- /dev/null +++ b/vrobbler/templates/podcasts/podcast_list.html @@ -0,0 +1,32 @@ +{% extends "base_list.html" %} + +{% block lists %} +
+
+
+ + + + + + + + + + + {% for obj in object_list %} + {% for episode in obj.episode_set.all %} + + + + + + + {% endfor %} + {% endfor %} + +
SeriesEpisodeScrobblesAll time
{{episode}}{{obj}}{{episode.scrobble_set.count}}
+
+
+
+{% endblock %} diff --git a/vrobbler/urls.py b/vrobbler/urls.py index 7f123f1..deff78e 100644 --- a/vrobbler/urls.py +++ b/vrobbler/urls.py @@ -7,6 +7,7 @@ from vrobbler.apps.books.api.views import AuthorViewSet, BookViewSet from vrobbler.apps.music import urls as music_urls from vrobbler.apps.books import urls as book_urls from vrobbler.apps.sports import urls as sports_urls +from vrobbler.apps.podcasts import urls as podcast_urls from vrobbler.apps.videogames import urls as videogame_urls from vrobbler.apps.music.api.views import ( AlbumViewSet, @@ -63,6 +64,7 @@ urlpatterns = [ path("", include(video_urls, namespace="videos")), path("", include(videogame_urls, namespace="videogames")), path("", include(sports_urls, namespace="sports")), + path("", include(podcast_urls, namespace="podcasts")), path("", include(scrobble_urls, namespace="scrobbles")), path( "", scrobbles_views.RecentScrobbleList.as_view(), name="vrobbler-home"