From 920f0144c2b791b507adf827dcb7d39bcbe396b8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 21 Aug 2015 23:43:19 -0500 Subject: [PATCH] Treat filter by "contains X Y" as "contains X and contains Y". --- tailbone/newgrids/filters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tailbone/newgrids/filters.py b/tailbone/newgrids/filters.py index 3b03ddbc..fa5b71a7 100644 --- a/tailbone/newgrids/filters.py +++ b/tailbone/newgrids/filters.py @@ -287,7 +287,8 @@ class AlchemyStringFilter(AlchemyGridFilter): """ if value is None or value == '': return query - return query.filter(self.column.ilike('%{0}%'.format(value))) + return query.filter(sa.and_( + *[self.column.ilike('%{0}%'.format(v)) for v in value.split()])) def filter_does_not_contain(self, query, value): """ @@ -300,7 +301,8 @@ class AlchemyStringFilter(AlchemyGridFilter): # include things which are nothing at all, in our result set. return query.filter(sa.or_( self.column == None, - ~self.column.ilike('%{0}%'.format(value)), + sa.and_( + *[~self.column.ilike('%{0}%'.format(v)) for v in value.split()]), ))