Allow delete acquisition
This commit is contained in:
parent
9913c394f3
commit
6671f2ad15
8
app.py
8
app.py
|
|
@ -226,6 +226,14 @@ def validate_acquisition(acquisition_id: int):
|
|||
return redirect(f'/object/{object.id}')
|
||||
|
||||
|
||||
@app.route("/delete-acquisition/<acquisition_id>")
|
||||
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()
|
||||
|
|
|
|||
11
db.py
11
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())
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
{% else %}
|
||||
<a id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
||||
{% endif %}
|
||||
<a id="delete-button" class="button is-danger" {% if acquisition %}href="/delete-acquisition/{{ acquisition.id }}"{% endif %}>Supprimer l'acquisition</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue