Tweak default "numeric" grid filter, to ignore UPC-like values
Those tend to cause SQL errors, so just "fail silently" for now. This situation needs to be improved on the front end at some point...
This commit is contained in:
parent
f67fdb8c5b
commit
8f98d61a38
|
@ -366,12 +366,48 @@ class AlchemyNumericFilter(AlchemyGridFilter):
|
|||
"""
|
||||
value_renderer_factory = NumericValueRenderer
|
||||
|
||||
def default_verbs(self):
|
||||
"""
|
||||
Expose greater-than / less-than verbs in addition to core.
|
||||
"""
|
||||
return ['equal', 'not_equal', 'greater_than', 'greater_equal',
|
||||
'less_than', 'less_equal', 'is_null', 'is_not_null']
|
||||
# expose greater-than / less-than verbs in addition to core
|
||||
default_verbs = ['equal', 'not_equal', 'greater_than', 'greater_equal',
|
||||
'less_than', 'less_equal', 'is_null', 'is_not_null']
|
||||
|
||||
# TODO: what follows "works" in that it prevents an error...but from the
|
||||
# user's perspective it still fails silently...need to improve on front-end
|
||||
|
||||
# try to detect (and ignore) common mistake where user enters UPC as search
|
||||
# term for integer field...
|
||||
|
||||
def value_invalid(self, value):
|
||||
return bool(value and len(value) > 8)
|
||||
|
||||
def filter_equal(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).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)
|
||||
|
||||
def filter_greater_than(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).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)
|
||||
|
||||
def filter_less_than(self, query, value):
|
||||
if self.value_invalid(value):
|
||||
return query
|
||||
return super(AlchemyNumericFilter, self).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)
|
||||
|
||||
|
||||
class AlchemyBooleanFilter(AlchemyGridFilter):
|
||||
|
|
Loading…
Reference in a new issue