Get printer editing working end to end
This commit is contained in:
parent
0fa65cfbe2
commit
c1375cb179
3 changed files with 47 additions and 16 deletions
|
@ -108,6 +108,7 @@ def handle_add_printer():
|
||||||
def get_edit_printers():
|
def get_edit_printers():
|
||||||
pid = int(request.args.get("id", "-1"))
|
pid = int(request.args.get("id", "-1"))
|
||||||
if row := ctx.db.fetch_printer(pid=pid):
|
if row := ctx.db.fetch_printer(pid=pid):
|
||||||
|
print(row)
|
||||||
return render_template("edit_printer.html.j2", printer=row)
|
return render_template("edit_printer.html.j2", printer=row)
|
||||||
else:
|
else:
|
||||||
flash("No such printer", category="error")
|
flash("No such printer", category="error")
|
||||||
|
@ -119,7 +120,11 @@ def get_edit_printers():
|
||||||
def handle_edit_printers():
|
def handle_edit_printers():
|
||||||
args = request.form.copy()
|
args = request.form.copy()
|
||||||
args["id"] = int(args["id"])
|
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")
|
return redirect("/admin")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,9 @@ CREATE TABLE IF NOT EXISTS filament (
|
||||||
, UNIQUE(name)
|
, UNIQUE(name)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT OR IGNORE INTO filament (name) VALUES ('pla');
|
INSERT OR IGNORE INTO filament (name) VALUES ('PLA');
|
||||||
INSERT OR IGNORE INTO filament (name) VALUES ('abs');
|
INSERT OR IGNORE INTO filament (name) VALUES ('ABS');
|
||||||
INSERT OR IGNORE INTO filament (name) VALUES ('petg');
|
INSERT OR IGNORE INTO filament (name) VALUES ('PETG');
|
||||||
|
|
||||||
ALTER TABLE printers ADD filament_id INTEGER REFERENCES filament(id) DEFAULT 1;
|
ALTER TABLE printers ADD filament_id INTEGER REFERENCES filament(id) DEFAULT 1;
|
||||||
|
|
||||||
|
@ -98,6 +98,9 @@ SELECT
|
||||||
, p.stream_url
|
, p.stream_url
|
||||||
, p.api_key
|
, p.api_key
|
||||||
, p.last_poll_date
|
, p.last_poll_date
|
||||||
|
, p.filament_id
|
||||||
|
, p.chassis_id
|
||||||
|
, p.enabled
|
||||||
, s.name as status
|
, s.name as status
|
||||||
FROM printers p
|
FROM printers p
|
||||||
INNER JOIN printer_statuses s ON p.status_id = s.id
|
INNER JOIN printer_statuses s ON p.status_id = s.id
|
||||||
|
@ -151,15 +154,30 @@ WHERE
|
||||||
id = :pid
|
id = :pid
|
||||||
;
|
;
|
||||||
|
|
||||||
-- name: edit-printer
|
-- name: edit-printer!
|
||||||
UPDATE printers
|
UPDATE printers
|
||||||
SET
|
SET
|
||||||
name = :name
|
name = :name
|
||||||
, url = :url
|
, url = :url
|
||||||
, stream_url = :stream_url
|
, stream_url = :stream_url
|
||||||
, api_key = :api_key
|
, api_key = :api_key
|
||||||
, filament_load = :filament_load
|
, filament_id = :filament_id
|
||||||
, enabled = (CASE WHEN LOWER(:enabled) = 'true' THEN 1 ELSE 0)
|
, chassis_id = :chassis_id
|
||||||
|
, enabled = :enabled
|
||||||
WHERE
|
WHERE
|
||||||
id = :id
|
id = :id
|
||||||
;
|
;
|
||||||
|
|
||||||
|
-- name: list-chassis
|
||||||
|
SELECT
|
||||||
|
id
|
||||||
|
, name
|
||||||
|
FROM printer_chassis
|
||||||
|
;
|
||||||
|
|
||||||
|
-- name: list-filament
|
||||||
|
SELECT
|
||||||
|
id
|
||||||
|
, name
|
||||||
|
FROM filament
|
||||||
|
;
|
||||||
|
|
|
@ -28,19 +28,27 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class"row">
|
<div class"row">
|
||||||
<div class="six columns">
|
<div class="four columns">
|
||||||
<label for="filament_load">Filament load</label>
|
<label for="chassis">Chassis</label>
|
||||||
<select name="filament_load">
|
<select name="chassis_id">
|
||||||
<option value="pla" {% if printer.filament_load == "pla"%}selected{%endif%}>PLA</option>
|
{% for c in ctx.db.list_chassis() %}
|
||||||
<option value="petg" {% if printer.filament_load == "petg" %}selected{%endif%}>PETG</option>
|
<option value="{{c.id}}" {% if printer.chassis_id == c.id %}selected{%endif%}>{{c.name}}</option>
|
||||||
<option value="abs" {% if printer.filament_load == "abs" %}selected{%endif%}>ABS</option>
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="six columns">
|
<div class="four columns">
|
||||||
|
<label for="filament">Filament load</label>
|
||||||
|
<select name="filament_id">
|
||||||
|
{% for f in ctx.db.list_filament() %}
|
||||||
|
<option value="{{f.id}}" {% if printer.filament_id == f.id %}selected{%endif%}>{{f.name}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="four columns">
|
||||||
<label for="enabled">Printing enabled</label>
|
<label for="enabled">Printing enabled</label>
|
||||||
<select name="enabled">
|
<select name="enabled">
|
||||||
<option value="true" {% if printer.enabled %}selected{%endif%}>Enabled</option>
|
<option value="1" {% if printer.enabled %}selected{%endif%}>Enabled</option>
|
||||||
<option value="false" {% if not printer.enabled %}selected{%endif%}>Disabled</option>
|
<option value="0" {% if not printer.enabled %}selected{%endif%}>Disabled</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue