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
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
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
def finalize_query(self, query: SaQuery) -> SaQuery: return query.order_by(model.Post.post_id.desc())
def finalize_query(self, query: SaQuery) -> SaQuery: return query.order_by(model.User.name.asc())
def finalize_query(self, query: SaQuery) -> SaQuery: return query.order_by(model.Tag.first_name.asc())
def finalize_query(self, query: SaQuery) -> SaQuery: return query.order_by(model.Snapshot.creation_time.desc())
def finalize_query(self, query: SaQuery) -> SaQuery: return query.order_by(model.Comment.creation_time.desc())