|
|
|
@ -216,6 +216,108 @@ class VideoPlaylistListAPIView(generics.ListAPIView): |
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
class VideoListAPIView(generics.ListAPIView): |
|
|
|
""" |
|
|
|
API view to list all video playlists, with optional filtering by category or collection |
|
|
|
""" |
|
|
|
serializer_class = VideoListSerializer |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
authentication_classes = [TokenAuthentication] |
|
|
|
pagination_class = StandardResultsSetPagination |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Get a list of videos with optional filtering", |
|
|
|
tags=["Dobodbi - Video"], |
|
|
|
manual_parameters=[ |
|
|
|
openapi.Parameter( |
|
|
|
name='category', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Filter playlists by category slug', |
|
|
|
type=openapi.TYPE_STRING, |
|
|
|
required=False |
|
|
|
), |
|
|
|
openapi.Parameter( |
|
|
|
name='collection', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Filter playlists by collection slug', |
|
|
|
type=openapi.TYPE_STRING, |
|
|
|
required=False |
|
|
|
), |
|
|
|
openapi.Parameter( |
|
|
|
name='is_bookmark', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Filter playlists that are bookmarked by the user (true/false)', |
|
|
|
type=openapi.TYPE_BOOLEAN, |
|
|
|
required=False |
|
|
|
), |
|
|
|
openapi.Parameter( |
|
|
|
name='search', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Search playlists by title', |
|
|
|
type=openapi.TYPE_STRING, |
|
|
|
required=False |
|
|
|
) |
|
|
|
], |
|
|
|
responses={ |
|
|
|
200: openapi.Response( |
|
|
|
description="List of video playlists", |
|
|
|
schema=VideoPlaylistListSerializer(many=True) |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
queryset = Video.objects.filter(status=True).order_by('-created_at') |
|
|
|
|
|
|
|
# Search by title if search parameter is provided |
|
|
|
search_query = self.request.query_params.get('search', None) |
|
|
|
if search_query: |
|
|
|
queryset = queryset.filter(title__icontains=search_query) |
|
|
|
|
|
|
|
# Filter by category if provided |
|
|
|
category_slug = self.request.query_params.get('category', None) |
|
|
|
if category_slug: |
|
|
|
queryset = queryset.filter(categories__slug=category_slug) |
|
|
|
|
|
|
|
# Filter by collection if provided |
|
|
|
collection_slug = self.request.query_params.get('collection', None) |
|
|
|
if collection_slug: |
|
|
|
queryset = queryset.filter(collections__slug=collection_slug) |
|
|
|
|
|
|
|
is_bookmark = self.request.query_params.get('is_bookmark', '').lower() |
|
|
|
if is_bookmark == 'true': |
|
|
|
# Import Bookmark model here to avoid circular imports |
|
|
|
from apps.bookmark.models import Bookmark |
|
|
|
|
|
|
|
# Get all bookmarked playlist IDs for the current user |
|
|
|
bookmarked_ids = Bookmark.objects.filter( |
|
|
|
user=self.request.user, |
|
|
|
service=Bookmark.ServiceChoices.VIDEO_PLAYLIST, |
|
|
|
status=True |
|
|
|
).values_list('content_id', flat=True) |
|
|
|
|
|
|
|
# Filter playlists by these IDs |
|
|
|
queryset = queryset.filter(id__in=bookmarked_ids) |
|
|
|
sort = self.request.query_params.get('sort', '-created_at') |
|
|
|
allowed_sorts = [ |
|
|
|
'created_at', '-created_at', 'view_count', '-view_count', |
|
|
|
'title', '-title', |
|
|
|
'total_time', '-total_time','-created_at','created_at' |
|
|
|
] |
|
|
|
|
|
|
|
if sort in allowed_sorts: |
|
|
|
# Handle multiple sort fields (e.g., '-pin,-created_at') |
|
|
|
if ',' in sort: |
|
|
|
queryset = queryset.order_by(*sort.split(',')) |
|
|
|
else: |
|
|
|
queryset = queryset.order_by(sort) |
|
|
|
else: |
|
|
|
queryset = queryset.order_by('-created_at') |
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
class VideoPlaylistDetailAPIView(generics.RetrieveAPIView): |
|
|
|
serializer_class = VideoPlaylistDetailSerializer |
|
|
|
@ -266,11 +368,11 @@ class VideoDetailAPIView(generics.RetrieveAPIView): |
|
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
return Video.objects.filter(status=True) |
|
|
|
return Video.objects.filter(slug = self.kwargs.get('slug')) |
|
|
|
|
|
|
|
def retrieve(self, request, *args, **kwargs): |
|
|
|
instance = self.get_object() |
|
|
|
instance.increment_view_count() |
|
|
|
serializer = self.get_serializer(instance) |
|
|
|
return Response(serializer.data) |
|
|
|
# def retrieve(self, request, *args, **kwargs): |
|
|
|
# instance = self.get_object() |
|
|
|
# instance.increment_view_count() |
|
|
|
# serializer = self.get_serializer(instance) |
|
|
|
# return Response(serializer.data) |
|
|
|
|