From 4a5fa2d3c8e0aa2d71e13d15ca7b31ef46535001 Mon Sep 17 00:00:00 2001 From: Kunal Sharma Date: Fri, 26 Feb 2021 13:10:05 +0530 Subject: Update pagination docs and pagination class location --- pydis_site/apps/api/pagination.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pydis_site/apps/api/pagination.py (limited to 'pydis_site/apps/api/pagination.py') diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py new file mode 100644 index 00000000..bd8d963d --- /dev/null +++ b/pydis_site/apps/api/pagination.py @@ -0,0 +1,49 @@ +import typing + +from rest_framework.pagination import LimitOffsetPagination +from rest_framework.response import Response + + +class LimitOffsetPaginationExtended(LimitOffsetPagination): + """ + Extend LimitOffsetPagination to customise the default response. + + For example: + + ## Default response + { + "count": 1, + "next": null, + "previous": null, + "results": [{ + "id": 6, + "inserted_at": "2021-01-26T21:13:35.477879Z", + "expires_at": null, + "active": false, + "user": 1, + "actor": 2, + "type": "warning", + "reason": null, + "hidden": false + }] + } + ## Required response + [{ + "id": 6, + "inserted_at": "2021-01-26T21:13:35.477879Z", + "expires_at": null, + "active": false, + "user": 1, + "actor": 2, + "type": "warning", + "reason": null, + "hidden": false + }] + + """ + + default_limit = 100 + + def get_paginated_response(self, data: typing.Any) -> Response: + """Override to skip metadata i.e. `count`, `next` and `previous`.""" + return Response(data) -- cgit v1.2.3