Add integer-specific grid filter

this was necessary for smarter handling of "invalid" input, e.g. '.645' is not
a good value when querying integer fields
This commit is contained in:
Lance Edgar 2018-06-05 11:08:36 -05:00
parent cac9de3cc7
commit 3688979b8f
2 changed files with 13 additions and 1 deletions

View file

@ -416,7 +416,7 @@ class Grid(object):
elif isinstance(column.type, sa.Numeric):
factory = gridfilters.AlchemyNumericFilter
elif isinstance(column.type, sa.Integer):
factory = gridfilters.AlchemyNumericFilter
factory = gridfilters.AlchemyIntegerFilter
elif isinstance(column.type, sa.Boolean):
# TODO: check column for nullable here?
factory = gridfilters.AlchemyNullableBooleanFilter

View file

@ -460,6 +460,18 @@ class AlchemyNumericFilter(AlchemyGridFilter):
return super(AlchemyNumericFilter, self).filter_less_equal(query, value)
class AlchemyIntegerFilter(AlchemyNumericFilter):
"""
Integer filter for SQLAlchemy.
"""
def value_invalid(self, value):
if value:
if not value.isdigit():
return True
return False
class AlchemyBooleanFilter(AlchemyGridFilter):
"""
Boolean filter for SQLAlchemy.