diff --git a/tailbone/grids/filters.py b/tailbone/grids/filters.py index 695326fd..e4b522f5 100644 --- a/tailbone/grids/filters.py +++ b/tailbone/grids/filters.py @@ -331,6 +331,38 @@ class AlchemyGridFilter(GridFilter): self.column != self.encode_value(value), )) + def filter_equal_any_of(self, query, value): + """ + This filter expects "multiple values" separated by newline + character, and will add an "OR" condition with each value + being checked separately. For instance if the user submits a + "value" like this: + + .. code-block:: none + + foo bar + baz + + This will result in SQL condition like this: + + .. code-block:: sql + + name = 'foo bar' OR name = 'baz' + """ + if not value: + return query + + values = value.split('\n') + values = [value for value in values if value] + if not values: + return query + + conditions = [] + for value in values: + conditions.append(self.column == self.encode_value(value)) + + return query.filter(sa.or_(*conditions)) + def filter_is_null(self, query, value): """ Filter data with an 'IS NULL' query. Note that this filter does not @@ -430,7 +462,7 @@ class AlchemyStringFilter(AlchemyGridFilter): """ return ['contains', 'does_not_contain', 'contains_any_of', - 'equal', 'not_equal', + 'equal', 'not_equal', 'equal_any_of', 'is_empty', 'is_not_empty', 'is_null', 'is_not_null', 'is_empty_or_null',