Improve "download rows as XLSX" for importer batch

still could be better, but at least this avoids error
This commit is contained in:
Lance Edgar 2023-01-07 22:46:35 -06:00
parent b11f9f62b7
commit 33ffd7e855
2 changed files with 36 additions and 6 deletions

View file

@ -286,6 +286,30 @@ class ImporterBatchView(BatchMasterView):
delete_query.execute() delete_query.execute()
return self.redirect(self.get_action_url('view', batch)) return self.redirect(self.get_action_url('view', batch))
def get_row_xlsx_fields(self):
return [
'sequence',
'object_key',
'object_str',
'status',
'status_code',
'status_text',
]
def get_row_xlsx_row(self, row, fields):
xlrow = super(ImporterBatchView, self).get_row_xlsx_row(row, fields)
xlrow['status'] = self.enum.IMPORTER_BATCH_ROW_STATUS[row.status_code]
return xlrow
def defaults(config, **kwargs):
base = globals()
ImporterBatchView = kwargs.get('ImporterBatchView', base['ImporterBatchView'])
ImporterBatchView.defaults(config)
def includeme(config): def includeme(config):
ImporterBatchView.defaults(config) defaults(config)

View file

@ -3850,11 +3850,17 @@ class MasterView(View):
""" """
Return the list of row fields to be written to CSV download. Return the list of row fields to be written to CSV download.
""" """
fields = [] try:
mapper = orm.class_mapper(self.model_row_class) mapper = orm.class_mapper(self.model_row_class)
for prop in mapper.iterate_properties: except:
if isinstance(prop, orm.ColumnProperty): fields = self.get_row_form_fields()
fields.append(prop.key) if not fields:
fields = self.get_row_grid_columns()
else:
fields = []
for prop in mapper.iterate_properties:
if isinstance(prop, orm.ColumnProperty):
fields.append(prop.key)
return fields return fields
def get_csv_row(self, obj, fields): def get_csv_row(self, obj, fields):