mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 22:14:06 +03:00
updated script to just use page_size_kwarg
This commit is contained in:
parent
b17a981800
commit
3ae203a018
|
@ -149,8 +149,7 @@ Should be mixed in with [MultipleObjectAPIView].
|
||||||
|
|
||||||
**Arguments**:
|
**Arguments**:
|
||||||
|
|
||||||
* `allow_page_size_param` - Allows you to overwrite the global settings `ALLOW_PAGE_SIZE_PARAM` for a specific view.
|
* `page_size_kwarg` - Allows you to overwrite the global settings `PAGE_SIZE_KWARG` for a specific view. You can also turn it off for a specific view by setting it to `None`. Default is `page_size`.
|
||||||
* `page_size_param` - Allows you to customize the page_size parameter. Default is `page_size`.
|
|
||||||
|
|
||||||
## CreateModelMixin
|
## CreateModelMixin
|
||||||
|
|
||||||
|
|
|
@ -150,10 +150,14 @@ Default: `'accept'`
|
||||||
|
|
||||||
Default: `'format'`
|
Default: `'format'`
|
||||||
|
|
||||||
## ALLOW_PAGE_SIZE_PARAM
|
## PAGE_SIZE_KWARG
|
||||||
|
|
||||||
Allows you to globally pass a page size parameter for an individual request.
|
Allows you to globally pass a page size parameter for an individual request.
|
||||||
|
|
||||||
Default: `'True'`
|
The name of the GET parameter of views which inherit ListModelMixin for requesting data with an individual page size.
|
||||||
|
|
||||||
|
If the value if this setting is `None` the passing a page size is turned off by default.
|
||||||
|
|
||||||
|
Default: `'page_size'`
|
||||||
|
|
||||||
[cite]: http://www.python.org/dev/peps/pep-0020/
|
[cite]: http://www.python.org/dev/peps/pep-0020/
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
## Master
|
## Master
|
||||||
|
|
||||||
* Support for `read_only_fields` on `ModelSerializer` classes.
|
* Support for `read_only_fields` on `ModelSerializer` classes.
|
||||||
* Support for `page_size` GET parameter in views which inherit ListModelMixin.
|
* Support for individual page sizes per request via `page_size` GET parameter in views which inherit ListModelMixin.
|
||||||
* Support for customizing `page_size` param via `page_size_param` attribute.
|
|
||||||
* Support for allowing `page_size` param globally (via `ALLOW_PAGE_SIZE_PARAM`) and for individual views (via `allow_page_size_param`)
|
|
||||||
|
|
||||||
## 2.1.2
|
## 2.1.2
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ class ListModelMixin(object):
|
||||||
Should be mixed in with `MultipleObjectAPIView`.
|
Should be mixed in with `MultipleObjectAPIView`.
|
||||||
"""
|
"""
|
||||||
empty_error = u"Empty list and '%(class_name)s.allow_empty' is False."
|
empty_error = u"Empty list and '%(class_name)s.allow_empty' is False."
|
||||||
allow_page_size_param = api_settings.ALLOW_PAGE_SIZE_PARAM
|
page_size_kwarg = api_settings.PAGE_SIZE_KWARG
|
||||||
page_size_param = 'page_size'
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
self.object_list = self.get_filtered_queryset()
|
self.object_list = self.get_filtered_queryset()
|
||||||
|
@ -59,11 +58,11 @@ class ListModelMixin(object):
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
def get_paginate_by(self, queryset):
|
def get_paginate_by(self, queryset):
|
||||||
if self.allow_page_size_param:
|
if self.page_size_kwarg is not None:
|
||||||
page_size_param = self.request.QUERY_PARAMS.get(self.page_size_param)
|
page_size_kwarg = self.request.QUERY_PARAMS.get(self.page_size_kwarg)
|
||||||
if page_size_param:
|
if page_size_kwarg:
|
||||||
try:
|
try:
|
||||||
page_size = int(page_size_param)
|
page_size = int(page_size_kwarg)
|
||||||
return page_size
|
return page_size
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -68,7 +68,7 @@ DEFAULTS = {
|
||||||
|
|
||||||
'FORMAT_SUFFIX_KWARG': 'format',
|
'FORMAT_SUFFIX_KWARG': 'format',
|
||||||
|
|
||||||
'ALLOW_PAGE_SIZE_PARAM': True
|
'PAGE_SIZE_KWARG': 'page_size'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user