mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-21 22:07:59 -05:00
MediaCMS backend, initial commit
This commit is contained in:
29
cms/custom_pagination.py
Normal file
29
cms/custom_pagination.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from rest_framework.response import Response
|
||||
from collections import OrderedDict # requires Python 2.7 or later
|
||||
from django.core.paginator import Paginator
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
|
||||
class FasterDjangoPaginator(Paginator):
|
||||
@cached_property
|
||||
def count(self):
|
||||
return 50
|
||||
|
||||
|
||||
class FastPaginationWithoutCount(PageNumberPagination):
|
||||
"""Experimental, for cases where a SELECT COUNT is redundant"""
|
||||
|
||||
django_paginator_class = FasterDjangoPaginator
|
||||
|
||||
def get_paginated_response(self, data):
|
||||
|
||||
return Response(
|
||||
OrderedDict(
|
||||
[
|
||||
("next", self.get_next_link()),
|
||||
("previous", self.get_previous_link()),
|
||||
("results", data),
|
||||
]
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user