コード例 #1
0
ファイル: serializers.py プロジェクト: saskeroms/badgr-server
class CursorPaginatedListSerializer(serializers.ListSerializer):
    def __init__(self,
                 queryset,
                 request,
                 ordering='updated_at',
                 *args,
                 **kwargs):
        self.paginator = BadgrCursorPagination(ordering=ordering)
        self.page = self.paginator.paginate_queryset(queryset, request)
        super(CursorPaginatedListSerializer, self).__init__(data=self.page,
                                                            *args,
                                                            **kwargs)

    def to_representation(self, data):
        representation = super(CursorPaginatedListSerializer,
                               self).to_representation(data)
        envelope = BaseSerializerV2.response_envelope(result=representation,
                                                      success=True,
                                                      description='ok')
        envelope['pagination'] = self.paginator.get_page_info()
        return envelope

    @property
    def data(self):
        return super(serializers.ListSerializer, self).data
コード例 #2
0
ファイル: serializers.py プロジェクト: saskeroms/badgr-server
 def __init__(self,
              queryset,
              request,
              ordering='updated_at',
              *args,
              **kwargs):
     self.paginator = BadgrCursorPagination(ordering=ordering)
     self.page = self.paginator.paginate_queryset(queryset, request)
     super(CursorPaginatedListSerializer, self).__init__(data=self.page,
                                                         *args,
                                                         **kwargs)
コード例 #3
0
ファイル: api.py プロジェクト: saskeroms/badgr-server
    def get_objects(self, request, **kwargs):
        queryset = self.get_queryset(request=request, **kwargs)
        per_page = self.get_page_size(request)

        # only paginate on request
        if per_page:
            self.paginator = BadgrCursorPagination(ordering=self.get_ordering(), page_size=per_page)
            page = self.paginator.paginate_queryset(queryset, request=request)
        else:
            page = list(queryset)

        return page
コード例 #4
0
class UncachedPaginatedViewMixin(object):
    min_per_page = 1
    max_per_page = 500
    default_per_page = None  # dont paginate by default
    per_page_query_parameter_name = 'num'
    ordering = "-created_at"

    def get_ordering(self):
        return self.ordering

    def get_queryset(self, request, **kwargs):
        raise NotImplementedError

    def get_objects(self, request, **kwargs):
        queryset = self.get_queryset(request=request, **kwargs)

        try:
            per_page = int(
                request.query_params.get(self.per_page_query_parameter_name,
                                         self.default_per_page))
            per_page = max(self.min_per_page, per_page)
            per_page = min(self.max_per_page, per_page)
        except (TypeError, ValueError):
            per_page = None

        # only paginate on request
        if per_page:
            self.paginator = BadgrCursorPagination(
                ordering=self.get_ordering(), page_size=per_page)
            page = self.paginator.paginate_queryset(queryset, request=request)
        else:
            page = list(queryset)

        return page
コード例 #5
0
ファイル: api.py プロジェクト: concentricsky/badgr-server
class UncachedPaginatedViewMixin(object):
    min_per_page = 1
    max_per_page = 500
    default_per_page = None  # dont paginate by default
    per_page_query_parameter_name = 'num'
    ordering = "-created_at"

    def get_ordering(self):
        return self.ordering

    def get_queryset(self, request, **kwargs):
        raise NotImplementedError

    def get_objects(self, request, **kwargs):
        queryset = self.get_queryset(request=request, **kwargs)

        try:
            per_page = int(request.query_params.get(self.per_page_query_parameter_name, self.default_per_page))
            per_page = max(self.min_per_page, per_page)
            per_page = min(self.max_per_page, per_page)
        except (TypeError, ValueError):
            per_page = None

        # only paginate on request
        if per_page:
            self.paginator = BadgrCursorPagination(ordering=self.get_ordering(), page_size=per_page)
            page = self.paginator.paginate_queryset(queryset, request=request)
        else:
            page = list(queryset)

        return page
コード例 #6
0
class CursorPaginatedListSerializer(serializers.ListSerializer):

    def __init__(self, queryset, request, *args, **kwargs):
        self.paginator = BadgrCursorPagination()
        self.page = self.paginator.paginate_queryset(queryset, request)
        super(CursorPaginatedListSerializer, self).__init__(data=self.page, *args, **kwargs)

    def to_representation(self, data):
        representation = super(CursorPaginatedListSerializer, self).to_representation(data)
        envelope = BaseSerializerV2.response_envelope(result=representation,
                                                      success=True,
                                                      description='ok')
        envelope['pagination'] = self.paginator.get_page_info()
        return envelope

    @property
    def data(self):
        return super(serializers.ListSerializer, self).data
コード例 #7
0
    def get_objects(self, request, **kwargs):
        queryset = self.get_queryset(request=request, **kwargs)

        try:
            per_page = int(
                request.query_params.get(self.per_page_query_parameter_name,
                                         self.default_per_page))
            per_page = max(self.min_per_page, per_page)
            per_page = min(self.max_per_page, per_page)
        except (TypeError, ValueError):
            per_page = None

        # only paginate on request
        if per_page:
            self.paginator = BadgrCursorPagination(
                ordering=self.get_ordering(), page_size=per_page)
            page = self.paginator.paginate_queryset(queryset, request=request)
        else:
            page = list(queryset)

        return page
コード例 #8
0
ファイル: api.py プロジェクト: concentricsky/badgr-server
    def get_objects(self, request, **kwargs):
        queryset = self.get_queryset(request=request, **kwargs)

        try:
            per_page = int(request.query_params.get(self.per_page_query_parameter_name, self.default_per_page))
            per_page = max(self.min_per_page, per_page)
            per_page = min(self.max_per_page, per_page)
        except (TypeError, ValueError):
            per_page = None

        # only paginate on request
        if per_page:
            self.paginator = BadgrCursorPagination(ordering=self.get_ordering(), page_size=per_page)
            page = self.paginator.paginate_queryset(queryset, request=request)
        else:
            page = list(queryset)

        return page
コード例 #9
0
 def __init__(self, queryset, request, *args, **kwargs):
     self.paginator = BadgrCursorPagination()
     self.page = self.paginator.paginate_queryset(queryset, request)
     super(CursorPaginatedListSerializer, self).__init__(data=self.page, *args, **kwargs)