Add "is empty" and related verbs, for "string" type grid filters

This commit is contained in:
Lance Edgar 2020-12-04 15:26:21 -06:00
parent 2ad0223e9a
commit 0220e401cd

View file

@ -134,19 +134,33 @@ class GridFilter(object):
'greater_equal': "greater than or equal to",
'less_than': "less than",
'less_equal': "less than or equal to",
'is_empty': "is empty",
'is_not_empty': "is not empty",
'is_null': "is null",
'is_not_null': "is not null",
'is_true': "is true",
'is_false': "is false",
'is_false_null': "is false or null",
'is_empty_or_null': "is either empty or null",
'contains': "contains",
'does_not_contain': "does not contain",
'is_me': "is me",
'is_not_me': "is not me",
}
valueless_verbs = ['is_any', 'is_null', 'is_not_null', 'is_true', 'is_false',
'is_false_null', 'is_me', 'is_not_me']
valueless_verbs = [
'is_any',
'is_empty',
'is_not_empty',
'is_null',
'is_not_null',
'is_true',
'is_false',
'is_false_null',
'is_empty_or_null',
'is_me',
'is_not_me',
]
value_renderer_factory = DefaultValueRenderer
data_type = 'string' # default, but will be set from value renderer
@ -380,7 +394,11 @@ class AlchemyStringFilter(AlchemyGridFilter):
Expose contains / does-not-contain verbs in addition to core.
"""
return ['contains', 'does_not_contain',
'equal', 'not_equal', 'is_null', 'is_not_null', 'is_any']
'equal', 'not_equal',
'is_empty', 'is_not_empty',
'is_null', 'is_not_null',
'is_empty_or_null',
'is_any']
def filter_contains(self, query, value):
"""
@ -408,6 +426,17 @@ class AlchemyStringFilter(AlchemyGridFilter):
for v in value.split()]),
))
def filter_is_empty(self, query, value):
return query.filter(sa.func.trim(self.column) == self.encode_value(''))
def filter_is_not_empty(self, query, value):
return query.filter(sa.func.trim(self.column) != self.encode_value(''))
def filter_is_empty_or_null(self, query, value):
return query.filter(
sa.or_(
sa.func.trim(self.column) == self.encode_value(''),
self.column == None))
class AlchemyEmptyStringFilter(AlchemyStringFilter):
"""