Browse Source

fix bookmark issues in online server for hadith and hadith corrections

master
Mohsen Taba 2 months ago
parent
commit
75a3553c4a
  1. 16
      apps/hadis/docs.py
  2. 5
      apps/hadis/views/hadis.py
  3. 2
      apps/podcast/views.py
  4. 13
      apps/video/serializers.py
  5. 58
      apps/video/views.py

16
apps/hadis/docs.py

@ -318,6 +318,14 @@ hadis_list_swagger = swagger_auto_schema(
required=True, required=True,
example='-330' example='-330'
), ),
openapi.Parameter(
'is_bookmark',
openapi.IN_QUERY,
description="Filter only bookmarked hadis for the authenticated user",
type=openapi.TYPE_BOOLEAN,
required=False,
default=False
),
openapi.Parameter( openapi.Parameter(
'page', 'page',
openapi.IN_QUERY, openapi.IN_QUERY,
@ -2373,6 +2381,14 @@ hadis_main_list_swagger = swagger_auto_schema(
required=False, required=False,
example="prayer" example="prayer"
), ),
openapi.Parameter(
'is_bookmark',
openapi.IN_QUERY,
description="Filter only bookmarked hadis for the authenticated user",
type=openapi.TYPE_BOOLEAN,
required=False,
default=False
),
openapi.Parameter( openapi.Parameter(
'status', 'status',
openapi.IN_QUERY, openapi.IN_QUERY,

5
apps/hadis/views/hadis.py

@ -1,4 +1,5 @@
from rest_framework.authentication import TokenAuthentication from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.generics import ListAPIView, RetrieveAPIView from rest_framework.generics import ListAPIView, RetrieveAPIView
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from utils.pagination import NoPagination, StandardResultsSetPagination from utils.pagination import NoPagination, StandardResultsSetPagination
@ -314,6 +315,8 @@ class HadisMainListView(ListAPIView):
API view to list Hadis by category_id API view to list Hadis by category_id
""" """
serializer_class = HadisListSerializer serializer_class = HadisListSerializer
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]
pagination_class = StandardResultsSetPagination pagination_class = StandardResultsSetPagination
@hadis_main_list_swagger @hadis_main_list_swagger
@ -562,6 +565,8 @@ class HadisCorrectionsView(ListAPIView):
API view to retrieve corrections for a specific hadis API view to retrieve corrections for a specific hadis
""" """
serializer_class = HadisCorrectionSerializer serializer_class = HadisCorrectionSerializer
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]
pagination_class = StandardResultsSetPagination pagination_class = StandardResultsSetPagination
lookup_field = 'slug' lookup_field = 'slug'
lookup_url_kwarg = 'hadis_slug' lookup_url_kwarg = 'hadis_slug'

2
apps/podcast/views.py

@ -202,7 +202,7 @@ class PodcastListAPIView(generics.ListAPIView):
bookmarked_ids = Bookmark.objects.filter( bookmarked_ids = Bookmark.objects.filter(
user=self.request.user, user=self.request.user,
service=Bookmark.ServiceChoices.PODCAST_PLAYLIST,
service=Bookmark.ServiceChoices.PODCAST,
status=True status=True
).values_list('content_id', flat=True) ).values_list('content_id', flat=True)

13
apps/video/serializers.py

@ -277,4 +277,17 @@ class MiddleVideoCollectionSerializer(serializers.ModelSerializer):
def get_playlists(self, obj): def get_playlists(self, obj):
playlists = obj.related_playlists.filter(status=True).order_by('order', '-created_at') playlists = obj.related_playlists.filter(status=True).order_by('order', '-created_at')
# Filter by bookmarks if requested in context
is_bookmark = self.context.get('is_bookmark')
request = self.context.get('request')
if is_bookmark == 'true' and request 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)
playlists = playlists.filter(id__in=bookmarked_ids)
return VideoPlaylistListSerializer(playlists, many=True, context=self.context).data return VideoPlaylistListSerializer(playlists, many=True, context=self.context).data

58
apps/video/views.py

@ -51,6 +51,15 @@ class PinnedVideoCollectionListView(generics.ListAPIView):
@swagger_auto_schema( @swagger_auto_schema(
operation_description="Get a list of pinned video collections", operation_description="Get a list of pinned video collections",
tags=["Dobodbi - Video"], 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={ responses={
200: openapi.Response( 200: openapi.Response(
description="List of pinned video collections", description="List of pinned video collections",
@ -62,10 +71,25 @@ class PinnedVideoCollectionListView(generics.ListAPIView):
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
def get_queryset(self): def get_queryset(self):
return PinnedVideoCollection.objects.filter(
queryset = PinnedVideoCollection.objects.filter(
status=True, status=True,
display_position=VideoCollection.DisplayPosition.PINNED display_position=VideoCollection.DisplayPosition.PINNED
).order_by('-order', '-id') ).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): def list(self, request, *args, **kwargs):
response = super().list(request, *args, **kwargs) response = super().list(request, *args, **kwargs)
@ -97,6 +121,15 @@ class MiddleVideoCollectionListView(generics.ListAPIView):
@swagger_auto_schema( @swagger_auto_schema(
operation_description="Get a list of middle video collections", operation_description="Get a list of middle video collections",
tags=["Dobodbi - Video"], 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={ responses={
200: openapi.Response( 200: openapi.Response(
description="List of middle video collections", description="List of middle video collections",
@ -114,6 +147,29 @@ class MiddleVideoCollectionListView(generics.ListAPIView):
).order_by('order') ).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): class VideoPlaylistListAPIView(generics.ListAPIView):
""" """
API view to list all video playlists, with optional filtering by category or collection API view to list all video playlists, with optional filtering by category or collection

Loading…
Cancel
Save