Use ltrim(rtrim())
instead of just trim()
in grid filters
apparently this is needed for older SQL Server compatibility, per https://stackoverflow.com/questions/54340470/trim-is-not-a-recognized-built-in-function-name
This commit is contained in:
parent
91e7001963
commit
98fc82acfd
|
@ -313,7 +313,7 @@ class AlchemyGridFilter(GridFilter):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.column = kwargs.pop('column')
|
||||
super(AlchemyGridFilter, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def filter_equal(self, query, value):
|
||||
"""
|
||||
|
@ -538,17 +538,18 @@ class AlchemyStringFilter(AlchemyGridFilter):
|
|||
return query.filter(sa.or_(*conditions))
|
||||
|
||||
def filter_is_empty(self, query, value):
|
||||
return query.filter(sa.func.trim(self.column) == self.encode_value(''))
|
||||
return query.filter(sa.func.ltrim(sa.func.rtrim(self.column)) == self.encode_value(''))
|
||||
|
||||
def filter_is_not_empty(self, query, value):
|
||||
return query.filter(sa.func.trim(self.column) != self.encode_value(''))
|
||||
return query.filter(sa.func.ltrim(sa.func.rtrim(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(''),
|
||||
sa.func.ltrim(sa.func.rtrim(self.column)) == self.encode_value(''),
|
||||
self.column == None))
|
||||
|
||||
|
||||
class AlchemyEmptyStringFilter(AlchemyStringFilter):
|
||||
"""
|
||||
String filter with special logic to treat empty string values as NULL
|
||||
|
@ -558,13 +559,13 @@ class AlchemyEmptyStringFilter(AlchemyStringFilter):
|
|||
return query.filter(
|
||||
sa.or_(
|
||||
self.column == None,
|
||||
sa.func.trim(self.column) == self.encode_value('')))
|
||||
sa.func.ltrim(sa.func.rtrim(self.column)) == self.encode_value('')))
|
||||
|
||||
def filter_is_not_null(self, query, value):
|
||||
return query.filter(
|
||||
sa.and_(
|
||||
self.column != None,
|
||||
sa.func.trim(self.column) != self.encode_value('')))
|
||||
sa.func.ltrim(sa.func.rtrim(self.column)) != self.encode_value('')))
|
||||
|
||||
|
||||
class AlchemyByteStringFilter(AlchemyStringFilter):
|
||||
|
@ -576,7 +577,7 @@ class AlchemyByteStringFilter(AlchemyStringFilter):
|
|||
value_encoding = 'utf-8'
|
||||
|
||||
def get_value(self, value=UNSPECIFIED):
|
||||
value = super(AlchemyByteStringFilter, self).get_value(value)
|
||||
value = super().get_value(value)
|
||||
if isinstance(value, str):
|
||||
value = value.encode(self.value_encoding)
|
||||
return value
|
||||
|
@ -637,32 +638,32 @@ class AlchemyNumericFilter(AlchemyGridFilter):
|
|||
def filter_equal(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_equal(query, value)
|
||||
return super().filter_equal(query, value)
|
||||
|
||||
def filter_not_equal(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_not_equal(query, value)
|
||||
return super().filter_not_equal(query, value)
|
||||
|
||||
def filter_greater_than(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_greater_than(query, value)
|
||||
return super().filter_greater_than(query, value)
|
||||
|
||||
def filter_greater_equal(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_greater_equal(query, value)
|
||||
return super().filter_greater_equal(query, value)
|
||||
|
||||
def filter_less_than(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_less_than(query, value)
|
||||
return super().filter_less_than(query, value)
|
||||
|
||||
def filter_less_equal(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).filter_less_equal(query, value)
|
||||
return super().filter_less_equal(query, value)
|
||||
|
||||
|
||||
class AlchemyIntegerFilter(AlchemyNumericFilter):
|
||||
|
@ -1193,7 +1194,7 @@ class AlchemyPhoneNumberFilter(AlchemyStringFilter):
|
|||
'ILIKE' query with those parts.
|
||||
"""
|
||||
value = self.parse_value(value)
|
||||
return super(AlchemyPhoneNumberFilter, self).filter_contains(query, value)
|
||||
return super().filter_contains(query, value)
|
||||
|
||||
def filter_does_not_contain(self, query, value):
|
||||
"""
|
||||
|
@ -1201,7 +1202,7 @@ class AlchemyPhoneNumberFilter(AlchemyStringFilter):
|
|||
'NOT ILIKE' query with those parts.
|
||||
"""
|
||||
value = self.parse_value(value)
|
||||
return super(AlchemyPhoneNumberFilter, self).filter_does_not_contain(query, value)
|
||||
return super().filter_does_not_contain(query, value)
|
||||
|
||||
|
||||
class GridFilterSet(OrderedDict):
|
||||
|
@ -1245,7 +1246,7 @@ class GridFiltersForm(forms.Form):
|
|||
node = colander.SchemaNode(colander.String(), name=key)
|
||||
schema.add(node)
|
||||
kwargs['schema'] = schema
|
||||
super(GridFiltersForm, self).__init__(**kwargs)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def iter_filters(self):
|
||||
return self.filters.values()
|
||||
|
|
Loading…
Reference in a new issue