Skip to content

Commit

Permalink
page_size parameter for all REST API methods (cvat-ai#884)
Browse files Browse the repository at this point in the history
* Added page_size parameter for all REST API methods which returns list of objects.

Also it is possible to specify page_size=all to return all elements.

* Updated changelog.md
  • Loading branch information
nmanovic authored and Chris Lee-Messer committed Mar 5, 2020
1 parent 2fefeb4 commit d3948cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit d3948cb

Please sign in to comment.