From 19c941dc9596d2f467beec7ad99e421e512c0c97 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 8 Jul 2023 13:45:31 -0600 Subject: [PATCH] Get printer editing working end to end --- .../python/tentacles/blueprints/admin_ui.py | 7 ++++- .../src/python/tentacles/sql/printers.sql | 30 +++++++++++++++---- .../tentacles/templates/edit_printer.html.j2 | 26 ++++++++++------ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py b/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py index e0068d1..9438d8a 100644 --- a/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py +++ b/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py @@ -108,6 +108,7 @@ def handle_add_printer(): def get_edit_printers(): pid = int(request.args.get("id", "-1")) if row := ctx.db.fetch_printer(pid=pid): + print(row) return render_template("edit_printer.html.j2", printer=row) else: flash("No such printer", category="error") @@ -119,7 +120,11 @@ def get_edit_printers(): def handle_edit_printers(): args = request.form.copy() args["id"] = int(args["id"]) - ctx.db.edit_printer(**request.form) + args["enabled"] = int(args["enabled"]) + args["filament_id"] = int(args["filament_id"]) + args["chassis_id"] = int(args["chassis_id"]) + print(args) + ctx.db.edit_printer(**args) return redirect("/admin") diff --git a/projects/tentacles/src/python/tentacles/sql/printers.sql b/projects/tentacles/src/python/tentacles/sql/printers.sql index 478d63f..f3e6980 100644 --- a/projects/tentacles/src/python/tentacles/sql/printers.sql +++ b/projects/tentacles/src/python/tentacles/sql/printers.sql @@ -65,9 +65,9 @@ CREATE TABLE IF NOT EXISTS filament ( , UNIQUE(name) ); -INSERT OR IGNORE INTO filament (name) VALUES ('pla'); -INSERT OR IGNORE INTO filament (name) VALUES ('abs'); -INSERT OR IGNORE INTO filament (name) VALUES ('petg'); +INSERT OR IGNORE INTO filament (name) VALUES ('PLA'); +INSERT OR IGNORE INTO filament (name) VALUES ('ABS'); +INSERT OR IGNORE INTO filament (name) VALUES ('PETG'); ALTER TABLE printers ADD filament_id INTEGER REFERENCES filament(id) DEFAULT 1; @@ -98,6 +98,9 @@ SELECT , p.stream_url , p.api_key , p.last_poll_date + , p.filament_id + , p.chassis_id + , p.enabled , s.name as status FROM printers p INNER JOIN printer_statuses s ON p.status_id = s.id @@ -151,15 +154,30 @@ WHERE id = :pid ; --- name: edit-printer +-- name: edit-printer! UPDATE printers SET name = :name , url = :url , stream_url = :stream_url , api_key = :api_key - , filament_load = :filament_load - , enabled = (CASE WHEN LOWER(:enabled) = 'true' THEN 1 ELSE 0) + , filament_id = :filament_id + , chassis_id = :chassis_id + , enabled = :enabled WHERE id = :id ; + +-- name: list-chassis +SELECT + id + , name +FROM printer_chassis +; + +-- name: list-filament +SELECT + id + , name + FROM filament + ; diff --git a/projects/tentacles/src/python/tentacles/templates/edit_printer.html.j2 b/projects/tentacles/src/python/tentacles/templates/edit_printer.html.j2 index 0dd1a03..28a748f 100644 --- a/projects/tentacles/src/python/tentacles/templates/edit_printer.html.j2 +++ b/projects/tentacles/src/python/tentacles/templates/edit_printer.html.j2 @@ -28,19 +28,27 @@
-
- - + {% for c in ctx.db.list_chassis() %} + + {% endfor %}
-
+
+ + +
+