From 700813fa57495973d59c0c85bf1100c29380d5b0 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 9 Oct 2019 10:55:13 -0500 Subject: [PATCH] Add "is false or null" verb for boolean grid filters --- tailbone/grids/filters.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tailbone/grids/filters.py b/tailbone/grids/filters.py index e136aa21..3f23196d 100644 --- a/tailbone/grids/filters.py +++ b/tailbone/grids/filters.py @@ -138,6 +138,7 @@ class GridFilter(object): 'is_not_null': "is not null", 'is_true': "is true", 'is_false': "is false", + 'is_false_null': "is false or null", 'contains': "contains", 'does_not_contain': "does not contain", 'is_me': "is me", @@ -145,7 +146,7 @@ class GridFilter(object): } valueless_verbs = ['is_any', 'is_null', 'is_not_null', 'is_true', 'is_false', - 'is_me', 'is_not_me'] + 'is_false_null', 'is_me', 'is_not_me'] value_renderer_factory = DefaultValueRenderer data_type = 'string' # default, but will be set from value renderer @@ -548,7 +549,16 @@ class AlchemyNullableBooleanFilter(AlchemyBooleanFilter): """ Boolean filter for SQLAlchemy which is NULL-aware. """ - default_verbs = ['is_true', 'is_false', 'is_null', 'is_not_null', 'is_any'] + default_verbs = ['is_true', 'is_false', 'is_false_null', + 'is_null', 'is_not_null', 'is_any'] + + def filter_is_false_null(self, query, value): + """ + Filter data with an "is false or null" query. Note that this filter + does not use the value for anything. + """ + return query.filter(sa.or_(self.column == False, + self.column == None)) class AlchemyDateFilter(AlchemyGridFilter):