From 910e6ed970b145b910f6c12bd0ef55d60ed55627 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 1 Aug 2012 07:58:56 -0700 Subject: [PATCH] add subdepartment to products grid --- rattail/pyramid/views/products.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/rattail/pyramid/views/products.py b/rattail/pyramid/views/products.py index bb41a463..ba07e1c7 100644 --- a/rattail/pyramid/views/products.py +++ b/rattail/pyramid/views/products.py @@ -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"), ],