Add generate excel fault tolerance with compare

This commit is contained in:
2023-05-29 20:07:00 +02:00
parent 2df055334c
commit 007c419979
2 changed files with 33 additions and 13 deletions

View File

@@ -85,17 +85,33 @@ def excel():
else:
selected_files = request.form["selected-files"]
book = None
for file_name in selected_files:
file_name_result = os.path.join(Folders.results, file_name)
if book is None:
file_excel = os.path.join(Folders.excel, Files.be_list_excel)
book = xlsxwriter.Workbook(file_excel, {"nan_inf_to_errors": True})
excel = Excel(
file_name=file_name_result,
book=book,
compare=app.config[COMPARE],
try:
for file_name in selected_files:
file_name_result = os.path.join(Folders.results, file_name)
if book is None:
file_excel = os.path.join(Folders.excel, Files.be_list_excel)
book = xlsxwriter.Workbook(
file_excel, {"nan_inf_to_errors": True}
)
excel = Excel(
file_name=file_name_result,
book=book,
compare=app.config[COMPARE],
)
excel.report()
except Exception as e:
if book is not None:
book.close()
return (
json.dumps(
{
"success": False,
"error": "Could not create excel file, " + str(e),
}
),
200,
{"ContentType": "application/json"},
)
excel.report()
if book is not None:
book.close()
Files.open(file_excel, test=app.config[TEST])

View File

@@ -51,11 +51,15 @@ function excel() {
contentType: "application/json",
dataType: 'json',
success: function(data){
alert("Se ha generado el archivo "+data.file);
if (data.success) {
alert("Se ha generado el archivo "+data.file);
} else {
alert(data.error);
}
},
error: function (xhr, ajaxOptions, thrownError) {
var mensaje = JSON.parse(xhr.responseText || '{\"mensaje\": \"Error indeterminado\"}');
alert(mensaje.mensaje);
var mensaje = JSON.parse(xhr.responseText || '{\"message\": \"Error indeterminado\"}');
alert(mensaje.message);
}
});
}