Add basic Excel download support for Products table
This commit is contained in:
parent
79e71ec4ab
commit
5a9fedbb9a
|
@ -78,6 +78,7 @@ class ProductsView(MasterView):
|
|||
model_class = model.Product
|
||||
supports_mobile = True
|
||||
has_versions = True
|
||||
results_downloadable_xlsx = True
|
||||
|
||||
labels = {
|
||||
'upc': "UPC",
|
||||
|
@ -471,6 +472,67 @@ class ProductsView(MasterView):
|
|||
if classes:
|
||||
return ' '.join(classes)
|
||||
|
||||
def get_xlsx_fields(self):
|
||||
fields = super(ProductsView, self).get_xlsx_fields()
|
||||
|
||||
i = fields.index('department_uuid')
|
||||
fields.insert(i + 1, 'department_number')
|
||||
|
||||
i = fields.index('subdepartment_uuid')
|
||||
fields.insert(i + 1, 'subdepartment_number')
|
||||
|
||||
i = fields.index('category_uuid')
|
||||
fields.insert(i + 1, 'category_code')
|
||||
|
||||
i = fields.index('family_uuid')
|
||||
fields.insert(i + 1, 'family_code')
|
||||
|
||||
i = fields.index('report_code_uuid')
|
||||
fields.insert(i + 1, 'report_code')
|
||||
|
||||
i = fields.index('deposit_link_uuid')
|
||||
fields.insert(i + 1, 'deposit_link_code')
|
||||
|
||||
i = fields.index('tax_uuid')
|
||||
fields.insert(i + 1, 'tax_code')
|
||||
|
||||
i = fields.index('brand_uuid')
|
||||
fields.insert(i + 1, 'brand_name')
|
||||
|
||||
return fields
|
||||
|
||||
def get_xlsx_row(self, product, fields):
|
||||
row = super(ProductsView, self).get_xlsx_row(product, fields)
|
||||
|
||||
if 'upc' in fields and isinstance(row['upc'], GPC):
|
||||
row['upc'] = row['upc'].pretty()
|
||||
|
||||
if 'department_number' in fields:
|
||||
row['department_number'] = product.department.number if product.department else None
|
||||
|
||||
if 'subdepartment_number' in fields:
|
||||
row['subdepartment_number'] = product.subdepartment.number if product.subdepartment else None
|
||||
|
||||
if 'category_code' in fields:
|
||||
row['category_code'] = product.category.code if product.category else None
|
||||
|
||||
if 'family_code' in fields:
|
||||
row['family_code'] = product.family.code if product.family else None
|
||||
|
||||
if 'report_code' in fields:
|
||||
row['report_code'] = product.report_code.code if product.report_code else None
|
||||
|
||||
if 'deposit_link_code' in fields:
|
||||
row['deposit_link_code'] = product.deposit_link.code if product.deposit_link else None
|
||||
|
||||
if 'tax_code' in fields:
|
||||
row['tax_code'] = product.tax.code if product.tax else None
|
||||
|
||||
if 'brand_name' in fields:
|
||||
row['brand_name'] = product.brand.name if product.brand else None
|
||||
|
||||
return row
|
||||
|
||||
def get_instance(self):
|
||||
key = self.request.matchdict['uuid']
|
||||
product = Session.query(model.Product).get(key)
|
||||
|
|
Loading…
Reference in a new issue