Пример #1
0
    def paginate_queryset(self, queryset, request, view=None):
        rql_ast = None
        try:
            rql_ast = request.rql_ast
        except AttributeError:
            query = get_query(request)
            if query:
                rql_ast = RQLParser.parse_query(query)

        if rql_ast is not None:
            try:
                self._rql_limit, self._rql_offset = RQLLimitOffsetTransformer(
                ).transform(rql_ast)
            except LarkError:
                raise RQLFilterParsingError(
                    details={
                        'error': 'Limit and offset are set incorrectly.',
                    })

        if self.get_limit() == 0:
            self.count = self.get_count(queryset)
            self.offset = 0
            return []

        return super(RQLLimitOffsetPagination,
                     self).paginate_queryset(queryset, request, view)
Пример #2
0
    def get_query(cls, filter_instance, request, view):
        query_string = cls.modify_initial_query(filter_instance, request,
                                                get_query(request))

        if not cls.is_old_syntax(filter_instance, request, query_string):
            return query_string

        return cls.get_rql_query(filter_instance, request, query_string)
Пример #3
0
    def get_query(cls, filter_instance, request, view):
        try:
            query_string = cls.modify_initial_query(filter_instance, request,
                                                    get_query(request))

            if not cls.is_old_syntax(filter_instance, request, query_string):
                return query_string

            else:
                return cls.get_rql_query(filter_instance, request,
                                         query_string)
        except Exception:
            raise RQLFilterParsingError(details={
                'error': 'Bad filter query.',
            })
Пример #4
0
    def paginate_queryset(self, queryset, request, view=None):
        rql_ast = None
        try:
            rql_ast = request.rql_ast
        except AttributeError:
            query = get_query(request)
            if query:
                rql_ast = RQLParser.parse_query(query)

        if rql_ast is not None:
            try:
                self._rql_limit, self._rql_offset = RQLLimitOffsetTransformer(
                ).transform(rql_ast)
            except LarkError:
                raise RQLFilterParsingError(
                    details={
                        'error': 'Limit and offset are set incorrectly.',
                    })

        self.limit = self.get_limit(request)
        if self.limit == 0:
            self.count = self.get_count(queryset)
            self.offset = 0
            return []

        elif self.limit is None:
            return None

        self.count = self.get_count(queryset)
        self.offset = self.get_offset(request)
        self.request = request
        if self.count > self.limit and self.template is not None:
            self.display_page_controls = True

        if self.count == 0 or self.offset > self.count:
            return []

        if self.limit + self.offset > self.count:
            self.limit = self.count - self.offset

        return list(queryset[self.offset:self.offset + self.limit])
Пример #5
0
 def get_query(cls, filter_instance, request, view):
     return get_query(request)