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 a model_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 and is_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_equal(query, value)[source]

Filter data with an equal (=) condition.

filter_is_not_null(query, value)[source]

Filter data with an IS NOT NULL query. The value is ignored.

filter_is_null(query, value)[source]

Filter data with an IS NULL query. The value is ignored.

filter_not_equal(query, value)[source]

Filter data with a not 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.

filter_is_true(query, value)[source]

Filter data with an “is true” condition. The value is ignored.

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.

active

Boolean indicating whether the filter is currently active.

See also verb and value.

verb

Verb for current filter, if active is true.

See also value.

value

Value for current filter, if active is true.

See also verb.

default_active

Boolean indicating whether the filter should be active by default, i.e. when first displaying the grid.

See also default_verb and default_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/or value 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. if value 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.

get_default_verb()[source]

Returns the default verb for the filter.

get_valueless_verbs()[source]

Returns a list of verb names which do not need a value.

get_verb_labels()[source]

Returns a dict of all defined verb labels.

get_verbs()[source]

Returns the list of verbs supported by the filter.

class wuttaweb.grids.filters.StringAlchemyFilter(*args, **kwargs)[source]

SQLAlchemy filter option for a text data column.

Subclass of AlchemyFilter.

filter_contains(query, value)[source]

Filter data with an ILIKE condition.

filter_does_not_contain(query, value)[source]

Filter data with a NOT ILIKE condition.