diff --git a/app.py b/app.py index a00c909..e07fc99 100644 --- a/app.py +++ b/app.py @@ -46,8 +46,10 @@ def create_app(config_object="config"): if not brand: flash("Brand is required.", "error") + brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()] return render_template("battery_add.html", - form_brand="", form_count=1, form_notes=notes or ""), 400 + form_brand="", form_count=1, form_notes=notes or "", + brands=brands), 400 existing = db.query(func.count(Battery.id)).filter_by(brand=brand).scalar() for i in range(count): @@ -57,7 +59,8 @@ def create_app(config_object="config"): flash(f"Added {count} {brand} batter{'y' if count == 1 else 'ies'}.", "success") return redirect(url_for("dashboard")) - return render_template("battery_add.html", form_count=1) + brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()] + return render_template("battery_add.html", form_count=1, brands=brands) # ------------------------------------------------------------------ # # Battery — detail @@ -290,7 +293,8 @@ def create_app(config_object="config"): device = db.get(Device, device_id) if device is None: abort(404) - return render_template("device_detail.html", device=device) + brands = [r[0] for r in db.query(Battery.brand).distinct().order_by(Battery.brand).all()] + return render_template("device_detail.html", device=device, brands=brands) # ------------------------------------------------------------------ # # Devices — install batteries diff --git a/templates/battery_add.html b/templates/battery_add.html index 9e4e23f..433422d 100644 --- a/templates/battery_add.html +++ b/templates/battery_add.html @@ -9,7 +9,10 @@
+ placeholder="e.g. Panasonic Eneloop" list="brand-list" required> + + {% for b in brands|default([]) %}
diff --git a/templates/device_detail.html b/templates/device_detail.html index 4e6bd12..83d8a5b 100644 --- a/templates/device_detail.html +++ b/templates/device_detail.html @@ -29,12 +29,16 @@

Install Batteries

{% set free_slots = device.battery_slots - device.installed_count() %}

{{ free_slots }} slot(s) free

+ + {% for b in brands|default([]) %}
Brand Qty {% for _ in range(4) %} - + {% endfor %}