aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/generics.py
diff options
context:
space:
mode:
authorTom Christie2013-08-29 20:52:46 +0100
committerTom Christie2013-08-29 20:52:46 +0100
commit19f9adacb254841d02f43295baf81406ce3c60eb (patch)
treef77644b5515c15e09d49d12aef0855c67262f9ba /rest_framework/generics.py
parente4d2f54529bcf538be93da5770e05b88a32da1c7 (diff)
parent02b6836ee88498861521dfff743467b0456ad109 (diff)
downloaddjango-rest-framework-19f9adacb254841d02f43295baf81406ce3c60eb.tar.bz2
Merge branch 'master' into display-raw-data
Diffstat (limited to 'rest_framework/generics.py')
-rw-r--r--rest_framework/generics.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index 5ecf6310..14feed20 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -14,13 +14,15 @@ from rest_framework.settings import api_settings
import warnings
-def strict_positive_int(integer_string):
+def strict_positive_int(integer_string, cutoff=None):
"""
Cast a string to a strictly positive integer.
"""
ret = int(integer_string)
if ret <= 0:
raise ValueError()
+ if cutoff:
+ ret = min(ret, cutoff)
return ret
def get_object_or_404(queryset, **filter_kwargs):
@@ -56,6 +58,7 @@ class GenericAPIView(views.APIView):
# Pagination settings
paginate_by = api_settings.PAGINATE_BY
paginate_by_param = api_settings.PAGINATE_BY_PARAM
+ max_paginate_by = api_settings.MAX_PAGINATE_BY
pagination_serializer_class = api_settings.DEFAULT_PAGINATION_SERIALIZER_CLASS
page_kwarg = 'page'
@@ -205,9 +208,11 @@ class GenericAPIView(views.APIView):
PendingDeprecationWarning, stacklevel=2)
if self.paginate_by_param:
- query_params = self.request.QUERY_PARAMS
try:
- return int(query_params[self.paginate_by_param])
+ return strict_positive_int(
+ self.request.QUERY_PARAMS[self.paginate_by_param],
+ cutoff=self.max_paginate_by
+ )
except (KeyError, ValueError):
pass