Allow delete object
This commit is contained in:
parent
6671f2ad15
commit
70383ebb34
8
app.py
8
app.py
|
|
@ -68,6 +68,14 @@ def object(id: int):
|
||||||
return render_template('object.html', object=object)
|
return render_template('object.html', object=object)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/delete-object/<id>')
|
||||||
|
def delete_object(id: int):
|
||||||
|
conn = db.get()
|
||||||
|
with conn:
|
||||||
|
db.Object.delete_from_id(id, conn)
|
||||||
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/scan/<id>')
|
@app.route('/scan/<id>')
|
||||||
def scan(id: int):
|
def scan(id: int):
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
|
|
|
||||||
28
db.py
28
db.py
|
|
@ -182,14 +182,6 @@ class Acquisition:
|
||||||
return Acquisition.from_row(response.fetchone())
|
return Acquisition.from_row(response.fetchone())
|
||||||
|
|
||||||
|
|
||||||
class FullObject:
|
|
||||||
def __init__(self, object_id: int, name: str, project: str, acquisitions: list[Acquisition]):
|
|
||||||
self.id = object_id
|
|
||||||
self.name = name
|
|
||||||
self.project = project
|
|
||||||
self.acquisitions = acquisitions
|
|
||||||
|
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
def __init__(self, name: str, objects: list['Object']):
|
def __init__(self, name: str, objects: list['Object']):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -263,7 +255,16 @@ class Object:
|
||||||
)
|
)
|
||||||
return Acquisition.from_row(response.fetchone())
|
return Acquisition.from_row(response.fetchone())
|
||||||
|
|
||||||
def full(self, db: sqlite3.Connection) -> FullObject:
|
@staticmethod
|
||||||
|
def delete_from_id(object_id: int, db: sqlite3.Connection) -> 'Object':
|
||||||
|
cur = db.cursor()
|
||||||
|
response = cur.execute(
|
||||||
|
'DELETE FROM object WHERE id = ? RETURNING ' + Object.select_args() + ';',
|
||||||
|
[object_id]
|
||||||
|
)
|
||||||
|
return Object.from_row(response.fetchone())
|
||||||
|
|
||||||
|
def full(self, db: sqlite3.Connection) -> 'FullObject':
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
response = cur.execute(
|
response = cur.execute(
|
||||||
'SELECT ' + Acquisition.select_args() + ' FROM acquisition WHERE object_id = ? ORDER BY date DESC;',
|
'SELECT ' + Acquisition.select_args() + ' FROM acquisition WHERE object_id = ? ORDER BY date DESC;',
|
||||||
|
|
@ -273,6 +274,15 @@ class Object:
|
||||||
return FullObject(self.id, self.name, self.project, acquisitions)
|
return FullObject(self.id, self.name, self.project, acquisitions)
|
||||||
|
|
||||||
|
|
||||||
|
class FullObject(Object):
|
||||||
|
def __init__(self, object_id: int, name: str, project: str, acquisitions: list[Acquisition]):
|
||||||
|
super().__init__(object_id, name, project)
|
||||||
|
self.id = object_id
|
||||||
|
self.name = name
|
||||||
|
self.project = project
|
||||||
|
self.acquisitions = acquisitions
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Move current data to backup dir
|
# Move current data to backup dir
|
||||||
if os.path.isdir(config.DATA_DIR):
|
if os.path.isdir(config.DATA_DIR):
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ CREATE TABLE acquisition (
|
||||||
date INTEGER NOT NULL,
|
date INTEGER NOT NULL,
|
||||||
validated INT NOT NULL,
|
validated INT NOT NULL,
|
||||||
CONSTRAINT fk_calibration FOREIGN KEY(calibration_id) REFERENCES calibration(id),
|
CONSTRAINT fk_calibration FOREIGN KEY(calibration_id) REFERENCES calibration(id),
|
||||||
CONSTRAINT fk_object FOREIGN KEY(object_id) REFERENCES object(id)
|
CONSTRAINT fk_object FOREIGN KEY(object_id) REFERENCES object(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE object (
|
CREATE TABLE object (
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@
|
||||||
<button class="modal-close is-large" aria-label="close"></button>
|
<button class="modal-close is-large" aria-label="close"></button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a href="/delete-object/{{ object.id }}" class="button is-danger">Supprimer cet objet</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue