Show existing relays on relay creation page.
This both shows the relays that we already have assigned and removes existing pins from the list to choose from. It also alphabetizes for easy reading by the human.
This commit is contained in:
parent
0fee05acf7
commit
82c741033d
|
@ -37,10 +37,13 @@ def index(request: Request):
|
||||||
def relay_create_get(request: Request):
|
def relay_create_get(request: Request):
|
||||||
"Get the form to create a new relay."
|
"Get the form to create a new relay."
|
||||||
relays.load_all_pins()
|
relays.load_all_pins()
|
||||||
pins = relays.pins
|
used_pin_names = {relay.pin.name for relay in relays}
|
||||||
|
pins = [p for p in relays.pins if p.name not in used_pin_names]
|
||||||
|
sorted_pins = sorted(pins, key=lambda p: p.name)
|
||||||
return templates.TemplateResponse("relay-create.template.html", {
|
return templates.TemplateResponse("relay-create.template.html", {
|
||||||
|
"relays": relays,
|
||||||
"request": request,
|
"request": request,
|
||||||
"pins": pins,
|
"pins": sorted_pins,
|
||||||
})
|
})
|
||||||
|
|
||||||
@app.post("/relay/create")
|
@app.post("/relay/create")
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
<html>
|
<html>
|
||||||
<h1>Relay Creation</h1>
|
<h1>Relay Creation</h1>
|
||||||
|
<h2>Existing relays</h2>
|
||||||
|
<table>
|
||||||
|
<thead><th>Relay</th><th>Pin</th></thead>
|
||||||
|
<tbody>
|
||||||
|
{% for relay in relays %}
|
||||||
|
<tr><td>{{ relay.name }}</td><td>{{ relay.pin.name }}</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
<form method="POST" action="/relay/create">
|
<form method="POST" action="/relay/create">
|
||||||
<input type="text" name="name" placeholder="Pool Pump 1"></input>
|
<input type="text" name="name" placeholder="Pool Pump 1"></input>
|
||||||
<select name="pin_id">:
|
<select name="pin_id">:
|
||||||
|
|
Loading…
Reference in New Issue