From 3688979b8f3a4fb5685b839196a7cc34a21ef2d2 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 5 Jun 2018 11:08:36 -0500 Subject: [PATCH] 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 --- tailbone/grids/core.py | 2 +- tailbone/grids/filters.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 044d2302..676480b6 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -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 diff --git a/tailbone/grids/filters.py b/tailbone/grids/filters.py index a3431ef6..7d355300 100644 --- a/tailbone/grids/filters.py +++ b/tailbone/grids/filters.py @@ -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.