Built-in Filters

class webgrid.filters.TextFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Filter with single freeform text input.

apply(query)[source]

Query modifier to apply the needed clauses for filter inputs.

property comparisons

Handles the dialect-specific job of text comparisons.

In a functional text filter, we want to be case-insensitive. The default behavior of some databases (such as postgresql) is to be case-sensitive for LIKE operations. We work around that for dialects known to have that complexity, and compare upper-case values or use the ILIKE operator.

Some, like mssql, are normally case-insensitive for string comparisons, and we assume that is the case here. Obviously, the database can be set up differently. If it is, that case would need to be handled separately in a custom filter.

get_search_expr()[source]

Filters can be used for the general “single search” function on the grid. For this to work in SQL, the grid needs to pull search expressions from all filters and OR them together.

Return value is expected to be a callable taking one argument (the search value). E.g. lambda value: self.sa_col.like(‘%{}%’.format(value))

Return value of None is filtered out, essentially disabling search for the filter.

class webgrid.filters.IntFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Number filter validating inputs as integers.

validator

alias of IntValidator

class webgrid.filters.AggregateIntFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Number filter validating inputs as integers, for use on aggregate columns.

class webgrid.filters.NumberFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Same as int filter, but will handle real numbers and type everything as a decimal.Decimal object

process(value, is_value2)[source]

Process the values as given to .set(), validating and manipulating as needed.

validator

alias of FloatValidator

class webgrid.filters.AggregateNumberFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Number filter validating inputs as Decimal, for use on aggregate columns.

class webgrid.filters.DateFilter(sa_col, _now=None, default_op=None, default_value1=None, default_value2=None)[source]

Complex date filter.

Depending on the operator, inputs could be one or two freeform, or a select and freeform.

Notable args:

_now (datetime, optional): Useful for testing, supplies a date the filter will use instead of the true datetime.now(). Defaults to None.

apply(query)[source]

Query modifier to apply the needed clauses for filter inputs.

check_arrow_type()[source]

Verify that the expression given to the filter is not ArrowType. If it is, cast it to a date to avoid type problems in the date filter

process(value, is_value2)[source]

Process the values as given to .set(), validating and manipulating as needed.

set(op, value1, value2=None)[source]

Set filter operator and input values.

Stores the raw inputs, then processes the inputs for validation. Applies the default operator if needed.

Args:

op (str): Operator key. value1 (Any): First filter input value. Pass None if the operator takes no input. value2 (Any, optional): Second filter input value. Defaults to None.

Raises:

validators.ValueInvalid: One or more inputs did not validate.

class webgrid.filters.DateTimeFilter(sa_col, _now=None, default_op=None, default_value1=None, default_value2=None)[source]

Complex datetime filter.

Depending on the operator, inputs could be one or two freeform, or a select and freeform.

Notable args:

_now (datetime, optional): Useful for testing, supplies a date the filter will use instead of the true datetime.now(). Defaults to None.

check_arrow_type()[source]

DateTimeFilter has no problems with ArrowType. Pass this case through.

get_search_expr()[source]

Filters can be used for the general “single search” function on the grid. For this to work in SQL, the grid needs to pull search expressions from all filters and OR them together.

Return value is expected to be a callable taking one argument (the search value). E.g. lambda value: self.sa_col.like(‘%{}%’.format(value))

Return value of None is filtered out, essentially disabling search for the filter.

process(value, is_value2)[source]

Process the values as given to .set(), validating and manipulating as needed.

class webgrid.filters.TimeFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Time filter with one or two freeform inputs.

apply(query)[source]

Query modifier to apply the needed clauses for filter inputs.

get_search_expr(date_comparator=None)[source]

Filters can be used for the general “single search” function on the grid. For this to work in SQL, the grid needs to pull search expressions from all filters and OR them together.

Return value is expected to be a callable taking one argument (the search value). E.g. lambda value: self.sa_col.like(‘%{}%’.format(value))

Return value of None is filtered out, essentially disabling search for the filter.

process(value, is_value2)[source]

Process the values as given to .set(), validating and manipulating as needed.

class webgrid.filters.YesNoFilter(sa_col=None, default_op=None, default_value1=None, default_value2=None, dialect=None)[source]

Simple “bool” filter designed for use with the YesNoColumn.

No inputs, just the all/yes/no operators.

apply(query)[source]

Query modifier to apply the needed clauses for filter inputs.

get_search_expr()[source]

Filters can be used for the general “single search” function on the grid. For this to work in SQL, the grid needs to pull search expressions from all filters and OR them together.

Return value is expected to be a callable taking one argument (the search value). E.g. lambda value: self.sa_col.like(‘%{}%’.format(value))

Return value of None is filtered out, essentially disabling search for the filter.

class webgrid.filters.OptionsEnumFilter(sa_col, value_modifier=None, default_op=None, default_value1=None, default_value2=None, enum_type=None)[source]

Options filter that pulls options from a python Enum.

Most filters can be used in column definitions as a class or an instance. With this filter, an instance must be given, so the enum_type can be specified.

Notable args:

enum_type (Enum): Python Enum type to use for options list.

default_modifier(value)[source]

Generic value_modifier that validates an item in the given Enum.

new_instance(**kwargs)[source]

Note: Ensure any overrides of this method accept and pass through kwargs to preserve compatibility in future

options_from()[source]

Override as an instance method here, returns the options tuples from the Enum.

process(value)[source]

Validate value using value_modifier.