trentpalmerdotorg/audio/views.py

48 lines
1.5 KiB
Python
Raw Normal View History

2021-03-13 07:49:20 -08:00
from django.shortcuts import render, reverse
from django.contrib.sites.shortcuts import get_current_site
2021-03-13 07:49:20 -08:00
from .models import Feed, Episode
2021-02-24 20:13:54 -08:00
from tp.settings import IMAGES_URL, MP3_URL
def home(request):
2021-02-24 22:28:09 -08:00
episodes = Episode.objects.all().order_by('-pub_date')
2021-02-24 20:13:54 -08:00
return render(
request,
'audio/index.html',
2021-03-04 19:10:34 -08:00
{
'episodes': episodes, 'IMAGES_URL': IMAGES_URL,
'MP3_URL': MP3_URL, 'add_feed_link': True})
2021-02-24 20:13:54 -08:00
def feed(request, pk, slug):
feed = Feed.objects.get(id=pk)
2021-02-24 22:28:09 -08:00
episodes = feed.episode_set.all().order_by('-pub_date')
2021-02-24 20:13:54 -08:00
return render(
request, 'audio/index.html',
{
'episodes': episodes, 'IMAGES_URL': IMAGES_URL, 'view': 'feed',
'MP3_URL': MP3_URL, 'title': feed.title, 'heading': feed.title,
'feed_pk': pk, 'feed_slug': slug,
2021-02-24 20:13:54 -08:00
})
def episode(request, pk, slug):
episode = Episode.objects.get(id=pk)
ogurl = reverse('audio:episode', kwargs={'pk': pk, 'slug': slug})
og_url = f'{get_current_site(request)}{ogurl}'
2021-02-24 20:13:54 -08:00
return render(
request, 'audio/index.html',
{
'episodes': (episode, ), 'IMAGES_URL': IMAGES_URL, 'is_episode': True,
'MP3_URL': MP3_URL, 'title': episode.title, 'heading': episode.title,
'ogtitle': episode.title, 'ogurl': og_url, 'ogmp3': episode.mp3, 'feed': episode.feed
2021-02-24 20:13:54 -08:00
})
def feeds(request):
feeds = Feed.objects.all().order_by('-created_on')
return render(
request,
'audio/feeds.html',
{'feeds': feeds, 'IMAGES_URL': IMAGES_URL})