当前位置: 首页>>代码示例>>Python>>正文


Python api_settings.PAGE_SIZE属性代码示例

本文整理汇总了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) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:util.py

示例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 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:19,代码来源:checks.py

示例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),
    ]) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:34,代码来源:util.py

示例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) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:15,代码来源:util.py

示例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)) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:8,代码来源:test_pagination.py

示例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)) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:14,代码来源:test_pagination.py

示例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 
开发者ID:lavalamp-,项目名称:ws-backend-community,代码行数:13,代码来源:pagination.py

示例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"])) 
开发者ID:lavalamp-,项目名称:ws-backend-community,代码行数:12,代码来源:mixin.py


注:本文中的rest_framework.settings.api_settings.PAGE_SIZE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。