add type check to product upc search filter

This commit is contained in:
Lance Edgar 2012-10-26 10:49:55 -07:00
parent ae40b15977
commit 5f7fd2401e

View file

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