本文整理汇总了Python中rest_framework.settings.api_settings.PAGE_SIZE属性的典型用法代码示例。如果您正苦于以下问题:Python api_settings.PAGE_SIZE属性的具体用法?Python api_settings.PAGE_SIZE怎么用?Python api_settings.PAGE_SIZE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类rest_framework.settings.api_settings
的用法示例。
在下文中一共展示了api_settings.PAGE_SIZE属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_previous_link
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def get_previous_link(request):
""" Generate URL of previous page in pagination. """
limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE))
offset = int(request.query_params.get('offset', 0))
if offset <= 0:
return None
url = request.build_absolute_uri()
url = replace_query_param(url, 'limit', limit)
if offset - limit <= 0:
return remove_query_param(url, 'offset')
offset = offset - limit
return replace_query_param(url, 'offset', offset)
示例2: pagination_system_check
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def pagination_system_check(app_configs, **kwargs):
errors = []
# Use of default page size setting requires a default Paginator class
from rest_framework.settings import api_settings
if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS:
errors.append(
Warning(
"You have specified a default PAGE_SIZE pagination rest_framework setting,"
"without specifying also a DEFAULT_PAGINATION_CLASS.",
hint="The default for DEFAULT_PAGINATION_CLASS is None. "
"In previous versions this was PageNumberPagination. "
"If you wish to define PAGE_SIZE globally whilst defining "
"pagination_class on a per-view basis you may silence this check.",
id="rest_framework.W001"
)
)
return errors
示例3: paginate_results
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def paginate_results(request, *qs_serializers):
"""
Custom pagination to handle multiple querysets and renderers.
Supports serializing 1 to many different querysets. Based of DRF's
LimitOffsetPagination. Useful when adding pagination to a regular
APIView.
qs_serializers - tuple of a queryset/array and respective serializer
"""
limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE))
offset = int(request.query_params.get('offset', 0))
count = 0
cur_offset = offset
out = []
for qs, serializer in qs_serializers:
len_func = ('__len__' if isinstance(qs, list) else 'count')
qs_len = getattr(qs, len_func)()
count += qs_len
if (len(out) < limit):
end_index = min([limit - len(out) + cur_offset, qs_len])
qs = qs[cur_offset:end_index]
if qs:
out += serializer(qs, many=True).data
cur_offset = max([cur_offset - end_index, 0])
return OrderedDict([
('count', count),
('next', get_next_link(request, count)),
('previous', get_previous_link(request)),
('results', out),
])
示例4: get_next_link
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def get_next_link(request, count):
""" Generate URL of next page in pagination. """
limit = int(request.query_params.get('limit', api_settings.PAGE_SIZE))
offset = int(request.query_params.get('offset', 0))
if offset + limit >= count:
return None
url = request.build_absolute_uri()
url = replace_query_param(url, 'limit', limit)
offset = offset + limit
return replace_query_param(url, 'offset', offset)
示例5: test_next_link
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def test_next_link(self):
req = self._get_request('/foo')
assert (
get_next_link(req, 200) ==
'http://testserver/foo?limit={}&offset=100'.format(
api_settings.PAGE_SIZE))
示例6: test_previous_link
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def test_previous_link(self):
req = self._get_request('/foo', {'offset': 200})
resp = get_previous_link(req)
assert (
resp == 'http://testserver/foo?limit={}&offset=100'.format(
api_settings.PAGE_SIZE))
req = self._get_request('/foo', {'offset': api_settings.PAGE_SIZE})
resp = get_previous_link(req)
assert (
resp == 'http://testserver/foo?limit={}'.format(
api_settings.PAGE_SIZE))
示例7: __init__
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def __init__(
self,
results=None,
count=None,
current_page=None,
page_size=api_settings.PAGE_SIZE,
):
self.results = results
self.count = count
self.current_page = current_page
self.page_size = page_size
示例8: test_response_count_matches_results
# 需要导入模块: from rest_framework.settings import api_settings [as 别名]
# 或者: from rest_framework.settings.api_settings import PAGE_SIZE [as 别名]
def test_response_count_matches_results(self):
"""
Tests to ensure that the value in the count field matches the number of results returned in
the response.
:return: None
"""
response = self.send(user=self.auth_user)
content = response.json()
if content["count"] <= api_settings.PAGE_SIZE:
self.assertEqual(content["count"], len(content["results"]))