From 5f7fd2401e89592ddc64385252a29e81035e0d30 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 26 Oct 2012 10:49:55 -0700 Subject: [PATCH] add type check to product upc search filter --- rattail/pyramid/views/products.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/rattail/pyramid/views/products.py b/rattail/pyramid/views/products.py index 57169801..afaf8659 100644 --- a/rattail/pyramid/views/products.py +++ b/rattail/pyramid/views/products.py @@ -88,9 +88,30 @@ class ProductsGrid(SearchableAlchemyGridView): } def filter_map(self): + + def filter_upc(): + + def filter_is(q, v): + try: + v = int(v) + except ValueError: + return q + else: + return q.filter(field == v) if v else q + + def filter_not(q, v): + try: + v = int(v) + except ValueError: + return q + else: + return q.filter(field != v) if v else q + + return {'is': filter_is, 'nt': filter_not} + return self.make_filter_map( - exact=['upc'], ilike=['description', 'size'], + upc=filter_upc(), brand=self.filter_ilike(rattail.Brand.name), department=self.filter_ilike(rattail.Department.name), subdepartment=self.filter_ilike(rattail.Subdepartment.name),