add feed_list_api

This commit is contained in:
Trent Palmer 2021-05-20 12:53:52 -07:00
parent 8b63db59a7
commit 493189ab01
2 changed files with 14 additions and 0 deletions

View File

@ -20,4 +20,5 @@ urlpatterns = [
path('rss/<str:slug>.xml', AudioRssFeed(), name='rss'), path('rss/<str:slug>.xml', AudioRssFeed(), name='rss'),
path('feed/<str:pk>/<str:slug>', views.feed, name='feed'), path('feed/<str:pk>/<str:slug>', views.feed, name='feed'),
path('episode/<str:pk>/<str:slug>', views.episode, name='episode'), path('episode/<str:pk>/<str:slug>', views.episode, name='episode'),
path('feed-list-api/', views.feed_list_api, name='feed_list_api')
] ]

View File

@ -1,4 +1,5 @@
from django.shortcuts import render, reverse from django.shortcuts import render, reverse
from django.http import JsonResponse
from django.contrib.sites.shortcuts import get_current_site from django.contrib.sites.shortcuts import get_current_site
from .models import Feed, Episode from .models import Feed, Episode
from tp.settings import IMAGES_URL, MP3_URL from tp.settings import IMAGES_URL, MP3_URL
@ -46,3 +47,15 @@ def feeds(request):
request, request,
'audio/feeds.html', 'audio/feeds.html',
{'feeds': feeds, 'IMAGES_URL': IMAGES_URL}) {'feeds': feeds, 'IMAGES_URL': IMAGES_URL})
def feed_list_api(request):
feeds = Feed.objects.all().order_by('created_on')
result = []
for feed in feeds:
result.append({
'title': feed.title,
'read_by': feed.user.username,
'rss_feed': f'{get_current_site(request)}' + reverse('audio:rss', kwargs={'slug': feed.slug})
})
return JsonResponse(result, safe=False)