From 6671f2ad15784b1f2489e05afdb127fcec68b7ad Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 22 Aug 2024 16:04:58 +0200 Subject: [PATCH] Allow delete acquisition --- app.py | 8 ++++++++ db.py | 11 ++++++++++- templates/scan.html | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 6123ed2..9db12b5 100755 --- a/app.py +++ b/app.py @@ -226,6 +226,14 @@ def validate_acquisition(acquisition_id: int): return redirect(f'/object/{object.id}') +@app.route("/delete-acquisition/") +def delete_acquisition(acquisition_id: int): + conn = db.get() + with conn: + acqusition = db.Acquisition.delete_from_id(acquisition_id, conn) + return redirect('/object/' + str(acqusition.object_id)) + + @app.route('/api/use-last-calibration') def use_last_calibration(): conn = db.get() diff --git a/db.py b/db.py index 1ad4a47..5ecaa14 100755 --- a/db.py +++ b/db.py @@ -172,6 +172,15 @@ class Acquisition: def get_pretty_date(self) -> str: return dateutils.format(self.date) + @staticmethod + def delete_from_id(acquisition_id: int, db: sqlite3.Connection) -> 'Acquisition': + cur = db.cursor() + response = cur.execute( + 'DELETE FROM acquisition WHERE id = ? RETURNING ' + Acquisition.select_args() + ';', + [acquisition_id] + ) + return Acquisition.from_row(response.fetchone()) + class FullObject: def __init__(self, object_id: int, name: str, project: str, acquisitions: list[Acquisition]): @@ -214,7 +223,7 @@ class Object: def create(name: str, project: str, db: sqlite3.Connection) -> 'Object': cur = db.cursor() response = cur.execute( - 'INSERT INTO object(name, project) VALUES (?, ?) RETURNING ' + Object.select_args() + ';', + 'INSERT INTO object(name, project) VALUES (?, ?) RETURNING ' + Object.select_args() + ';', [name, project] ) object = Object.from_row(response.fetchone()) diff --git a/templates/scan.html b/templates/scan.html index 9b74e59..6cc9233 100644 --- a/templates/scan.html +++ b/templates/scan.html @@ -33,6 +33,7 @@ {% else %} Valider l'acquisition {% endif %} + Supprimer l'acquisition @@ -51,6 +52,7 @@ let errorContent = document.getElementById('error-content'); let calibrateDiv = document.getElementById('calibrate'); let calibrateButton = document.getElementById('calibrate-button'); + let deleteButton = document.getElementById('delete-button'); // If we already have calibration images, we show them right now if (acquisitionId !== null) { @@ -97,6 +99,8 @@ if (acquisitionId === null) { acquisitionId = parseInt(value, 10); calibrateButton.setAttribute('href', '/validate-acquisition/' + acquisitionId); + deleteButton.setAttribute('href', '/delete-acquisition/' + acquisitionId); + window.history.pushState('', '', '/scan-acquisition/' + acquisitionId); continue; }