|
|
|
@ -51,6 +51,15 @@ class PinnedVideoCollectionListView(generics.ListAPIView): |
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Get a list of pinned video collections", |
|
|
|
tags=["Dobodbi - Video"], |
|
|
|
manual_parameters=[ |
|
|
|
openapi.Parameter( |
|
|
|
name='is_bookmark', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Filter collections that contain bookmarked playlists (true/false)', |
|
|
|
type=openapi.TYPE_BOOLEAN, |
|
|
|
required=False |
|
|
|
), |
|
|
|
], |
|
|
|
responses={ |
|
|
|
200: openapi.Response( |
|
|
|
description="List of pinned video collections", |
|
|
|
@ -62,11 +71,26 @@ class PinnedVideoCollectionListView(generics.ListAPIView): |
|
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
return PinnedVideoCollection.objects.filter( |
|
|
|
queryset = PinnedVideoCollection.objects.filter( |
|
|
|
status=True, |
|
|
|
display_position=VideoCollection.DisplayPosition.PINNED |
|
|
|
).order_by('-order', '-id') |
|
|
|
|
|
|
|
# Filter by bookmarks if requested |
|
|
|
is_bookmark = self.request.query_params.get('is_bookmark', '').lower() |
|
|
|
if is_bookmark == 'true' and self.request.user.is_authenticated: |
|
|
|
from apps.bookmark.models import Bookmark |
|
|
|
bookmarked_ids = Bookmark.objects.filter( |
|
|
|
user=self.request.user, |
|
|
|
service=Bookmark.ServiceChoices.VIDEO_PLAYLIST, |
|
|
|
status=True |
|
|
|
).values_list('content_id', flat=True) |
|
|
|
|
|
|
|
# Only include collections that contain at least one bookmarked playlist |
|
|
|
queryset = queryset.filter(related_playlists__id__in=bookmarked_ids).distinct() |
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
|
response = super().list(request, *args, **kwargs) |
|
|
|
categories_count = VideoCategory.objects.filter(status=True).count() |
|
|
|
@ -97,6 +121,15 @@ class MiddleVideoCollectionListView(generics.ListAPIView): |
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Get a list of middle video collections", |
|
|
|
tags=["Dobodbi - Video"], |
|
|
|
manual_parameters=[ |
|
|
|
openapi.Parameter( |
|
|
|
name='is_bookmark', |
|
|
|
in_=openapi.IN_QUERY, |
|
|
|
description='Filter collections that contain bookmarked playlists (true/false)', |
|
|
|
type=openapi.TYPE_BOOLEAN, |
|
|
|
required=False |
|
|
|
), |
|
|
|
], |
|
|
|
responses={ |
|
|
|
200: openapi.Response( |
|
|
|
description="List of middle video collections", |
|
|
|
@ -114,6 +147,29 @@ class MiddleVideoCollectionListView(generics.ListAPIView): |
|
|
|
).order_by('order') |
|
|
|
|
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
|
queryset = self.get_queryset() |
|
|
|
|
|
|
|
# Pass is_bookmark to serializer context |
|
|
|
is_bookmark = request.query_params.get('is_bookmark', '').lower() |
|
|
|
|
|
|
|
# If is_bookmark=true, we filter the queryset to only include collections that |
|
|
|
# have at least one bookmarked playlist |
|
|
|
if is_bookmark == 'true' and request.user.is_authenticated: |
|
|
|
from apps.bookmark.models import Bookmark |
|
|
|
bookmarked_ids = Bookmark.objects.filter( |
|
|
|
user=request.user, |
|
|
|
service=Bookmark.ServiceChoices.VIDEO_PLAYLIST, |
|
|
|
status=True |
|
|
|
).values_list('content_id', flat=True) |
|
|
|
|
|
|
|
# Filter collections that have any of these playlists |
|
|
|
queryset = queryset.filter(related_playlists__id__in=bookmarked_ids).distinct() |
|
|
|
|
|
|
|
serializer = self.get_serializer(queryset, many=True, context={'request': request, 'is_bookmark': is_bookmark}) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class VideoPlaylistListAPIView(generics.ListAPIView): |
|
|
|
""" |
|
|
|
API view to list all video playlists, with optional filtering by category or collection |
|
|
|
|