From 25c25c06e3407250e85a964fca5592d4a6b02739 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 21 Feb 2026 13:35:38 -0600 Subject: [PATCH] fix: move `coerce_value()` method to base `GridFilter` class this should be standard practice for non-alchemy filters too --- src/wuttaweb/grids/filters.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/wuttaweb/grids/filters.py b/src/wuttaweb/grids/filters.py index 54fce1c..f34d848 100644 --- a/src/wuttaweb/grids/filters.py +++ b/src/wuttaweb/grids/filters.py @@ -350,6 +350,26 @@ class GridFilter: # pylint: disable=too-many-instance-attributes 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): """ Filter the given data set according to a verb/value pair. @@ -420,15 +440,6 @@ class AlchemyFilter(GridFilter): if len(columns) == 1: 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): """ Filter data with an equal (``=``) condition.