diff --git a/audio/urls.py b/audio/urls.py index e451b64..ded5fb5 100644 --- a/audio/urls.py +++ b/audio/urls.py @@ -20,4 +20,5 @@ urlpatterns = [ path('rss/.xml', AudioRssFeed(), name='rss'), path('feed//', views.feed, name='feed'), path('episode//', views.episode, name='episode'), + path('feed-list-api/', views.feed_list_api, name='feed_list_api') ] diff --git a/audio/views.py b/audio/views.py index a6e1f33..1af291e 100644 --- a/audio/views.py +++ b/audio/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render, reverse +from django.http import JsonResponse from django.contrib.sites.shortcuts import get_current_site from .models import Feed, Episode from tp.settings import IMAGES_URL, MP3_URL @@ -46,3 +47,15 @@ def feeds(request): request, 'audio/feeds.html', {'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)