forked from researchapps/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
page_size parameter for all REST API methods (cvat-ai#884)
* 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
Showing
3 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters