當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。