diff --git a/tailbone/newgrids/filters.py b/tailbone/newgrids/filters.py index d6cf51cd..fa8616b7 100644 --- a/tailbone/newgrids/filters.py +++ b/tailbone/newgrids/filters.py @@ -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):