Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page_size parameter for all REST API methods #884

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://github.com/opencv/cvat/issues/750).
- Text Detection Auto Annoation Script in OpenVINO format for version 4

### Changed
-
- page_size parameter for all REST API methods

### Deprecated
-
Expand Down
22 changes: 22 additions & 0 deletions cvat/apps/engine/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2019 Intel Corporation
#
# SPDX-License-Identifier: MIT

import sys
from rest_framework.pagination import PageNumberPagination

class CustomPagination(PageNumberPagination):
page_size_query_param = "page_size"

def get_page_size(self, request):
page_size = 0
try:
value = request.query_params[self.page_size_query_param]
if value == "all":
page_size = sys.maxsize
else:
page_size = int(value)
except (KeyError, ValueError):
pass

return page_size if page_size > 0 else self.page_size
2 changes: 1 addition & 1 deletion cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def generate_ssh_keys():
# Need to add 'api-docs' here as a workaround for include_docs_urls.
'ALLOWED_VERSIONS': ('v1', 'api-docs'),
'DEFAULT_PAGINATION_CLASS':
'rest_framework.pagination.PageNumberPagination',
'cvat.apps.engine.pagination.CustomPagination',
'PAGE_SIZE': 10,
'DEFAULT_FILTER_BACKENDS': (
'rest_framework.filters.SearchFilter',
Expand Down