Add grid filter type for BigInteger columns

so we can filter by larger values
This commit is contained in:
Lance Edgar 2023-09-01 11:20:30 -05:00
parent 5ab47aeead
commit de373a683b
2 changed files with 14 additions and 3 deletions

View file

@ -689,6 +689,8 @@ class Grid(object):
factory = gridfilters.AlchemyStringFilter factory = gridfilters.AlchemyStringFilter
elif isinstance(column.type, sa.Numeric): elif isinstance(column.type, sa.Numeric):
factory = gridfilters.AlchemyNumericFilter factory = gridfilters.AlchemyNumericFilter
elif isinstance(column.type, sa.BigInteger):
factory = gridfilters.AlchemyBigIntegerFilter
elif isinstance(column.type, sa.Integer): elif isinstance(column.type, sa.Integer):
factory = gridfilters.AlchemyIntegerFilter factory = gridfilters.AlchemyIntegerFilter
elif isinstance(column.type, sa.Boolean): elif isinstance(column.type, sa.Boolean):

View file

@ -659,6 +659,7 @@ class AlchemyIntegerFilter(AlchemyNumericFilter):
""" """
Integer filter for SQLAlchemy. Integer filter for SQLAlchemy.
""" """
bigint = False
def value_invalid(self, value): def value_invalid(self, value):
if value: if value:
@ -666,9 +667,10 @@ class AlchemyIntegerFilter(AlchemyNumericFilter):
return True return True
if not value.isdigit(): if not value.isdigit():
return True return True
# TODO: this one is to avoid DataError from PG, but perhaps that # normal Integer columns have a max value, beyond which PG
# isn't a good enough reason to make this global logic? # will throw an error if we try to query for larger values
if int(value) > 2147483647: # TODO: this seems hacky, how to better handle it?
if not self.bigint and int(value) > 2147483647:
return True return True
return False return False
@ -678,6 +680,13 @@ class AlchemyIntegerFilter(AlchemyNumericFilter):
return int(value) return int(value)
class AlchemyBigIntegerFilter(AlchemyIntegerFilter):
"""
BigInteger filter for SQLAlchemy.
"""
bigint = True
class AlchemyBooleanFilter(AlchemyGridFilter): class AlchemyBooleanFilter(AlchemyGridFilter):
""" """
Boolean filter for SQLAlchemy. Boolean filter for SQLAlchemy.