From 9a61f55f76cb808ed7b2652a0cfd93bc215d0df9 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 14 Mar 2020 18:58:06 -0500 Subject: [PATCH] Tweak GPC grid filter, to better handle spaces in user input i.e. when a user copy/pastes a UPC with leading/trailing space --- tailbone/grids/filters.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tailbone/grids/filters.py b/tailbone/grids/filters.py index 3f23196d..b80f6050 100644 --- a/tailbone/grids/filters.py +++ b/tailbone/grids/filters.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -859,8 +859,13 @@ class AlchemyGPCFilter(AlchemyGridFilter): """ Filter data with an equal ('=') query. """ - if value is None or value == '': + if value is None: return query + + value = value.strip() + if not value: + return query + try: return query.filter(self.column.in_(( GPC(value), @@ -870,9 +875,13 @@ class AlchemyGPCFilter(AlchemyGridFilter): def filter_not_equal(self, query, value): """ - Filter data with a not eqaul ('!=') query. + Filter data with a not equal ('!=') query. """ - if value is None or value == '': + if value is None: + return query + + value = value.strip() + if not value: return query # When saying something is 'not equal' to something else, we must also