diff --git a/base/pagination.py b/base/pagination.py new file mode 100644 index 0000000..085579c --- /dev/null +++ b/base/pagination.py @@ -0,0 +1,46 @@ +""" +web_admin pagination file +""" +# third party imports +from collections import OrderedDict +from rest_framework.pagination import PageNumberPagination + +from account.utils import custom_response +from base.constants import NUMBER + + +class CustomPageNumberPagination(PageNumberPagination): + """ + custom paginator class + """ + # Set the desired page size + page_size = NUMBER['ten'] + page_size_query_param = 'page_size' + # Set a maximum page size if needed + max_page_size = NUMBER['hundred'] + + def get_paginated_response(self, data): + """ + :param data: queryset to be paginated + :return: return a OrderedDict + """ + return custom_response(None, OrderedDict([ + ('count', self.page.paginator.count), + ('data', data), + ('current_page', self.page.number), + ('total_pages', self.page.paginator.num_pages), + + + ])) + + def get_paginated_dict_response(self, data): + """ + :param data: queryset to be paginated + :return: return a simple dict obj + """ + return { + 'current': self.page.number, + 'data': data, + 'total': self.page.paginator.count, + 'total_pages': self.page.paginator.num_pages, + } diff --git a/web_admin/pagination.py b/web_admin/pagination.py deleted file mode 100644 index c2eed5e..0000000 --- a/web_admin/pagination.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -web_admin pagination file -""" -# third party imports -from rest_framework.pagination import PageNumberPagination - -from base.constants import NUMBER - - -class CustomPageNumberPagination(PageNumberPagination): - """ - custom paginator class - """ - # Set the desired page size - page_size = NUMBER['ten'] - page_size_query_param = 'page_size' - # Set a maximum page size if needed - max_page_size = NUMBER['hundred'] diff --git a/web_admin/views/analytics.py b/web_admin/views/analytics.py index 926cd47..b4f228f 100644 --- a/web_admin/views/analytics.py +++ b/web_admin/views/analytics.py @@ -23,11 +23,11 @@ from django.http import HttpResponse # local imports from account.utils import custom_response, get_user_full_name -from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, EXPIRED, DATE_FORMAT, TASK_STATUS +from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, EXPIRED, TASK_STATUS from guardian.models import JuniorTask from guardian.utils import upload_excel_file_to_alibaba from junior.models import JuniorPoints -from web_admin.pagination import CustomPageNumberPagination +from base.pagination import CustomPageNumberPagination from web_admin.permission import AdminPermission from web_admin.serializers.analytics_serializer import LeaderboardSerializer, UserCSVReportSerializer from web_admin.utils import get_dates