Skip to content

customize pagination size #65

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
OpenApiTypes,
extend_schema,
)
from rest_framework.pagination import PageNumberPagination

from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination
from base.logging import logger
from donations.models import Donation
from donations.serializers import (
Expand Down Expand Up @@ -44,7 +45,7 @@
)


class DonorsAPI(APIView, PageNumberPagination):
class DonorsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -89,7 +90,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountsListAPI(APIView, PageNumberPagination):
class AccountsListAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -157,7 +158,7 @@ def get(self, request: Request, *args, **kwargs):
return Response(serializer.data)


class AccountActivePotsAPI(APIView, PageNumberPagination):
class AccountActivePotsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -214,7 +215,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountPotApplicationsAPI(APIView, PageNumberPagination):
class AccountPotApplicationsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -269,7 +270,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountDonationsReceivedAPI(APIView, PageNumberPagination):
class AccountDonationsReceivedAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -310,7 +311,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountDonationsSentAPI(APIView, PageNumberPagination):
class AccountDonationsSentAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -351,7 +352,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class AccountPayoutsReceivedAPI(APIView, PageNumberPagination):
class AccountPayoutsReceivedAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down
7 changes: 7 additions & 0 deletions api/pagination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter
from rest_framework.pagination import PageNumberPagination



# ovveeride PageNumberPagination to add page_size_query_param alias
class CustomSizePageNumberPagination(PageNumberPagination):
page_size_query_param = 'page_size'

pagination_parameters = [
OpenApiParameter(
Expand Down
5 changes: 3 additions & 2 deletions donations/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
OpenApiResponse,
extend_schema,
)
from rest_framework.pagination import PageNumberPagination

from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination
from base.logging import logger

from .serializers import DonationContractConfigSerializer

DONATE_CONTRACT = "donate." + settings.POTLOCK_TLA


class DonationContractConfigAPI(APIView, PageNumberPagination):
class DonationContractConfigAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down
6 changes: 3 additions & 3 deletions lists/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
OpenApiResponse,
extend_schema,
)
from rest_framework.pagination import PageNumberPagination
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination

from .models import List, ListRegistrationStatus
from .serializers import (
Expand All @@ -30,7 +30,7 @@
)


class ListsListAPI(APIView, PageNumberPagination):
class ListsListAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -98,7 +98,7 @@ def get(self, request: Request, *args, **kwargs):
return Response(serializer.data)


class ListRegistrationsAPI(APIView, PageNumberPagination):
class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down
14 changes: 7 additions & 7 deletions pots/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
OpenApiResponse,
extend_schema,
)
from rest_framework.pagination import PageNumberPagination
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
Expand All @@ -20,6 +19,7 @@
PaginatedAccountsResponseSerializer,
)
from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination
from donations.models import Donation
from donations.serializers import (
PAGINATED_DONATION_EXAMPLE,
Expand All @@ -45,7 +45,7 @@
)


class PotsListAPI(APIView, PageNumberPagination):
class PotsListAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -75,7 +75,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class PotFactoriesAPI(APIView, PageNumberPagination):
class PotFactoriesAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -139,7 +139,7 @@ def get(self, request: Request, *args, **kwargs):
return Response(serializer.data)


class PotApplicationsAPI(APIView, PageNumberPagination):
class PotApplicationsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -177,7 +177,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class PotDonationsAPI(APIView, PageNumberPagination):
class PotDonationsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -215,7 +215,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class PotSponsorsAPI(APIView, PageNumberPagination):
class PotSponsorsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down Expand Up @@ -258,7 +258,7 @@ def get(self, request: Request, *args, **kwargs):
return self.get_paginated_response(serializer.data)


class PotPayoutsAPI(APIView, PageNumberPagination):
class PotPayoutsAPI(APIView, CustomSizePageNumberPagination):

@extend_schema(
parameters=[
Expand Down