Add podcast pages

This commit is contained in:
2023-03-23 00:16:20 -04:00
parent 70118e2e62
commit 1d95d59d8d
6 changed files with 131 additions and 4 deletions

View File

@ -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 = {}

View File

@ -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/<slug:slug>/",
views.PodcastDetailView.as_view(),
name="podcast_detail",
),
]

View File

@ -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