3
0
Fork 0

fix: move coerce_value() method to base GridFilter class

this should be standard practice for non-alchemy filters too
This commit is contained in:
Lance Edgar 2026-02-21 13:35:38 -06:00
parent cd1c536555
commit 25c25c06e3

View file

@ -350,6 +350,26 @@ class GridFilter: # pylint: disable=too-many-instance-attributes
return normalized return normalized
def coerce_value(self, value):
"""
Coerce the given value to the correct type/format for use with
the filter. This is where e.g. a boolean or date filter
should convert input string to ``bool`` or ``date`` value.
This is (usually) called from a filter method, when applying
the filter. See also :meth:`apply_filter()`.
Default logic on the base class returns value as-is; subclass
may override as needed.
:param value: Input string provided by the user via the filter
form submission.
:returns: Value of the appropriate type, depending on the
filter subclass.
"""
return value
def apply_filter(self, data, verb=None, value=UNSPECIFIED): def apply_filter(self, data, verb=None, value=UNSPECIFIED):
""" """
Filter the given data set according to a verb/value pair. Filter the given data set according to a verb/value pair.
@ -420,15 +440,6 @@ class AlchemyFilter(GridFilter):
if len(columns) == 1: if len(columns) == 1:
self.nullable = columns[0].nullable self.nullable = columns[0].nullable
def coerce_value(self, value):
"""
Coerce the given value to the correct type/format for use with
the filter.
Default logic returns value as-is; subclass may override.
"""
return value
def filter_equal(self, query, value): def filter_equal(self, query, value):
""" """
Filter data with an equal (``=``) condition. Filter data with an equal (``=``) condition.