55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
from rest_framework.pagination import LimitOffsetPagination
|
|
from rest_framework.response import Response
|
|
|
|
class PuckignationMixin(LimitOffsetPagination):
|
|
|
|
def get_paginated_response(self, data, status=200):
|
|
return Response({
|
|
'count': self.count,
|
|
'next': self.get_next_link(),
|
|
'previous': self.get_previous_link(),
|
|
'results': data
|
|
}, status=status)
|
|
|
|
def get_paginated_response_schema(self, schema, *args, **kwargs):
|
|
return {
|
|
'type': 'object',
|
|
'required': ['count', 'results'],
|
|
'properties': {
|
|
'count': {
|
|
'type': 'integer',
|
|
'example': 123,
|
|
},
|
|
'next': {
|
|
'type': 'string',
|
|
'nullable': True,
|
|
'format': 'uri',
|
|
'example': 'http://pfapi.puckoprutt.tech/actions/?format=yaml&{offset_param}=30&{limit_param}=10'.format(
|
|
offset_param=self.offset_query_param, limit_param=self.limit_query_param),
|
|
},
|
|
'previous': {
|
|
'type': 'string',
|
|
'nullable': True,
|
|
'format': 'uri',
|
|
'example': 'http://pfapi.puckoprutt.tech/actions/?format=yaml&{offset_param}=10&{limit_param}=10'.format(
|
|
offset_param=self.offset_query_param, limit_param=self.limit_query_param),
|
|
},
|
|
'results': schema,
|
|
}
|
|
}
|
|
|
|
class SmallPagination(PuckignationMixin):
|
|
page_size = 10
|
|
page_size_query_param = "page_size"
|
|
max_page_size = 25
|
|
|
|
class MediumPagination(PuckignationMixin):
|
|
page_size = 25
|
|
page_size_query_param = "page_size"
|
|
max_page_size = 55
|
|
|
|
class LargePagination(PuckignationMixin):
|
|
page_size = 100
|
|
page_size_query_param = "page_size"
|
|
max_page_size = 200
|