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),