Add bulk set field (Storage Location, Brand) to dashboard toolbar

Select batteries, choose field and value from toolbar, hit Apply.
Storage Location dropdown populated from existing locations.
This commit is contained in:
2026-04-12 15:48:46 -05:00
parent a806a5b19a
commit 6384f6b589
2 changed files with 78 additions and 5 deletions
+22 -1
View File
@@ -28,7 +28,13 @@ def create_app(config_object="config"):
@app.route("/")
def dashboard():
batteries = db.query(Battery).order_by(Battery.label).all()
return render_template("dashboard.html", batteries=batteries)
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("dashboard.html", batteries=batteries,
storage_locations=storage_locations)
# ------------------------------------------------------------------ #
# Battery — add
@@ -278,6 +284,21 @@ def create_app(config_object="config"):
b.brand = new_brand
db.commit()
flash(f"Updated brand to '{new_brand}' for {n} batter{'y' if n == 1 else 'ies'}.", "success")
elif action == "set_field":
field_name = request.form.get("field_name", "").strip()
field_value = request.form.get("field_value", "").strip() or None
allowed = {"brand", "storage_location"}
if field_name not in allowed:
flash("Invalid field.", "error")
return redirect(url_for("dashboard"))
if field_name == "brand" and not field_value:
flash("Brand name is required.", "error")
return redirect(url_for("dashboard"))
for b in batteries:
setattr(b, field_name, field_value)
db.commit()
label = field_name.replace("_", " ").title()
flash(f"Set {label} on {n} batter{'y' if n == 1 else 'ies'}.", "success")
else:
flash("Unknown action.", "error")