コード例 #1
0
ファイル: filters.py プロジェクト: jeffca/recipes
    def process_request(self, query):
        field_dict = self.get_field_dict()
        FormClass = self.get_form(field_dict)

        form = FormClass(request.args)
        query_filters = self.parse_query_filters()
        cleaned = []

        for field, filters in query_filters.items():
            for (filter_idx_list, filter_value_list, path, join_path, qf_s,
                 qf_v) in filters:
                query = query.switch(self.model)
                for join, model in zip(join_path, path):
                    query = query.join(model, on=join)

                q_objects = []
                for filter_idx, filter_value in zip(filter_idx_list,
                                                    filter_value_list):
                    idx = int(filter_idx)
                    cleaned.append((qf_s, idx, qf_v, filter_value))
                    query_filter = self._query_filters[field][idx]
                    q_objects.append(
                        query_filter.query(field.db_value(filter_value)))

                query = query.where(reduce(operator.or_, q_objects))

        return form, query, cleaned
コード例 #2
0
ファイル: rest.py プロジェクト: coleifer/flask-peewee
 def apply_filter(self, query, expr, op, arg_list, negated):
     query_expr = '%s__%s' % (expr, op)
     constructor = lambda kwargs: negated and ~DQ(**kwargs) or DQ(**kwargs)
     if op == 'in':
         # in gives us a string format list '1,2,3,4'
         # we have to turn it into a list before passing to
         # the filter.
         arg_list = [i.strip() for i in arg_list[0].split(',')]
         return query.filter(constructor({query_expr: arg_list}))
     elif len(arg_list) == 1:
         return query.filter(constructor({query_expr: arg_list[0]}))
     else:
         query_clauses = [
             constructor({query_expr: val}) for val in arg_list]
         return query.filter(reduce(operator.or_, query_clauses))
コード例 #3
0
 def apply_filter(self, query, expr, op, arg_list, negated):
     query_expr = '%s__%s' % (expr, op)
     constructor = lambda kwargs: negated and ~DQ(**kwargs) or DQ(**kwargs)
     if op == 'in':
         # in gives us a string format list '1,2,3,4'
         # we have to turn it into a list before passing to
         # the filter.
         arg_list = [i.strip() for i in arg_list[0].split(',')]
         return query.filter(constructor({query_expr: arg_list}))
     elif len(arg_list) == 1:
         return query.filter(constructor({query_expr: arg_list[0]}))
     else:
         query_clauses = [
             constructor({query_expr: val}) for val in arg_list
         ]
         return query.filter(reduce(operator.or_, query_clauses))
コード例 #4
0
ファイル: filters.py プロジェクト: coleifer/flask-peewee
    def process_request(self, query):
        field_dict = self.get_field_dict()
        FormClass = self.get_form(field_dict)

        form = FormClass(request.args)
        query_filters = self.parse_query_filters()
        cleaned = []

        for field, filters in query_filters.items():
            for (filter_idx_list, filter_value_list, path, join_path, qf_s, qf_v) in filters:
                query = query.switch(self.model)
                for join, model in zip(join_path, path):
                    query = query.join(model, on=join)

                q_objects = []
                for filter_idx, filter_value in zip(filter_idx_list, filter_value_list):
                    idx = int(filter_idx)
                    cleaned.append((qf_s, idx, qf_v, filter_value))
                    query_filter = self._query_filters[field][idx]
                    q_objects.append(query_filter.query(field.db_value(filter_value)))

                query = query.where(reduce(operator.or_, q_objects))

        return form, query, cleaned