2021-03-13 07:49:20 -08:00
|
|
|
from django.shortcuts import render, reverse
|
2021-05-20 12:53:52 -07:00
|
|
|
from django.http import JsonResponse
|
2021-02-25 00:49:13 -08:00
|
|
|
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',
|
|
|
|
{
|
2021-03-02 19:37:48 -08:00
|
|
|
'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)
|
2021-02-25 00:49:13 -08:00
|
|
|
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',
|
|
|
|
{
|
2021-12-03 00:49:05 -08:00
|
|
|
'episodes': (episode, ), 'IMAGES_URL': IMAGES_URL,
|
|
|
|
'is_episode': True, 'MP3_URL': MP3_URL,
|
|
|
|
'title': episode.title, 'heading': episode.title,
|
2021-03-25 14:57:41 -07:00
|
|
|
'ogtitle': episode.title, 'ogurl': og_url, 'ogmp3': episode.mp3,
|
|
|
|
'feed': episode.feed, 'twitter_image': episode.image,
|
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})
|
2021-05-20 12:53:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
def feed_list_api(request):
|
|
|
|
feeds = Feed.objects.all().order_by('created_on')
|
|
|
|
result = []
|
|
|
|
for feed in feeds:
|
2021-12-03 00:49:05 -08:00
|
|
|
x = reverse('audio:rss', kwargs={'slug': feed.slug})
|
2021-05-20 12:53:52 -07:00
|
|
|
result.append({
|
|
|
|
'title': feed.title,
|
|
|
|
'read_by': feed.user.username,
|
2021-12-03 00:49:05 -08:00
|
|
|
'rss_feed': f'{get_current_site(request)}' + x
|
2021-05-20 12:53:52 -07:00
|
|
|
})
|
|
|
|
return JsonResponse(result, safe=False)
|