From 1f9a27a7aea033257be6edefd742bbec85e9ea17 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 10 Nov 2016 23:13:21 -0600 Subject: [PATCH] Tweak default factory for boolean grid filters --- tailbone/newgrids/alchemy.py | 3 ++- tailbone/newgrids/filters.py | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tailbone/newgrids/alchemy.py b/tailbone/newgrids/alchemy.py index 8c358917..a3d2a9f0 100644 --- a/tailbone/newgrids/alchemy.py +++ b/tailbone/newgrids/alchemy.py @@ -102,7 +102,8 @@ class AlchemyGrid(Grid): elif isinstance(column.type, sa.Integer): factory = filters.AlchemyNumericFilter elif isinstance(column.type, sa.Boolean): - factory = filters.AlchemyBooleanFilter + # TODO: check column for nullable here? + factory = filters.AlchemyNullableBooleanFilter elif isinstance(column.type, sa.Date): factory = filters.AlchemyDateFilter elif isinstance(column.type, sa.DateTime): diff --git a/tailbone/newgrids/filters.py b/tailbone/newgrids/filters.py index 32c3778e..be51c63e 100644 --- a/tailbone/newgrids/filters.py +++ b/tailbone/newgrids/filters.py @@ -336,7 +336,7 @@ class AlchemyBooleanFilter(AlchemyGridFilter): """ Boolean filter for SQLAlchemy. """ - default_verbs = ['is_true', 'is_false', 'is_null', 'is_not_null', 'is_any'] + default_verbs = ['is_true', 'is_false', 'is_any'] def filter_is_true(self, query, value): """ @@ -353,6 +353,13 @@ class AlchemyBooleanFilter(AlchemyGridFilter): return query.filter(self.column == False) +class AlchemyNullableBooleanFilter(AlchemyBooleanFilter): + """ + Boolean filter for SQLAlchemy which is NULL-aware. + """ + default_verbs = ['is_true', 'is_false', 'is_null', 'is_not_null', 'is_any'] + + class AlchemyDateFilter(AlchemyGridFilter): """ Date filter for SQLAlchemy.