def exact_filter( model, filter_, satisfied_filters, cumulative_filter_dict, hints): """Applies an exact filter to a query. :param model: the table model in question :param filter_: the dict that describes this filter :param satisfied_filters: a cumulative list of satisfied filters, to which filter_ will be added if it is satisfied. :param cumulative_filter_dict: a dict that describes the set of exact filters built up so far :param hints: contains the list of filters yet to be satisfied. :returns: updated cumulative dict """ key = filter_['name'] if isinstance(getattr(model, key).property.columns[0].type, sql.types.Boolean): cumulative_filter_dict[key] = ( utils.attr_as_boolean(filter_['value'])) else: cumulative_filter_dict[key] = filter_['value'] satisfied_filters.append(filter_) return cumulative_filter_dict
def _attr_match(ref_attr, val_attr): """Matche attributes allowing for booleans as strings. We test explicitly for a value that defines it as 'False', which also means that the existence of the attribute with no value implies 'True' """ if type(ref_attr) is bool: return ref_attr == utils.attr_as_boolean(val_attr) else: return ref_attr == val_attr
def exact_filter(model, filter_, cumulative_filter_dict): """Applies an exact filter to a query. :param model: the table model in question :param dict filter_: describes this filter :param dict cumulative_filter_dict: describes the set of exact filters built up so far """ key = filter_['name'] if isinstance(getattr(model, key).property.columns[0].type, sql.types.Boolean): cumulative_filter_dict[key] = ( utils.attr_as_boolean(filter_['value'])) else: cumulative_filter_dict[key] = filter_['value']
def exact_filter(model, query, filter_, satisfied_filters): """Apply an exact filter to a query. :param model: the table model in question :param query: query to apply filters to :param dict filter_: describes this filter :param list satisfied_filters: filter_ will be added if it is satisfied. :returns: query updated to add any exact filters satisfied """ key = filter_['name'] col = getattr(model, key) if isinstance(col.property.columns[0].type, sql.types.Boolean): filter_val = utils.attr_as_boolean(filter_['value']) else: _WontMatch.check(filter_['value'], col) filter_val = filter_['value'] satisfied_filters.append(filter_) return query.filter(col == filter_val)
def exact_filter(model, filter_, cumlative_filter_dict, hints): """Applies an exact filter to a query. :param model: the table model in question :param filter_: the dict that describes this filter :param cumlative_filter_dict: a dict that describes the set of exact filters built up so far :param hints: contains the list of filters yet to be satisfied. Any filters satisfied here will be removed so that the caller will know if any filters remain. :returns cumlative_filter_dict: updated cumulative dict """ key = filter_['name'] if isinstance(getattr(model, key).property.columns[0].type, sql.types.Boolean): filter_dict[key] = utils.attr_as_boolean(filter_['value']) else: filter_dict[key] = filter_['value'] hints.remove(filter_) return filter_dict
def exact_filter(model, filter_, cumulative_filter_dict, hints): """Applies an exact filter to a query. :param model: the table model in question :param filter_: the dict that describes this filter :param cumulative_filter_dict: a dict that describes the set of exact filters built up so far :param hints: contains the list of filters yet to be satisfied. Any filters satisfied here will be removed so that the caller will know if any filters remain. :returns: updated cumulative dict """ key = filter_['name'] if isinstance(getattr(model, key).property.columns[0].type, sql.types.Boolean): cumulative_filter_dict[key] = ( utils.attr_as_boolean(filter_['value'])) else: cumulative_filter_dict[key] = filter_['value'] hints.filters.remove(filter_) return cumulative_filter_dict