pyramid_jsonapi.filters module

Classes and methods for handling filter operators.

class pyramid_jsonapi.filters.FilterRegistry[source]

Bases: object

Registry of allowed filter operators.

data

data store for filter op information.

Type

dict

get_filter(column_type, filter_name)[source]

Get dictionary of filter information.

Parameters
  • column_type (class) – type (class object, not name) of a Column.

  • filter_name (str) – name of filter param in URL.

Returns

information dictionary for filter. Type specific entry if it

exists, entry from ‘__ALL__’ if it does not.

Return type

dict

Raises

KeyError – if filter_name is not in the type specific or ALL sections.

register(comparator_name, filter_name=None, value_transform=<function FilterRegistry.<lambda>>, column_type='__ALL__')[source]

Register a new filter operator.

Parameters
  • comparator_name (str) – name of sqlalchemy comparator method.

  • filter_name (str) – name of filter param in URL. Defaults to comparator_name with any occurrences of ‘__’ removed (so ‘__eq__’ defaults to ‘eq’, for example).

  • value_transform (func) – function taking the filter value as the only argument and returning a transformed value. Defaults to a function returning an unmodified value.

  • column_type (class) – type (class object, not name) for which this operator is to be registered. Defaults to ‘__ALL__’ (the string) which makes the operator valid for all column types.

register_standard_filters()[source]

Register standard supported filter operators.

valid_filter_names(column_types=None)[source]

Return set of supported filter operator names.