diff --git a/conservancy/podjango/urls.py b/conservancy/podjango/urls.py index b113e60a4383f136646ae119e00a86006a4ba9a2..6f1852bdc2c3f071b4386304e82f0e16d649ee65 100644 --- a/conservancy/podjango/urls.py +++ b/conservancy/podjango/urls.py @@ -20,39 +20,54 @@ import datetime from django.conf import settings +from django.shortcuts import get_object_or_404 from django.urls import path -from django.views.generic.dates import ( - DateDetailView, - DayArchiveView, - MonthArchiveView, - YearArchiveView, -) +from django.views.generic.dates import DateDetailView from . import frontpage from .feeds import Mp3CastFeed, OggCastFeed, view -from .models import Cast, CastTag -from .views import custom_index, query +from .models import Cast, CastTag, Podcast +from . import views app_name = 'podjango' extra_context = {} info_dict = { - 'queryset': Cast.objects.all(), 'date_field': 'pub_date', 'extra_context': extra_context, - 'template_name': 'podjango/cast/cast_detail.html', } +class PodcastDateDetailView(DateDetailView): + date_field = 'pub_date' + model = Cast + + def get(self, request, podcast_slug, *args, **kwargs): + self.podcast = get_object_or_404(Podcast, slug=podcast_slug) + return super().get(request, *args, **kwargs) + + def get_queryset(self): + return super().get_queryset().filter(podcast=self.podcast) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['podcast'] = self.podcast + return context + + urlpatterns = [ - path('', frontpage.view, name='cast-home'), - path('////', DateDetailView.as_view(**info_dict), name='detail'), - path('///', DayArchiveView.as_view(**info_dict), name='day-archive'), - path('//', MonthArchiveView.as_view(**info_dict), name='month-archive'), - path('/', YearArchiveView.as_view(**info_dict), name='year-archive'), - path('all/', custom_index, dict(info_dict, paginate_by=20), name='cast'), - path('feeds/ogg/', OggCastFeed(), name='feed-ogg'), - path('feeds/mp3/', Mp3CastFeed(), name='feed-mp3'), - path('feeds/', view, name='feeds'), + path('', views.podcasts, name='podcasts'), + path('/', frontpage.view, name='cast-home'), + path( + '/////', + PodcastDateDetailView.as_view( + template_name='podjango/cast_detail.html', + ), + name='detail' + ), + path('/all/', views.custom_index, info_dict, name='cast'), + path('/feeds/ogg/', OggCastFeed(), name='feed-ogg'), + path('/feeds/mp3/', Mp3CastFeed(), name='feed-mp3'), + path('/feeds/', view, name='feeds'), ] if settings.DEBUG: