From f9adb98a78effa73e2b13aaaa59d58dc12fee324 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 8 Jan 2026 12:14:40 -0600 Subject: Delete a job. Activate the UI element allowing the user to delete a chosen job. --- uploader/background_jobs.py | 32 ++++++++ uploader/templates/background-jobs/delete-job.html | 86 ++++++++++++++++++++++ .../templates/background-jobs/job-summary.html | 4 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 uploader/templates/background-jobs/delete-job.html diff --git a/uploader/background_jobs.py b/uploader/background_jobs.py index ad321f3..7206694 100644 --- a/uploader/background_jobs.py +++ b/uploader/background_jobs.py @@ -7,6 +7,8 @@ from typing import Union, Callable, Optional from werkzeug.wrappers.response import Response from flask import ( + flash, + request, redirect, Blueprint, current_app as app) @@ -160,3 +162,33 @@ def job_summary(job_id: uuid.UUID): return redirect(url_for("background-jobs.job_status", job["job_id"])) except JobNotFound as _jnf: return render_template("jobs/job-not-found.html", job_id=job_id) + + +@background_jobs_bp.route("/delete/", methods=["GET", "POST"]) +@require_login +def delete_single(job_id: uuid.UUID): + """Delete a single job.""" + with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn: + try: + job = jobs.job(conn, job_id, fulldetails=True) + status = job["metadata"]["status"] + if status not in ("completed", "error"): + flash("We cannot delete a running job.", "alert alert-error") + # redirect below might be wrong in some cases. Redirect + # appropriately. + return redirect(url_for("background-jobs.list_jobs")) + + if request.method == "GET": + return render_template("background-jobs/delete-job.html", + job=job, + display_datetime=make_datetime_formatter()) + + if request.form["btn-confirm-delete"] == "delete": + jobs.delete_job(conn, job_id) + flash("Job was deleted successfully.", "alert alert-success") + return redirect(url_for("background-jobs.list_jobs")) + flash("Delete cancelled.", "alert alert-info") + return redirect(url_for( + "background-jobs.job_summary", job_id=job_id)) + except JobNotFound as _jnf: + return render_template("jobs/job-not-found.html", job_id=job_id) diff --git a/uploader/templates/background-jobs/delete-job.html b/uploader/templates/background-jobs/delete-job.html new file mode 100644 index 0000000..6dc2144 --- /dev/null +++ b/uploader/templates/background-jobs/delete-job.html @@ -0,0 +1,86 @@ +{%extends "background-jobs/base.html"%} +{%from "flash_messages.html" import flash_all_messages%} + +{%block title%}Background Jobs{%endblock%} + +{%block pagetitle%}Background Jobs{%endblock%} + +{%block breadcrumbs%} +{{super()}} + +{%endblock%} + +{%block contents%} +{{flash_all_messages()}} + +
+

background jobs: delete?

+ +

Are you sure you want to delete the job below?

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Job ID{{job.job_id}}
Type{{job.metadata["job-type"]}}
Created{{display_datetime(job.created)}}
Expires{{display_datetime(job.expires)}}
Status{{job.metadata.status}}
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+{%endblock%} + + +{%block sidebarcontents%} +
+
What is this?
+
+
+

Confirm whether or not you want to delete job + {{job.job_id}}.

+
+{{super()}} +{%endblock%} diff --git a/uploader/templates/background-jobs/job-summary.html b/uploader/templates/background-jobs/job-summary.html index 3020b30..cffa785 100644 --- a/uploader/templates/background-jobs/job-summary.html +++ b/uploader/templates/background-jobs/job-summary.html @@ -57,8 +57,8 @@
- delete
-- cgit 1.4.1