You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
3.0 KiB
59 lines
3.0 KiB
from functools import wraps
|
|
from django.urls import path, re_path , include
|
|
from django.views.decorators.cache import cache_page
|
|
from django.views.decorators.vary import vary_on_headers
|
|
from rest_framework.routers import SimpleRouter
|
|
from .views import *
|
|
from .views_admin import *
|
|
|
|
# Helper function to cache public views
|
|
def cached_view(view_func):
|
|
return cache_page(60 * 60 * 2, key_prefix='podcast_api')(vary_on_headers('Accept-Language')(view_func))
|
|
|
|
# Helper to conditionally cache list views (bypasses cache when is_bookmark=true or in_playlist=true)
|
|
def conditional_cached_view(timeout, key_prefix):
|
|
def decorator(view_func):
|
|
cached_func = cache_page(timeout, key_prefix=key_prefix)(vary_on_headers('Accept-Language')(view_func))
|
|
@wraps(view_func)
|
|
def _wrapped_view(request, *args, **kwargs):
|
|
is_bookmark = (request.GET.get('is_bookmark') or request.GET.get('is_bookmarked') or '').lower()
|
|
in_playlist = request.GET.get('in_playlist', '').lower()
|
|
if is_bookmark in ('true', '1') or in_playlist in ('true', '1'):
|
|
return view_func(request, *args, **kwargs)
|
|
return cached_func(request, *args, **kwargs)
|
|
return _wrapped_view
|
|
return decorator
|
|
|
|
admin_router = SimpleRouter()
|
|
admin_router.register(r'podcasts', AdminPodcastViewSet, basename='admin-podcast')
|
|
admin_router.register(r'playlists', AdminPodcastPlaylistViewSet, basename='admin-podcast-playlist')
|
|
admin_router.register(r'categories', AdminPodcastCategoryViewSet, basename='admin-podcast-category')
|
|
admin_router.register(r'collections', AdminPodcastCollectionViewSet, basename='admin-podcast-collection')
|
|
|
|
# Hide admin viewsets from swagger
|
|
for prefix, viewset, basename in admin_router.registry:
|
|
viewset.swagger_schema = None
|
|
|
|
dovodi_router = SimpleRouter()
|
|
dovodi_router.register(r'categories', DovodiPodcastCategoryViewSet, basename='dovodi-podcast-category')
|
|
dovodi_router.register(r'collections', DovodiPodcastCollectionViewSet, basename='dovodi-podcast-collection')
|
|
dovodi_router.register(r'items', DovodiPodcastItemViewSet, basename='dovodi-podcast-item')
|
|
|
|
app_name = 'podcast'
|
|
|
|
urlpatterns = [
|
|
path('admin/', include(admin_router.urls)),
|
|
path('dovodi/', include(dovodi_router.urls)),
|
|
path('categories/', cached_view(PodcastCategoryListAPIView.as_view()), name='category-list'),
|
|
path('pinned-collections/', cached_view(PinnedPodcastCollectionListView.as_view()), name='pinned-collection-list'),
|
|
path('collections/', cached_view(MiddlePodcastCollectionListView.as_view()), name='collection-list'),
|
|
|
|
path('list/', conditional_cached_view(60 * 30, 'podcast_list')(PodcastListAPIView.as_view()), name='podcast-list'),
|
|
re_path(r'detail/(?P<slug>[\w-]+)/$', PodcastDetailAPIView.as_view(), name='podcast-detail'),
|
|
|
|
# User playlist endpoints
|
|
path('user-playlist/', UserPlaylistCreateAPIView.as_view(), name='user-playlist-create'),
|
|
path('user-playlist/list/', UserPlaylistListAPIView.as_view(), name='user-playlist-list'),
|
|
|
|
|
|
]
|