mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
Merge pull request #198 from KiwiTechLLC/ZBKADM-71
added pagination in leaderboard admin
This commit is contained in:
13
web_admin/pagination.py
Normal file
13
web_admin/pagination.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
web_admin pagination file
|
||||||
|
"""
|
||||||
|
from rest_framework.pagination import PageNumberPagination
|
||||||
|
|
||||||
|
|
||||||
|
class CustomPageNumberPagination(PageNumberPagination):
|
||||||
|
"""
|
||||||
|
custom paginator class
|
||||||
|
"""
|
||||||
|
page_size = 10 # Set the desired page size
|
||||||
|
page_size_query_param = 'page_size'
|
||||||
|
max_page_size = 100 # Set a maximum page size if needed
|
@ -1,10 +1,15 @@
|
|||||||
"""
|
"""
|
||||||
web_admin analytics view file
|
web_admin analytics view file
|
||||||
"""
|
"""
|
||||||
|
# python imports
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
# third party imports
|
||||||
from rest_framework.viewsets import GenericViewSet
|
from rest_framework.viewsets import GenericViewSet
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
|
# django imports
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
@ -12,10 +17,13 @@ from django.db.models.functions import TruncDate
|
|||||||
from django.db.models import F, Window
|
from django.db.models import F, Window
|
||||||
from django.db.models.functions.window import Rank
|
from django.db.models.functions.window import Rank
|
||||||
|
|
||||||
|
# local imports
|
||||||
from account.utils import custom_response
|
from account.utils import custom_response
|
||||||
from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, EXPIRED, DATE_FORMAT
|
from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, EXPIRED, DATE_FORMAT
|
||||||
from guardian.models import JuniorTask
|
from guardian.models import JuniorTask
|
||||||
from junior.models import JuniorPoints
|
from junior.models import JuniorPoints
|
||||||
|
from web_admin.pagination import CustomPageNumberPagination
|
||||||
|
from web_admin.permission import AdminPermission
|
||||||
from web_admin.serializers.analytics_serializer import LeaderboardSerializer
|
from web_admin.serializers.analytics_serializer import LeaderboardSerializer
|
||||||
|
|
||||||
USER = get_user_model()
|
USER = get_user_model()
|
||||||
@ -30,6 +38,7 @@ class AnalyticsViewSet(GenericViewSet):
|
|||||||
to get junior leaderboard and ranking
|
to get junior leaderboard and ranking
|
||||||
"""
|
"""
|
||||||
serializer_class = None
|
serializer_class = None
|
||||||
|
permission_classes = [IsAuthenticated, AdminPermission]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user_qs = USER.objects.filter(
|
user_qs = USER.objects.filter(
|
||||||
@ -128,7 +137,7 @@ class AnalyticsViewSet(GenericViewSet):
|
|||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at']
|
||||||
)).order_by('-total_points', 'junior__created_at')
|
)).order_by('-total_points', 'junior__created_at')
|
||||||
paginator = self.pagination_class()
|
paginator = CustomPageNumberPagination()
|
||||||
paginated_queryset = paginator.paginate_queryset(queryset, request)
|
paginated_queryset = paginator.paginate_queryset(queryset, request)
|
||||||
serializer = self.serializer_class(paginated_queryset, many=True)
|
serializer = self.serializer_class(paginated_queryset, many=True)
|
||||||
return custom_response(None, serializer.data)
|
return custom_response(None, serializer.data)
|
||||||
|
Reference in New Issue
Block a user