當前位置: 首頁>>代碼示例>>Python>>正文


Python pagination.LimitOffsetPagination方法代碼示例

本文整理匯總了Python中rest_framework.pagination.LimitOffsetPagination方法的典型用法代碼示例。如果您正苦於以下問題:Python pagination.LimitOffsetPagination方法的具體用法?Python pagination.LimitOffsetPagination怎麽用?Python pagination.LimitOffsetPagination使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.pagination的用法示例。


在下文中一共展示了pagination.LimitOffsetPagination方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_pagination_introspector

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def get_pagination_introspector(view, si=None):
    """
    Create pagination introspector based on view
    :param view: DjangoRestFramework view
    :param si: SerializerIntrospector
    :return: PaginationIntrospector
    :rtype: BasePaginationIntrospector
    """
    if getattr(view, 'pagination_class', None):
        # DjangoRestFramework 3.0 pagination style with pagination class
        pagination_class = view.pagination_class
        from rest_framework import pagination
        if pagination_class == pagination.PageNumberPagination:
            return PageNumberPaginationIntrospector(view, pagination_class, si=si)
        elif pagination_class == pagination.LimitOffsetPagination:
            return LimitOffsetPaginationIntrospector(view, pagination_class, si=si)
        elif pagination_class == pagination.CursorPagination:
            return CursorPaginationIntrospector(view, pagination_class, si=si)
        else:
            return BasePaginationIntrospector(view, pagination_class, si=si)
    else:
        # Unrecognized view type
        return BasePaginationIntrospector(si=si) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:25,代碼來源:pagination.py

示例2: _get_paginator

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def _get_paginator(self, request=False):
        for paginator, query_param in self.proxy.paginators:
            # DRF's ListModelMixin calls paginate_queryset() prior to get_paginated_response(),
            # storing the original request on the paginator's `request` attribute. If the paginator
            # has this attribute, it means we've routed a previous paginate_queryset() call
            # to it and should continue using it.
            is_request_stored = hasattr(paginator, 'request')

            # If a request is available, look for the presence of a query parameter
            # indicating that we should use this paginator.
            is_query_param_present = request and request.query_params.get(query_param)

            if is_request_stored or is_query_param_present:
                return paginator

        # If we don't have a stored request or query parameter to go off of,
        # default to the last paginator in the list on the proxy. To preserve
        # pre-existing behavior, this is currently LimitOffsetPagination.
        return paginator  # pylint: disable=undefined-loop-variable 
開發者ID:edx,項目名稱:course-discovery,代碼行數:21,代碼來源:pagination.py

示例3: __getattr__

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def __getattr__(self, name):
        # For each paginator, check if the requested attribute is defined.
        # If the attr is defined on both paginators, we take the one defined for
        # LimitOffsetPagination. As of this writing, `display_page_controls` is
        # the only attr shared by the two pagination classes.
        for paginator, __ in self.paginators:
            try:
                attr = getattr(paginator, name)
            except AttributeError:
                pass

        # The value defined for the attribute in the paginators may be None, which
        # prevents us from defaulting `attr` to None.
        try:
            attr
        except NameError:
            # The attribute wasn't found on either paginator.
            raise AttributeError
        else:
            # The attribute was found. If it's callable, return a ProxiedCall
            # which will route method calls to the correct paginator.
            if callable(attr):
                return ProxiedCall(self, name)
            else:
                return attr 
開發者ID:edx,項目名稱:course-discovery,代碼行數:27,代碼來源:pagination.py

示例4: get_paginator_serializer

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def get_paginator_serializer(self, view, child_serializer_class):
        class BaseFakeListSerializer(serializers.Serializer):
            results = child_serializer_class(many=True)

        class FakePrevNextListSerializer(BaseFakeListSerializer):
            next = URLField()
            previous = URLField()

        # Validate if the view has a pagination_class
        if not (hasattr(view, 'pagination_class')) or view.pagination_class is None:
            return BaseFakeListSerializer

        pager = view.pagination_class
        if hasattr(pager, 'default_pager'):
            # Must be a ProxyPagination
            pager = pager.default_pager

        if issubclass(pager, (PageNumberPagination, LimitOffsetPagination)):
            class FakeListSerializer(FakePrevNextListSerializer):
                count = IntegerField()
            return FakeListSerializer
        elif issubclass(pager, CursorPagination):
            return FakePrevNextListSerializer

        return BaseFakeListSerializer 
開發者ID:limdauto,項目名稱:drf_openapi,代碼行數:27,代碼來源:entities.py

示例5: __init__

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def __init__(self, serializer_class, *args, **kwargs):
        """
        The `source`, whether implied or explicit, must be a manager or
        queryset. Alternatively, pass a `source_processor` callable that
        transforms `source` into a usable queryset.

        :param serializer_class: The class (not instance) of the desired list
            serializer. Required.
        :param paginator_class: Optional; defaults to `LimitOffsetPagination`.
        :param default_limit: Optional; defaults to `10`.
        :param source_processor: Optional; a callable that receives `source`
            and must return an usable queryset
        """
        self.serializer_class = serializer_class
        self.paginator = kwargs.pop('paginator_class', LimitOffsetPagination)()
        self.paginator.default_limit = kwargs.pop('default_limit', 10)
        self.source_processor = kwargs.pop('source_processor', None)
        super().__init__(*args, **kwargs) 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:20,代碼來源:paginated_api.py

