예제 #1
0
    def _prepare_db_query(self, db_query: SaQuery, search_query: SearchQuery,
                          use_sort: bool) -> SaQuery:
        for anon_token in search_query.anonymous_tokens:
            if not self.config.anonymous_filter:
                raise errors.SearchError(
                    "Anonymous tokens are not valid in this context.")
            db_query = self.config.anonymous_filter(db_query,
                                                    anon_token.criterion,
                                                    anon_token.negated)

        for named_token in search_query.named_tokens:
            if named_token.name not in self.config.named_filters:
                raise errors.SearchError(
                    "Unknown named token: %r. Available named tokens: %r." % (
                        named_token.name,
                        _format_dict_keys(self.config.named_filters),
                    ))
            db_query = self.config.named_filters[named_token.name](
                db_query, named_token.criterion, named_token.negated)

        for sp_token in search_query.special_tokens:
            if sp_token.value not in self.config.special_filters:
                raise errors.SearchError(
                    "Unknown special token: %r. "
                    "Available special tokens: %r." % (
                        sp_token.value,
                        _format_dict_keys(self.config.special_filters),
                    ))
            db_query = self.config.special_filters[sp_token.value](
                db_query, None, sp_token.negated)

        if use_sort:
            for sort_token in search_query.sort_tokens:
                if sort_token.name not in self.config.sort_columns:
                    raise errors.SearchError(
                        "Unknown sort token: %r. "
                        "Available sort tokens: %r." % (
                            sort_token.name,
                            _format_dict_keys(self.config.sort_columns),
                        ))
                column, default_order = self.config.sort_columns[
                    sort_token.name]
                order = _get_order(sort_token.order, default_order)
                if order == sort_token.SORT_ASC:
                    db_query = db_query.order_by(column.asc())
                elif order == sort_token.SORT_DESC:
                    db_query = db_query.order_by(column.desc())

        db_query = self.config.finalize_query(db_query)
        return db_query
예제 #2
0
파일: executor.py 프로젝트: rr-/szurubooru
    def _prepare_db_query(
            self,
            db_query: SaQuery,
            search_query: SearchQuery,
            use_sort: bool) -> SaQuery:
        for anon_token in search_query.anonymous_tokens:
            if not self.config.anonymous_filter:
                raise errors.SearchError(
                    'Anonymous tokens are not valid in this context.')
            db_query = self.config.anonymous_filter(
                db_query, anon_token.criterion, anon_token.negated)

        for named_token in search_query.named_tokens:
            if named_token.name not in self.config.named_filters:
                raise errors.SearchError(
                    'Unknown named token: %r. Available named tokens: %r.' % (
                        named_token.name,
                        _format_dict_keys(self.config.named_filters)))
            db_query = self.config.named_filters[named_token.name](
                db_query, named_token.criterion, named_token.negated)

        for sp_token in search_query.special_tokens:
            if sp_token.value not in self.config.special_filters:
                raise errors.SearchError(
                    'Unknown special token: %r. '
                    'Available special tokens: %r.' % (
                        sp_token.value,
                        _format_dict_keys(self.config.special_filters)))
            db_query = self.config.special_filters[sp_token.value](
                db_query, None, sp_token.negated)

        if use_sort:
            for sort_token in search_query.sort_tokens:
                if sort_token.name not in self.config.sort_columns:
                    raise errors.SearchError(
                        'Unknown sort token: %r. '
                        'Available sort tokens: %r.' % (
                            sort_token.name,
                            _format_dict_keys(self.config.sort_columns)))
                column, default_order = (
                    self.config.sort_columns[sort_token.name])
                order = _get_order(sort_token.order, default_order)
                if order == sort_token.SORT_ASC:
                    db_query = db_query.order_by(column.asc())
                elif order == sort_token.SORT_DESC:
                    db_query = db_query.order_by(column.desc())

        db_query = self.config.finalize_query(db_query)
        return db_query
예제 #3
0
파일: executor.py 프로젝트: yf-dev/yfbooru
    def _prepare_db_query(self, db_query: SaQuery, search_query: SearchQuery,
                          use_sort: bool) -> SaQuery:
        for anon_token in search_query.anonymous_tokens:
            if not self.config.anonymous_filter:
                raise errors.SearchError('익명 토큰은 이 컨텍스트에서 사용할 수 없습니다.')
            db_query = self.config.anonymous_filter(db_query,
                                                    anon_token.criterion,
                                                    anon_token.negated)

        for named_token in search_query.named_tokens:
            if named_token.name not in self.config.named_filters:
                raise errors.SearchError(
                    '알 수 없는 명명된 토큰: %r. 가능한 명명된 토큰: %r.' %
                    (named_token.name,
                     _format_dict_keys(self.config.named_filters)))
            db_query = self.config.named_filters[named_token.name](
                db_query, named_token.criterion, named_token.negated)

        for sp_token in search_query.special_tokens:
            if sp_token.value not in self.config.special_filters:
                raise errors.SearchError(
                    '알 수 없는 특수 토큰: %r. '
                    '가능한 특수 토큰: %r.' %
                    (sp_token.value,
                     _format_dict_keys(self.config.special_filters)))
            db_query = self.config.special_filters[sp_token.value](
                db_query, None, sp_token.negated)

        if use_sort:
            for sort_token in search_query.sort_tokens:
                if sort_token.name not in self.config.sort_columns:
                    raise errors.SearchError(
                        '알 수 없는 정렬 토큰: %r. '
                        '가능한 정렬 토큰: %r.' %
                        (sort_token.name,
                         _format_dict_keys(self.config.sort_columns)))
                column, default_order = (
                    self.config.sort_columns[sort_token.name])
                order = _get_order(sort_token.order, default_order)
                if order == sort_token.SORT_ASC:
                    db_query = db_query.order_by(column.asc())
                elif order == sort_token.SORT_DESC:
                    db_query = db_query.order_by(column.desc())

        db_query = self.config.finalize_query(db_query)
        return db_query
예제 #4
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Post.post_id.desc())
예제 #5
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.User.name.asc())
예제 #6
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Tag.first_name.asc())
예제 #7
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.User.name.asc())
예제 #8
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Snapshot.creation_time.desc())
예제 #9
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Tag.first_name.asc())
예제 #10
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Comment.creation_time.desc())
예제 #11
0
 def finalize_query(self, query: SaQuery) -> SaQuery:
     return query.order_by(model.Post.post_id.desc())