diff options
author | Frederick Muriuki Muriithi | 2022-06-02 12:57:18 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-06-02 12:57:18 +0300 |
commit | 2f84b2eb1fecab4c381ad2dfd31277717cc9df2d (patch) | |
tree | c8a9080401ba40869454f55c88cd359bdbc393dd /qc_app | |
parent | 219248568252e7291f20105ce589c87c5a85f433 (diff) | |
download | gn-uploader-2f84b2eb1fecab4c381ad2dfd31277717cc9df2d.tar.gz |
Enable user abortion of file parsing
Enable the user to abort the background parsing of the file.
Diffstat (limited to 'qc_app')
-rw-r--r-- | qc_app/parse.py | 17 | ||||
-rw-r--r-- | qc_app/static/css/styles.css | 7 | ||||
-rw-r--r-- | qc_app/templates/job_progress.html | 7 | ||||
-rw-r--r-- | qc_app/templates/parse_results.html | 4 |
4 files changed, 33 insertions, 2 deletions
diff --git a/qc_app/parse.py b/qc_app/parse.py index 1a1b686..b2a0156 100644 --- a/qc_app/parse.py +++ b/qc_app/parse.py @@ -76,7 +76,7 @@ def parse_status(job_id: str): filename = job.get("filename", "uploaded file") errors = jsonpickle.decode( job.get("errors", jsonpickle.encode(tuple()))) - if status == "success": + if status == "success" or status == "aborted": return redirect(url_for("parse.results", job_id=job_id)) if status == "parse-error": @@ -107,7 +107,8 @@ def results(job_id: str): return render_template( "parse_results.html", errors=errors, - job_name = f"Parsing '{filename}'") + job_name = f"Parsing '{filename}'", + user_aborted = job.get("user_aborted")) return render_template("no_such_job.html", job_id=job_id) @@ -129,3 +130,15 @@ def fail(job_id: str): return render_template("parse_failure.html", job=job) return render_template("no_such_job.html", job_id=job_id) + +@parsebp.route("/abort", methods=["POST"]) +def abort(): + job_id = request.form["job_id"] + + with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn: + job = jobs.job(rconn, job_id) + + if job: + rconn.hset(name=job_id, key="user_aborted", value=int(True)) + + return redirect(url_for("parse.parse_status", job_id=job_id)) diff --git a/qc_app/static/css/styles.css b/qc_app/static/css/styles.css index a5f0e01..aa6b049 100644 --- a/qc_app/static/css/styles.css +++ b/qc_app/static/css/styles.css @@ -30,6 +30,13 @@ fieldset { font-weight: bold; } +.btn-danger { + color: #FEFEFE; + border-color: #FF3434; + background-color: #FF4545; + font-weight: bold; +} + .alert { display: block; border-style: solid; diff --git a/qc_app/templates/job_progress.html b/qc_app/templates/job_progress.html index accdc1c..acced9b 100644 --- a/qc_app/templates/job_progress.html +++ b/qc_app/templates/job_progress.html @@ -18,6 +18,13 @@ <span>{{"%.2f" | format(progress)}}%</span> <div> + <form action="{{url_for('parse.abort')}}" method="POST"> + <input type="hidden" name="job_id" value="{{job_id}}" /> + <input type="submit" value="Abort" class="btn btn-danger" /> + </form> +</div> + +<div> {{errors_display(errors, "No errors found so far", "We have found the following errors so far")}} </div> diff --git a/qc_app/templates/parse_results.html b/qc_app/templates/parse_results.html index 8d39359..358c5e8 100644 --- a/qc_app/templates/parse_results.html +++ b/qc_app/templates/parse_results.html @@ -6,6 +6,10 @@ {%block contents%} <h1 class="heading">{{job_name}}: parse results</h2> +{%if user_aborted%} +<span class="alert-warning">Job aborted by the user</span> +{%endif%} + {{errors_display(errors, "No errors found in the file", "We found the following errors")}} {%endblock%} |