示例6: __init__

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def __init__(self):
        page_number_paginator = PageNumberPagination()
        limit_offset_paginator = LimitOffsetPagination()

        self.paginators = [
            (page_number_paginator, page_number_paginator.page_query_param),
            (limit_offset_paginator, limit_offset_paginator.limit_query_param),
        ] 
開發者ID:edx,項目名稱:course-discovery,代碼行數:10,代碼來源:pagination.py

示例7: setUp

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def setUp(self):
        super().setUp()

        self.proxied_paginator = ProxiedPagination()
        self.page_number_paginator = PageNumberPagination()
        self.limit_offset_paginator = LimitOffsetPagination()

        self.queryset = range(100) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:10,代碼來源:test_pagination.py

示例8: test_default_pagination

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def test_default_pagination(self):
        """
        Verify that ProxiedPagination behaves like LimitOffsetPagination by
        default, when no query parameters are present.
        """
        request = self.get_request()
        self.assert_proxied(self.limit_offset_paginator, request) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:9,代碼來源:test_pagination.py

示例9: test_noncallable_attribute_access

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def test_noncallable_attribute_access(self):
        """
        Verify that attempts to access noncallable attributes are proxied to
        PageNumberPagination and LimitOffsetPagination.
        """
        # Access an attribute unique to PageNumberPagination.
        self.assertEqual(
            self.proxied_paginator.page_query_param,
            self.page_number_paginator.page_query_param
        )

        # Access an attribute unique to LimitOffsetPagination.
        self.assertEqual(
            self.proxied_paginator.limit_query_param,
            self.limit_offset_paginator.limit_query_param
        )

        # Access an attribute common to both PageNumberPagination and LimitOffsetPagination.
        self.assertEqual(
            self.proxied_paginator.display_page_controls,
            self.limit_offset_paginator.display_page_controls
        )

        # Access an attribute found on neither PageNumberPagination nor LimitOffsetPagination.
        with self.assertRaises(AttributeError):
            zach = self.proxied_paginator
            zach.cool  # pylint: disable=pointless-statement 
開發者ID:edx,項目名稱:course-discovery,代碼行數:29,代碼來源:test_pagination.py

示例10: get

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def get(self, request):
        serializer_context = {'request': request}
        page = LimitOffsetPagination()
        paginated_result = page.paginate_queryset(self.get_queryset(), request)

        serializer = self.serializer_class(paginated_result, context=serializer_context, many=True)

        new_data = {
            'posts': serializer.data
        }

        return Response(new_data) 
開發者ID:Monal5031,項目名稱:cruzz,代碼行數:14,代碼來源:views.py

示例11: get

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def get(self, request):
        serializer_context = {'request': request}
        page = LimitOffsetPagination()
        paginated_result = page.paginate_queryset(self.get_queryset(), request)

        serializer = self.serializer_class(paginated_result, context=serializer_context, many=True)

        new_data = {
            'profiles': serializer.data
        }

        return Response(new_data) 
開發者ID:Monal5031,項目名稱:cruzz,代碼行數:14,代碼來源:views.py

示例12: pagination_factory

# 需要導入模塊: from rest_framework import pagination [as 別名]
# 或者: from rest_framework.pagination import LimitOffsetPagination [as 別名]
def pagination_factory(endpoint):
    pg_cls_name = '{}Pagination'.format(endpoint.model.__name__)

    page_size = getattr(endpoint, 'page_size', None)
    pg_cls_attrs = {
        'page_size': page_size if page_size is not None else settings.REST_FRAMEWORK.get('PAGE_SIZE', 50),
    }

    if hasattr(endpoint, 'pagination_template'):
        pg_cls_attrs['template'] = endpoint.pagination_template

    BasePagination = getattr(endpoint, 'base_pagination_class', pagination.PageNumberPagination)
    if issubclass(BasePagination, pagination.PageNumberPagination):
        pg_cls_attrs['page_size_query_param'] = getattr(endpoint, 'page_size_query_param', 'page_size')
        for param in ('django_paginator_class', 'page_query_param', 'max_page_size', 'last_page_string',
                      'page_size'):
            if getattr(endpoint, param, None) is not None:
                pg_cls_attrs[param] = getattr(endpoint, param)
    elif issubclass(BasePagination, pagination.LimitOffsetPagination):
        pg_cls_attrs.pop('page_size')
        for param in ('default_limit', 'limit_query_param', 'offset_query_param', 'max_limit'):
            if getattr(endpoint, param, None) is not None:
                pg_cls_attrs[param] = getattr(endpoint, param)
    elif issubclass(BasePagination, pagination.CursorPagination):
        for param in ('page_size', 'cursor_query_param', 'ordering'):
            if getattr(endpoint, param, None) is not None:
                pg_cls_attrs[param] = getattr(endpoint, param)
    else:
        raise ImproperlyConfigured('base_pagination_class needs to be a subclass of one of the following:'
                                   'PageNumberPagination, LimitOffsetPagination, CursorPagination')

    return type(pg_cls_name, (BasePagination, ), pg_cls_attrs) 
開發者ID:drf-forms,項目名稱:drf-schema-adapter,代碼行數:34,代碼來源:factories.py


注:本文中的rest_framework.pagination.LimitOffsetPagination方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。