wuttaweb.grids.filters
¶
Grid Filters
- class wuttaweb.grids.filters.AlchemyFilter(*args, **kwargs)[source]¶
Filter option for a grid with SQLAlchemy query data.
This is a subclass of
GridFilter
. It requires amodel_property
to know how to filter the query.- Parameters:
model_property – Property of a model class, representing the column by which to filter. For instance,
model.Person.full_name
.nullable – Boolean indicating whether the filter should include
is_null
andis_not_null
verbs. If not specified, the column will be inspected and use its nullable flag.
- coerce_value(value)[source]¶
Coerce the given value to the correct type/format for use with the filter.
Default logic returns value as-is; subclass may override.
- class wuttaweb.grids.filters.BooleanAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a boolean data column.
Subclass of
AlchemyFilter
.
- class wuttaweb.grids.filters.GridFilter(request, key, label=None, verbs=None, default_active=False, default_verb=None, default_value=None, **kwargs)[source]¶
Filter option for a grid. Represents both the “features” as well as “state” for the filter.
- Parameters:
request – Current request object.
model_property – Property of a model class, representing the column by which to filter. For instance,
model.Person.full_name
.**kwargs – Any additional kwargs will be set as attributes on the filter instance.
Filter instances have the following attributes:
- key¶
Unique key for the filter. This often corresponds to a “column name” for the grid, but not always.
- label¶
Display label for the filter field.
- default_active¶
Boolean indicating whether the filter should be active by default, i.e. when first displaying the grid.
See also
default_verb
anddefault_value
.
- default_verb¶
Filter verb to use by default. This will be auto-selected when the filter is first activated, or when first displaying the grid if
default_active
is true.See also
default_value
.
- default_value¶
Filter value to use by default. This will be auto-populated when the filter is first activated, or when first displaying the grid if
default_active
is true.See also
default_verb
.
- apply_filter(data, verb=None, value=<object object>)[source]¶
Filter the given data set according to a verb/value pair.
If verb and/or value are not specified, will use
verb
and/orvalue
instead.This method does not directly filter the data; rather it delegates (based on
verb
) to some other method. The latter may choose not to filter the data, e.g. ifvalue
is empty, in which case this may return the original data set unchanged.- Returns:
The (possibly) filtered data set.
- class wuttaweb.grids.filters.StringAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a text data column.
Subclass of
AlchemyFilter
.