diff options
author | 2021-05-14 13:58:56 +0800 | |
---|---|---|
committer | 2021-05-14 14:23:29 +0800 | |
commit | 274efc3ec73e2bcfee9cd93b26f737ee68fd4638 (patch) | |
tree | c74a0fb5cb80b605d21843b8bd424a192198dd8a /pydis_site/apps/api/pagination.py | |
parent | Merge pull request #485 from python-discord/ks129/dewikification/redirection (diff) |
Merge branch main into dewikification
Diffstat (limited to 'pydis_site/apps/api/pagination.py')
-rw-r--r-- | pydis_site/apps/api/pagination.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py new file mode 100644 index 00000000..2a325460 --- /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": None, + ... "previous": None, + ... "results": [{ + ... "id": 6, + ... "inserted_at": "2021-01-26T21:13:35.477879Z", + ... "expires_at": None, + ... "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": None, + ... "active": False, + ... "user": 1, + ... "actor": 2, + ... "type": "warning", + ... "reason": None, + ... "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) |