Convert a Q object to filter
        :param q: a Q Object
        :return: a filter object
545668
def _Q_to_filter(self, q):
        
        default_filter = ANDFilter
        if q.connector == "OR":
            default_filter = ORFilter
        filters = []
        for child in q.children:
            if isinstance(child, Q):
                if child.children:
                    filters.append(self._Q_to_filter(child))
            elif isinstance(child, tuple):
                field, value = child
                filters.append(self._build_inner_filter(field, value))
        if len(filters) == 1:
            filter = filters[0]
            if q.negated:
                return NotFilter(filter)
            return filter
        if q.negated:
            return NotFilter(default_filter(filters))
        return default_filter(filters)
781016
def get_filter_qobj(self, keys=None):
    
    # only care about columns in aggregates right?
    cols = set()
    for agg in self.select.aggregates:
        cols.update(agg.cols)
    sels = [SelectExpr(col, [col], col, None) for col in cols]
    select = Select(sels)
    where = list(self.where)
    if keys:
      keys = list(keys)
      keys = map(sqlize, list(keys))
      expr = self.select.nonaggs[0].expr

      clause = []
      if None in keys:
        clause.append("%s is null" % expr)
      if len([k for k in keys if k is not None]) > 0:
        clause.append("%s in %%s" % expr)
      clause = " or ".join(clause)
      where.append(clause)
    else:
      where.append( '%s = %%s' % (self.select.nonaggs[0].expr ) )
    q = Query(self.db, select, self.fr, where)
    return q
837117
def query(self):
        
        ret = MultiDict(parse_qsl(self.raw_query_string, keep_blank_values=True))
        return MultiDictProxy(ret)
604189
def filter(self, **kwargs):
        
        from django.db.models import Q

        Statement = self.get_model('statement')

        kwargs.pop('page_size', 1000)
        order_by = kwargs.pop('order_by', None)
        tags = kwargs.pop('tags', [])
        exclude_text = kwargs.pop('exclude_text', None)
        exclude_text_words = kwargs.pop('exclude_text_words', [])
        persona_not_startswith = kwargs.pop('persona_not_startswith', None)
        search_text_contains = kwargs.pop('search_text_contains', None)

        # Convert a single sting into a list if only one tag is provided
        if type(tags) == str:
            tags = [tags]

        if tags:
            kwargs['tags__name__in'] = tags

        statements = Statement.objects.filter(**kwargs)

        if exclude_text:
            statements = statements.exclude(
                text__in=exclude_text
            )

        if exclude_text_words:
            or_query = [
                ~Q(text__icontains=word) for word in exclude_text_words
            ]

            statements = statements.filter(
                *or_query
            )

        if persona_not_startswith:
            statements = statements.exclude(
                persona__startswith='bot:'
            )

        if search_text_contains:
            or_query = Q()

            for word in search_text_contains.split(' '):
                or_query |= Q(search_text__contains=word)

            statements = statements.filter(
                or_query
            )

        if order_by:
            statements = statements.order_by(*order_by)

        for statement in statements.iterator():
            yield statement
1179917
def get_q_object(self):
        
        q_object = Q()
        for field in self.searchable_fields:
            value = self.request.GET.getlist(alias_field(self.model, field), None)
            mini_q = Q()
            for val in value:
                attr = "{0}{1}".format(field, self.specifications.get(field, ''))
                if val:
                    dic_tmp = {
                        attr: val
                    }
                    mini_q |= Q(**dic_tmp)
            q_object &= mini_q
        return q_object
1269921
def filter(self, q, parents=None):
        
        if self.node.leaf and self.node.filtered:
            # TODO: subject filters?
            q = q.where((self.parent.var,
                         self.predicate,
                         self.var))
            # TODO: inverted nodes
            q = self.filter_value(q, self.var)
        elif self.parent is not None:
            q = q.where((self.parent.var, self.predicate, self.var))

            if parents is not None:
                parents = [URIRef(p) for p in parents]
                q = q.filter(self.parent.var.in_(*parents))

        # TODO: forbidden nodes.
        for child in self.children:
            q = child.filter(q)
        return q
145664
def dicts_filter(dicts_object, field_to_filter, value_of_filter):
    
    lambda_query = lambda value: value[field_to_filter] == value_of_filter

    filtered_coin = filter(lambda_query, dicts_object)
    selected_coins = list(filtered_coin)
    #if not selected_coin: #Empty list, no coin found
    #    raise AttributeError('attribute %s not found' % attr)
    return selected_coins
143701
def get_follows(self, model_or_obj_or_qs):
        
        fname = self.fname(model_or_obj_or_qs)
        
        if isinstance(model_or_obj_or_qs, QuerySet):
            return self.filter(**{'%s__in' % fname: model_or_obj_or_qs})
        
        if inspect.isclass(model_or_obj_or_qs):
            return self.exclude(**{fname:None})

        return self.filter(**{fname:model_or_obj_or_qs})
538344
def __filter(filterable, filter_, logic_operation='and'):
        
        condition = []
        if not filter_:
            return filterable
        elif filter_.get('type') == '__ANY__':
            return filterable
        else:
            for key, value in filter_.items():
                condition.append('{key} == "{value}"'.format(key=key, value=value))
        try:
            res = filterable.query(" {operation} ".format(operation=logic_operation).join(condition))
        except pd.core.computation.ops.UndefinedVariableError:
            return pd.DataFrame()
        else:
            return res
808289
def _filter_by_simple_schema(self, qs, lookup, sublookup, value, schema):
        
        value_lookup = 'attrs__value_%s' % schema.datatype
        if sublookup:
            value_lookup = '%s__%s' % (value_lookup, sublookup)
        return {
            'attrs__schema': schema,
            str(value_lookup): value
        }
103697
def filter(self):
        
        argmap = {
            filter.label or label: filter.field
            for label, filter in self.filters.items()
        }
        args = self.opts.parser.parse(argmap)
        query = self.query if self.query is not None else self.opts.query
        for label, filter in self.filters.items():
            value = args.get(filter.label or label)
            if value is not None:
                query = filter.filter(query, self.opts.model, label, value)
        return query
1254997
def model_to_select_list(model_class, filter_dict=None, q_filter=None):
    
    if filter_dict is None:
        filter_dict = {}

    if q_filter is not None:
        filter_list = [q_filter]
    else:
        filter_list = []

    objects = model_class.objects.filter(
        *filter_list, **filter_dict).values('id', 'name')

    return list(objects)
1365630
def filtered(self, efilter):
        '''
        
        '''
        if not self.params:
            self.params={'filter' : efilter}
            return self
        if not self.params.has_key('filter'):
            self.params['filter'] = efilter
            return self
        self.params['filter'].update(efilter)
        return self
1362589
def filter(self, *query_filter):
        '''
        '''
        for query in query_filter:
            self.query.append(query)
        return self
145510
def filter(self, value=None, exclude=False, **selection):
        
        filters = self.meta.setdefault('filters', [])

        if value and len(selection):
            raise ValueError("Cannot specify a filter string and a filter keyword selection at the same time.")
        elif value:
            value = [value]
        elif len(selection):
            value = select(self.api.columns, selection, invert=exclude)

        filters.append(value)
        self.raw['filters'] = utils.paste(filters, ',', ';')
        return self
1307254
def device_filter(self):
        
        if isinstance(self._device_filter, str):
            return self._decode_query(self._device_filter)
        return self._device_filter
1132955
def query(self, *q):
    
    params = join_params(self.parameters, {"q": q})

    return self.__class__(**params)