diff options
| author | Tom Christie | 2013-08-27 20:58:30 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-08-27 20:58:30 +0100 |
| commit | e1b54f2a2a078b3f1f9ba67f216d127b8182b100 (patch) | |
| tree | 24563d2badbe0bf3df2b84bc211bc1f4894a0572 /rest_framework/generics.py | |
| parent | ea6eee304c230a9277fdc76f4ac91654e0019b7a (diff) | |
| parent | 7fb3f078f0973acc1d108d8c617b26b6845599f7 (diff) | |
| download | django-rest-framework-e1b54f2a2a078b3f1f9ba67f216d127b8182b100.tar.bz2 | |
Merge branch 'max_paginate_by' of git://github.com/alexander-akhmetov/django-rest-framework into alexander-akhmetov-max_paginate_by
Diffstat (limited to 'rest_framework/generics.py')
| -rw-r--r-- | rest_framework/generics.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 5ecf6310..ce6c462a 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,19 @@ 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 is not None: + return min(self.max_paginate_by, paginate_by_param) + else: + return paginate_by_param - return self.paginate_by + if self.max_paginate_by: + return min(self.max_paginate_by, self.paginate_by) + else: + return self.paginate_by def get_serializer_class(self): """ |
