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 From eae89ece75eba1947c2214266d5590aeba70c588 Mon Sep 17 00:00:00 2001 From: Kunal Sharma Date: Sun, 7 Mar 2021 20:29:22 +0530 Subject: Update doc in pydis_site/apps/api/pagination.py Co-authored-by: Mark --- pydis_site/apps/api/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site/apps/api/pagination.py') diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py index bd8d963d..f928ea94 100644 --- a/pydis_site/apps/api/pagination.py +++ b/pydis_site/apps/api/pagination.py @@ -45,5 +45,5 @@ class LimitOffsetPaginationExtended(LimitOffsetPagination): default_limit = 100 def get_paginated_response(self, data: typing.Any) -> Response: - """Override to skip metadata i.e. `count`, `next` and `previous`.""" + """Override to skip metadata i.e. `count`, `next`, and `previous`.""" return Response(data) -- cgit v1.2.3 From aa11f63cad537349c5ea04c6f969658c313a1370 Mon Sep 17 00:00:00 2001 From: Kunal Sharma Date: Sun, 7 Mar 2021 20:30:28 +0530 Subject: Update pydis_site/apps/api/pagination.py Co-authored-by: Mark --- pydis_site/apps/api/pagination.py | 1 - 1 file changed, 1 deletion(-) (limited to 'pydis_site/apps/api/pagination.py') diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py index f928ea94..ce9671ff 100644 --- a/pydis_site/apps/api/pagination.py +++ b/pydis_site/apps/api/pagination.py @@ -39,7 +39,6 @@ class LimitOffsetPaginationExtended(LimitOffsetPagination): "reason": null, "hidden": false }] - """ default_limit = 100 -- cgit v1.2.3 From c3c44ea0a733022fb30bb1905ce317b570e0466f Mon Sep 17 00:00:00 2001 From: Kunal Sharma Date: Sun, 7 Mar 2021 20:30:44 +0530 Subject: Update doc in pydis_site/apps/api/pagination.py Co-authored-by: Mark --- pydis_site/apps/api/pagination.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pydis_site/apps/api/pagination.py') diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py index ce9671ff..faf33687 100644 --- a/pydis_site/apps/api/pagination.py +++ b/pydis_site/apps/api/pagination.py @@ -27,6 +27,7 @@ class LimitOffsetPaginationExtended(LimitOffsetPagination): "hidden": false }] } + ## Required response [{ "id": 6, -- cgit v1.2.3 From b32f5b86d51eb2af4d959bc78450ec049e8b563f Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Sat, 24 Apr 2021 16:44:06 +0200 Subject: Pagination: Use REPL style examples --- pydis_site/apps/api/pagination.py | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'pydis_site/apps/api/pagination.py') diff --git a/pydis_site/apps/api/pagination.py b/pydis_site/apps/api/pagination.py index faf33687..2a325460 100644 --- a/pydis_site/apps/api/pagination.py +++ b/pydis_site/apps/api/pagination.py @@ -11,35 +11,35 @@ class LimitOffsetPaginationExtended(LimitOffsetPagination): 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 - }] - } + >>> { + ... "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": null, - "active": false, - "user": 1, - "actor": 2, - "type": "warning", - "reason": null, - "hidden": false - }] + >>> [{ + ... "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 -- cgit v1.2.3