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.
- filter_greater_equal(query, value)[source]¶
Filter data with a greater than or equal (
>=
) condition.
- class wuttaweb.grids.filters.BooleanAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a boolean data column.
Subclass of
AlchemyFilter
.- filter_is_false(query, value)[source]¶
Filter data with an “is false” condition. The value is ignored.
- class wuttaweb.grids.filters.DateAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a
sqlalchemy.types.Date
column.Subclass of
AlchemyFilter
.
- class wuttaweb.grids.filters.GridFilter(request, key, label=None, verbs=None, choices={}, 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.
- data_type¶
Simplistic “data type” which the filter supports. So far this will be one of:
'string'
'date'
'choice'
Note that this mainly applies to the “value input” used by the filter. There is no data type for boolean since it does not need a value input; the verb is enough.
- choices¶
OrderedDict of possible values for the filter.
This is safe to read from, but use
set_choices()
to update it.
- 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.
- filter_is_any(data, value)[source]¶
This is a no-op which always ignores the value and returns the data as-is.
- normalize_choices(choices)[source]¶
Normalize a collection of “choices” to standard
OrderedDict
.This is called automatically by
set_choices()
.- Parameters:
choices –
A collection of “choices” in one of the following formats:
enum.Enum
classsimple list, each value of which should be a string, which is assumed to be able to serve as both key and value (ordering of choices will be preserved)
simple dict, keys and values of which will define the choices (note that the final choices will be sorted by key!)
OrderedDict, keys and values of which will define the choices (ordering of choices will be preserved)
- Return type:
- set_choices(choices)[source]¶
Set the value choices for the filter.
If
choices
is non-empty, it is passed tonormalize_choices()
and the result is assigned tochoices
. Also, thedata_type
is set to'choice'
so the UI will present the value input as a dropdown.But if
choices
is empty,choices
is set to an empty dict, anddata_type
is set (back) to'string'
.- Parameters:
choices – Collection of “choices” or
None
.
- class wuttaweb.grids.filters.IntegerAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for an integer data column.
Subclass of
NumericAlchemyFilter
.
- class wuttaweb.grids.filters.NumericAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a numeric data column.
Subclass of
AlchemyFilter
.
- class wuttaweb.grids.filters.StringAlchemyFilter(*args, **kwargs)[source]¶
SQLAlchemy filter option for a text data column.
Subclass of
AlchemyFilter
.