Make separate method for writing results XLSX file
so subclass can customize
This commit is contained in:
parent
eb76d868ca
commit
2be1d12116
|
@ -2722,6 +2722,29 @@ class MasterView(View):
|
||||||
def results_xlsx_session(self):
|
def results_xlsx_session(self):
|
||||||
return self.make_isolated_session()
|
return self.make_isolated_session()
|
||||||
|
|
||||||
|
def results_write_xlsx(self, path, fields, results, session, progress=None):
|
||||||
|
writer = ExcelWriter(path, fields, sheet_title=self.get_model_title_plural())
|
||||||
|
writer.write_header()
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
def write(obj, i):
|
||||||
|
data = self.get_xlsx_row(obj, fields)
|
||||||
|
row = [data[field] for field in fields]
|
||||||
|
rows.append(row)
|
||||||
|
|
||||||
|
self.progress_loop(write, results, progress,
|
||||||
|
message="Collecting data for Excel")
|
||||||
|
|
||||||
|
def finalize(x, i):
|
||||||
|
writer.write_rows(rows)
|
||||||
|
writer.auto_freeze()
|
||||||
|
writer.auto_filter()
|
||||||
|
writer.auto_resize()
|
||||||
|
writer.save()
|
||||||
|
|
||||||
|
self.progress_loop(finalize, [1], progress,
|
||||||
|
message="Writing Excel file to disk")
|
||||||
|
|
||||||
def results_xlsx_thread(self, results, user_uuid, progress):
|
def results_xlsx_thread(self, results, user_uuid, progress):
|
||||||
"""
|
"""
|
||||||
Thread target, responsible for actually generating the Excel file which
|
Thread target, responsible for actually generating the Excel file which
|
||||||
|
@ -2743,27 +2766,9 @@ class MasterView(View):
|
||||||
|
|
||||||
results = results.with_session(session).all()
|
results = results.with_session(session).all()
|
||||||
fields = self.get_xlsx_fields()
|
fields = self.get_xlsx_fields()
|
||||||
writer = ExcelWriter(path, fields, sheet_title=self.get_model_title_plural())
|
|
||||||
writer.write_header()
|
|
||||||
|
|
||||||
rows = []
|
# write output file
|
||||||
def write(obj, i):
|
self.results_write_xlsx(path, fields, results, session, progress=progress)
|
||||||
data = self.get_xlsx_row(obj, fields)
|
|
||||||
row = [data[field] for field in fields]
|
|
||||||
rows.append(row)
|
|
||||||
|
|
||||||
self.progress_loop(write, results, progress,
|
|
||||||
message="Collecting data for Excel")
|
|
||||||
|
|
||||||
def finalize(x, i):
|
|
||||||
writer.write_rows(rows)
|
|
||||||
writer.auto_freeze()
|
|
||||||
writer.auto_filter()
|
|
||||||
writer.auto_resize()
|
|
||||||
writer.save()
|
|
||||||
|
|
||||||
self.progress_loop(finalize, [1], progress,
|
|
||||||
message="Writing Excel file to disk")
|
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
msg = "generating XLSX file for download failed!"
|
msg = "generating XLSX file for download failed!"
|
||||||
|
|
Loading…
Reference in a new issue