Optimize the XLSX download for CORE products table
This commit is contained in:
parent
ca1b865c0f
commit
9c0c7cc08c
|
@ -66,6 +66,10 @@ class CoreOfficeMasterView(MasterView):
|
|||
|
||||
return CoreOfficeSession
|
||||
|
||||
def results_xlsx_session(self):
|
||||
from corepos.db.office_op import Session as CoreSession
|
||||
return CoreSession()
|
||||
|
||||
def render_local_date(self, obj, field):
|
||||
value = getattr(obj, field)
|
||||
if not value:
|
||||
|
|
|
@ -143,16 +143,29 @@ class ProductView(CoreOfficeMasterView):
|
|||
|
||||
def get_xlsx_fields(self):
|
||||
fields = super(ProductView, self).get_xlsx_fields()
|
||||
|
||||
# add our extra field
|
||||
fields.append('superdepartment_number')
|
||||
|
||||
# but also, go ahead and cache the superdept mapping, for performance
|
||||
mapping = {}
|
||||
super_departments = self.Session.query(corepos.SuperDepartment).all()
|
||||
for superdept in super_departments:
|
||||
if superdept.child_id in mapping:
|
||||
if superdept.parent_id < mapping[superdept.child_id]:
|
||||
mapping[superdept.child_id] = superdept.parent_id
|
||||
else:
|
||||
mapping[superdept.child_id] = superdept.parent_id
|
||||
self.supermap = mapping
|
||||
|
||||
return fields
|
||||
|
||||
def get_xlsx_row(self, product, fields):
|
||||
row = super(ProductView, self).get_xlsx_row(product, fields)
|
||||
|
||||
row['superdepartment_number'] = None
|
||||
dept = product.department
|
||||
if dept and dept._super_parents:
|
||||
row['superdepartment_number'] = dept._super_parents[0].parent_id
|
||||
if product.department_number in self.supermap:
|
||||
row['superdepartment_number'] = self.supermap[product.department_number]
|
||||
|
||||
return row
|
||||
|
||||
|
|
Loading…
Reference in a new issue