refactor: failed attempts banner
This commit is contained in:
parent
e00d89f430
commit
cffcb0fa17
2 changed files with 31 additions and 7 deletions
|
|
@ -182,14 +182,34 @@ def queue_submission(doc: Document, action: str, alert: bool = True):
|
|||
)
|
||||
|
||||
|
||||
def format_tb(traceback: str):
|
||||
traceback = traceback.strip().split("\n")[-1]
|
||||
if len(traceback.split()) > 6:
|
||||
return " ".join(traceback.split()[0:6]) + "..."
|
||||
return traceback
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_latest_submissions(doctype, docname):
|
||||
# NOTE: not used creation as orderby intentianlly as we have used update_modified=False everywhere
|
||||
# hence assuming modified will be equal to creation for submission queue documents
|
||||
|
||||
dt = "Submission Queue"
|
||||
out = {}
|
||||
|
||||
filters = {"ref_doctype": doctype, "ref_docname": docname}
|
||||
return {
|
||||
"latest_submission": frappe.db.get_value(dt, filters),
|
||||
"latest_failed_submission": frappe.db.get_value(dt, filters | {"status": "Failed"}),
|
||||
}
|
||||
failed_submission = frappe.db.get_value(
|
||||
dt, filters=filters | {"status": "Failed"}, fieldname=["name", "exception"]
|
||||
)
|
||||
latest_submission = frappe.db.get_value(dt, filters=filters, fieldname=["name", "status"])
|
||||
|
||||
if failed_submission:
|
||||
out["latest_failed_submission"], out["latest_failed_submission_exc_info"] = (
|
||||
failed_submission[0],
|
||||
format_tb(failed_submission[1]),
|
||||
)
|
||||
|
||||
if latest_submission:
|
||||
out["latest_submission"], out["latest_submission_status"] = latest_submission
|
||||
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -2081,18 +2081,22 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
col_width = 3;
|
||||
failed_link = `<div class="col-md-3">
|
||||
<a href='/app/submission-queue/${r.message.latest_failed_submission}'>${__(
|
||||
"Previous Falied Submission"
|
||||
"Previous Failed Submission"
|
||||
)}</a>
|
||||
</div>`;
|
||||
} else {
|
||||
submission_label = __("Previous Falied Submission");
|
||||
if (r.message.latest_failed_submission_exc_info) {
|
||||
submission_label = r.message.latest_failed_submission_exc_info;
|
||||
} else {
|
||||
submission_label = "Errored";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let html = `
|
||||
<div class="row">
|
||||
<div class="col-md-${col_width}">
|
||||
<strong>${__("Submission Status:")}</strong>
|
||||
<strong>${__(`Submission Status: ${r.message.latest_submission_status}`)}</strong>
|
||||
</div>
|
||||
<div class="col-md-${col_width}">
|
||||
<a href='/app/submission-queue/${r.message.latest_submission}'>${submission_label}</a>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue