Skip to content

Commit

Permalink
Add REST API pagination settings
Browse files Browse the repository at this point in the history
Add settings to allow changing the default and the maximum
REST API page size.

Signed-off-by: Roberto Rosario <[email protected]>
  • Loading branch information
Roberto Rosario committed Oct 19, 2021
1 parent 65d9e6e commit 2f9f662
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
4.0.18 (2021-XX-XX)
===================
- Add settings to allow changing the default and the maximums
REST API page size.

4.0.17 (2021-10-18)
===================
- Backport workaround for swagger-spec-validator dependency
Expand Down
6 changes: 4 additions & 2 deletions mayan/apps/rest_api/literals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
API_VERSION = '4'
DEFAULT_MAX_PAGE_SIZE = 100
DEFAULT_PAGE_SIZE = 10

DEFAULT_PAGE_SIZE_QUERY_PARAMETER = 'page_size'
DEFAULT_REST_API_DISABLE_LINKS = False
DEFAULT_REST_API_MAXIMUM_PAGE_SIZE = 100
DEFAULT_REST_API_PAGE_SIZE = 10

10 changes: 4 additions & 6 deletions mayan/apps/rest_api/pagination.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from rest_framework import pagination

from .literals import (
DEFAULT_MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE,
DEFAULT_PAGE_SIZE_QUERY_PARAMETER
)
from .literals import DEFAULT_PAGE_SIZE_QUERY_PARAMETER
from .settings import setting_maximum_page_size, setting_page_size


class MayanPageNumberPagination(pagination.PageNumberPagination):
max_page_size = DEFAULT_MAX_PAGE_SIZE
page_size = DEFAULT_PAGE_SIZE
max_page_size = setting_maximum_page_size.value
page_size = setting_page_size.value
page_size_query_param = DEFAULT_PAGE_SIZE_QUERY_PARAMETER
18 changes: 17 additions & 1 deletion mayan/apps/rest_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from mayan.apps.smart_settings.classes import SettingNamespace

from .literals import DEFAULT_REST_API_DISABLE_LINKS
from .literals import (
DEFAULT_REST_API_DISABLE_LINKS, DEFAULT_REST_API_MAXIMUM_PAGE_SIZE,
DEFAULT_REST_API_PAGE_SIZE
)

namespace = SettingNamespace(
label=_('REST API'), name='rest_api', version='0001'
Expand All @@ -14,3 +17,16 @@
'Disable the REST API links in the tools menu.'
)
)
setting_maximum_page_size = namespace.add_setting(
default=DEFAULT_REST_API_MAXIMUM_PAGE_SIZE,
global_name='REST_API_MAXIMUM_PAGE_SIZE', help_text=_(
'The maximum page size that can be requested.'
)
)
setting_page_size = namespace.add_setting(
default=DEFAULT_REST_API_PAGE_SIZE,
global_name='REST_API_PAGE_SIZE', help_text=_(
'The default page size if none is specified.'
)
)

0 comments on commit 2f9f662

Please sign in to comment.