Add grid filter which treats empty string as NULL
This commit is contained in:
parent
512405f01f
commit
401cba23b7
|
@ -123,6 +123,9 @@ class Grid(object):
|
|||
def set_sorter(self, key, *args, **kwargs):
|
||||
self.sorters[key] = self.make_sorter(*args, **kwargs)
|
||||
|
||||
def set_filter(self, key, *args, **kwargs):
|
||||
self.filters[key] = self.make_filter(key, *args, **kwargs)
|
||||
|
||||
def set_label(self, key, label):
|
||||
self.labels[key] = label
|
||||
if key in self.filters:
|
||||
|
|
|
@ -334,6 +334,24 @@ class AlchemyStringFilter(AlchemyGridFilter):
|
|||
))
|
||||
|
||||
|
||||
class AlchemyEmptyStringFilter(AlchemyStringFilter):
|
||||
"""
|
||||
String filter with special logic to treat empty string values as NULL
|
||||
"""
|
||||
|
||||
def filter_is_null(self, query, value):
|
||||
return query.filter(
|
||||
sa.or_(
|
||||
self.column == None,
|
||||
sa.func.trim(self.column) == ''))
|
||||
|
||||
def filter_is_not_null(self, query, value):
|
||||
return query.filter(
|
||||
sa.and_(
|
||||
self.column != None,
|
||||
sa.func.trim(self.column) != ''))
|
||||
|
||||
|
||||
class AlchemyByteStringFilter(AlchemyStringFilter):
|
||||
"""
|
||||
String filter for SQLAlchemy, which encodes value as bytestring before
|
||||
|
|
Loading…
Reference in a new issue