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}')
|
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')
|
@app.route('/api/use-last-calibration')
|
||||||
def use_last_calibration():
|
def use_last_calibration():
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
|
|
|
||||||
11
db.py
11
db.py
|
|
@ -172,6 +172,15 @@ class Acquisition:
|
||||||
def get_pretty_date(self) -> str:
|
def get_pretty_date(self) -> str:
|
||||||
return dateutils.format(self.date)
|
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:
|
class FullObject:
|
||||||
def __init__(self, object_id: int, name: str, project: str, acquisitions: list[Acquisition]):
|
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':
|
def create(name: str, project: str, db: sqlite3.Connection) -> 'Object':
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
response = cur.execute(
|
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]
|
[name, project]
|
||||||
)
|
)
|
||||||
object = Object.from_row(response.fetchone())
|
object = Object.from_row(response.fetchone())
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<a id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
<a id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a id="delete-button" class="button is-danger" {% if acquisition %}href="/delete-acquisition/{{ acquisition.id }}"{% endif %}>Supprimer l'acquisition</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -51,6 +52,7 @@
|
||||||
let errorContent = document.getElementById('error-content');
|
let errorContent = document.getElementById('error-content');
|
||||||
let calibrateDiv = document.getElementById('calibrate');
|
let calibrateDiv = document.getElementById('calibrate');
|
||||||
let calibrateButton = document.getElementById('calibrate-button');
|
let calibrateButton = document.getElementById('calibrate-button');
|
||||||
|
let deleteButton = document.getElementById('delete-button');
|
||||||
|
|
||||||
// If we already have calibration images, we show them right now
|
// If we already have calibration images, we show them right now
|
||||||
if (acquisitionId !== null) {
|
if (acquisitionId !== null) {
|
||||||
|
|
@ -97,6 +99,8 @@
|
||||||
if (acquisitionId === null) {
|
if (acquisitionId === null) {
|
||||||
acquisitionId = parseInt(value, 10);
|
acquisitionId = parseInt(value, 10);
|
||||||
calibrateButton.setAttribute('href', '/validate-acquisition/' + acquisitionId);
|
calibrateButton.setAttribute('href', '/validate-acquisition/' + acquisitionId);
|
||||||
|
deleteButton.setAttribute('href', '/delete-acquisition/' + acquisitionId);
|
||||||
|
window.history.pushState('', '', '/scan-acquisition/' + acquisitionId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue