diff options
| author | Tom Christie | 2013-08-30 09:28:33 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-08-30 09:28:33 +0100 |
| commit | 9a5b2eefa92dede844ab94d049093e91ac98af5b (patch) | |
| tree | faf389e2f8c8296aeaa486ab97ed0be9113cc2ba /rest_framework/generics.py | |
| parent | bf07b8e616bd92e4ae3c2c09b198181d7075e6bd (diff) | |
| parent | f3ab0b2b1d5734314dbe3cdd13cd7c4f0531bf7d (diff) | |
| download | django-rest-framework-9a5b2eefa92dede844ab94d049093e91ac98af5b.tar.bz2 | |
Merge master
Diffstat (limited to 'rest_framework/generics.py')
| -rw-r--r-- | rest_framework/generics.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 8e6b8e26..851f8474 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): DeprecationWarning, stacklevel=2) if self.paginate_by_param: - query_params = self.request.QUERY_PARAMS try: - return strict_positive_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 |
