"""Opaque cursor pagination (``API-STANDARD.md`` ยง6).""" from __future__ import annotations from typing import Any from rest_framework.pagination import CursorPagination as DRFCursorPagination from rest_framework.response import Response __all__ = ["CursorPagination"] class CursorPagination(DRFCursorPagination): """Cursor pagination with a camelCase ``pageSize`` param and envelope meta. Defaults to ordering by ``-pk`` so it works on every model out of the box; views with a preferred ordering override the ``ordering`` attribute. """ page_size = 25 max_page_size = 100 page_size_query_param = "pageSize" cursor_query_param = "cursor" ordering = "-pk" def get_paginated_response(self, data: Any) -> Response: return Response( { "next": self.get_next_link(), "previous": self.get_previous_link(), "page_size": self.page_size, "results": data, } )