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


Python pagination.CursorPagination方法代码示例

本文整理汇总了Python中rest_framework.pagination.CursorPagination方法的典型用法代码示例。如果您正苦于以下问题:Python pagination.CursorPagination方法的具体用法?Python pagination.CursorPagination怎么用?Python pagination.CursorPagination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.pagination的用法示例。


在下文中一共展示了pagination.CursorPagination方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_pagination_introspector

# 需要导入模块: from rest_framework import pagination [as 别名]
# 或者: from rest_framework.pagination import CursorPagination [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_serializer

# 需要导入模块: from rest_framework import pagination [as 别名]
# 或者: from rest_framework.pagination import CursorPagination [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

示例3: pagination_factory

# 需要导入模块: from rest_framework import pagination [as 别名]
# 或者: from rest_framework.pagination import CursorPagination [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.CursorPagination方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。