Add storage location field to bulk add form

This commit is contained in:
2026-04-12 15:31:23 -05:00
parent 70abcfd0ac
commit a806a5b19a
2 changed files with 28 additions and 7 deletions
+14 -7
View File
@@ -59,23 +59,30 @@ def create_app(config_object="config"):
except ValueError:
return None
size = f.get("size", "").strip() or None
chemistry = f.get("chemistry", "").strip() or None
capacity_mah = _int("capacity_mah")
purchase_date = f.get("purchase_date", "").strip() or None
size = f.get("size", "").strip() or None
chemistry = f.get("chemistry", "").strip() or None
capacity_mah = _int("capacity_mah")
purchase_date = f.get("purchase_date", "").strip() or None
storage_location = f.get("storage_location", "").strip() or None
existing = db.query(func.count(Battery.id)).filter_by(brand=brand).scalar()
for i in range(count):
label = f"{brand} {existing + i + 1:03d}"
db.add(Battery(label=label, brand=brand, status="available", notes=notes,
size=size, chemistry=chemistry,
capacity_mah=capacity_mah, purchase_date=purchase_date))
size=size, chemistry=chemistry, capacity_mah=capacity_mah,
purchase_date=purchase_date, storage_location=storage_location))
db.commit()
flash(f"Added {count} {brand} batter{'y' if count == 1 else 'ies'}.", "success")
return redirect(url_for("dashboard"))
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)
storage_locations = [
r[0] for r in db.query(Battery.storage_location)
.filter(Battery.storage_location.isnot(None))
.distinct().order_by(Battery.storage_location).all()
]
return render_template("battery_add.html", form_count=1, brands=brands,
storage_locations=storage_locations)
# ------------------------------------------------------------------ #
# Battery — detail
+14
View File
@@ -68,6 +68,20 @@
</div>
<div class="form-group">
<label>Storage Location</label>
<select id="storage-select" onchange="metaSelectChanged(this,'storage_location')">
<option value="">— none —</option>
{% for loc in storage_locations|default([]) %}
<option value="{{ loc }}">{{ loc }}</option>
{% endfor %}
<option value="__new__"> New location…</option>
</select>
<input type="text" id="storage_location" name="storage_location" value=""
placeholder="e.g. Drawer 2, Toolbox, Shelf A"
style="display:none;margin-top:0.4rem;">
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea id="notes" name="notes"