From 33ffd7e8551b1ece0e3ed9eedb95fd677b49ac6f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 7 Jan 2023 22:46:35 -0600 Subject: [PATCH] Improve "download rows as XLSX" for importer batch still could be better, but at least this avoids error --- tailbone/views/batch/importer.py | 26 +++++++++++++++++++++++++- tailbone/views/master.py | 16 +++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/tailbone/views/batch/importer.py b/tailbone/views/batch/importer.py index c16c6180..ac690f80 100644 --- a/tailbone/views/batch/importer.py +++ b/tailbone/views/batch/importer.py @@ -286,6 +286,30 @@ class ImporterBatchView(BatchMasterView): delete_query.execute() 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): - ImporterBatchView.defaults(config) + defaults(config) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index dbe4049e..096108a6 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -3850,11 +3850,17 @@ class MasterView(View): """ Return the list of row fields to be written to CSV download. """ - fields = [] - mapper = orm.class_mapper(self.model_row_class) - for prop in mapper.iterate_properties: - if isinstance(prop, orm.ColumnProperty): - fields.append(prop.key) + try: + mapper = orm.class_mapper(self.model_row_class) + except: + fields = self.get_row_form_fields() + 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 def get_csv_row(self, obj, fields):