add subdepartment to products grid

This commit is contained in:
Lance Edgar 2012-08-01 07:58:56 -07:00
parent 9a8c647b25
commit 910e6ed970

View file

@ -28,6 +28,8 @@
from webhelpers.html.tags import link_to
from sqlalchemy.orm import joinedload
from edbob.pyramid.filters import filter_ilike
from edbob.pyramid.grids import sorter
from edbob.pyramid.views import GridView
@ -53,7 +55,11 @@ class ProductGrid(GridView):
'brand':
lambda q: q.outerjoin(rattail.Brand),
'department':
lambda q: q.outerjoin(rattail.Department),
lambda q: q.outerjoin(rattail.Department,
rattail.Product.department_uuid == rattail.Department.uuid),
'subdepartment':
lambda q: q.outerjoin(rattail.Subdepartment,
rattail.Product.subdepartment_uuid == rattail.Subdepartment.uuid),
}
def filter_map(self):
@ -61,7 +67,8 @@ class ProductGrid(GridView):
exact=['upc'],
ilike=['description', 'size'],
brand=filter_ilike(rattail.Brand.name),
department=filter_ilike(rattail.Department.name))
department=filter_ilike(rattail.Department.name),
subdepartment=filter_ilike(rattail.Subdepartment.name))
def search_config(self, fmap):
return self.make_search_config(
@ -90,7 +97,15 @@ class ProductGrid(GridView):
return self.make_sort_map(
'upc', 'description', 'size', 'regular_price', 'sale_price',
brand=sorter(rattail.Brand.name),
department=sorter(rattail.Department.name))
department=sorter(rattail.Department.name),
subdepartment=sorter(rattail.Subdepartment.name))
def query(self, config):
q = self.make_query(config)
q = q.options(joinedload(rattail.Product.department))
q = q.options(joinedload(rattail.Product.subdepartment))
q = q.options(joinedload(rattail.Product.brand))
return q
def grid(self, data, config):
g = self.make_grid(data, config)
@ -103,7 +118,8 @@ class ProductGrid(GridView):
g.brand,
g.description,
g.size,
g.department,
# g.department,
g.subdepartment,
g.regular_price.label("Reg Price"),
g.sale_price.label("Sale Price"),
],