diff options
| author | Alexander Akhmetov | 2013-08-26 20:05:36 +0400 |
|---|---|---|
| committer | Alexander Akhmetov | 2013-08-26 20:14:17 +0400 |
| commit | 316de3a8a314162e3d6ec081344eabca3a4d91b9 (patch) | |
| tree | b7ed9ee1eb27dc15b21136c1ce7e8f5b9c71f766 /rest_framework/generics.py | |
| parent | 2bcad32dcb57ae9419f6a901e081f0dcdc1a6f87 (diff) | |
| download | django-rest-framework-316de3a8a314162e3d6ec081344eabca3a4d91b9.tar.bz2 | |
Added max_paginate_by parameter
Diffstat (limited to 'rest_framework/generics.py')
| -rw-r--r-- | rest_framework/generics.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 5ecf6310..33affee8 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -56,6 +56,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' @@ -207,11 +208,16 @@ class GenericAPIView(views.APIView): if self.paginate_by_param: query_params = self.request.QUERY_PARAMS try: - return int(query_params[self.paginate_by_param]) + paginate_by_param = int(query_params[self.paginate_by_param]) except (KeyError, ValueError): pass + else: + if self.max_paginate_by: + return min(self.max_paginate_by, paginate_by_param) + else: + return paginate_by_param - return self.paginate_by + return min(self.max_paginate_by, self.paginate_by) or self.paginate_by def get_serializer_class(self): """ |
