Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
1f0a3434
Commit
1f0a3434
authored
May 24, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit to 10000 results per_page
parent
37458db3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
29 deletions
+2
-29
api/pagination.py
api/pagination.py
+2
-29
No files found.
api/pagination.py
View file @
1f0a3434
from
rest_framework
import
pagination
from
django.core
import
paginator
from
django.utils.functional
import
cached_property
class
AllowNegativePaginator
(
paginator
.
Paginator
):
"""
Paginator subclass to allow negative or null `per_page` argument,
meaning to show all items in one page.
"""
def
page
(
self
,
number
):
"""
Bypass the default page creation to render all items if `per_page`
argument is negative or null.
"""
if
self
.
per_page
<=
0
:
return
self
.
_get_page
(
self
.
object_list
,
1
,
self
)
return
super
(
AllowNegativePaginator
,
self
).
page
(
number
)
@
cached_property
def
num_pages
(
self
):
"""
Bypass the default number of page to return 1 if `per_page` argument
is negative or null.
"""
if
self
.
per_page
<=
0
:
return
1
return
super
(
AllowNegativePaginator
,
self
).
num_pages
class
PageSizedPagination
(
pagination
.
PageNumberPagination
):
...
...
@@ -34,13 +7,13 @@ class PageSizedPagination(pagination.PageNumberPagination):
"""
page_size_query_param
=
'page_size'
all_pages_strings
=
(
'all'
,)
django_paginator_class
=
AllowNegativePaginator
max_page_size
=
10000
def
get_page_size
(
self
,
request
):
try
:
page_size_str
=
request
.
query_params
[
self
.
page_size_query_param
]
if
page_size_str
in
self
.
all_pages_strings
:
return
-
1
return
self
.
max_page_size
except
KeyError
:
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment