Add optional battery metadata fields
New nullable columns on Battery: size, chemistry, capacity_mah, tested_capacity_mah, tested_date, charge_cycles, purchase_date. Battery detail page shows all populated fields and a full edit form with select dropdowns for size and chemistry (with Other fallback). Capacity health % shown in green/orange/red when both nominal and tested capacity are set. Dashboard gains a Size column.
This commit is contained in:
@@ -77,14 +77,31 @@ def create_app(config_object="config"):
|
||||
# Battery — edit notes
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@app.route("/battery/<int:battery_id>/edit-notes", methods=["POST"])
|
||||
def battery_edit_notes(battery_id):
|
||||
@app.route("/battery/<int:battery_id>/edit-details", methods=["POST"])
|
||||
def battery_edit_details(battery_id):
|
||||
battery = db.get(Battery, battery_id)
|
||||
if battery is None:
|
||||
abort(404)
|
||||
battery.notes = request.form.get("notes", "").strip() or None
|
||||
f = request.form
|
||||
|
||||
def _int(key):
|
||||
v = f.get(key, "").strip()
|
||||
try:
|
||||
return int(v) if v else None
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
battery.notes = f.get("notes", "").strip() or None
|
||||
battery.size = f.get("size", "").strip() or None
|
||||
battery.chemistry = f.get("chemistry", "").strip() or None
|
||||
battery.capacity_mah = _int("capacity_mah")
|
||||
battery.tested_capacity_mah = _int("tested_capacity_mah")
|
||||
battery.tested_date = f.get("tested_date", "").strip() or None
|
||||
battery.charge_cycles = _int("charge_cycles")
|
||||
battery.purchase_date = f.get("purchase_date", "").strip() or None
|
||||
|
||||
db.commit()
|
||||
flash("Notes updated.", "success")
|
||||
flash("Details updated.", "success")
|
||||
return redirect(url_for("battery_detail", battery_id=battery_id))
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
Reference in New Issue
Block a user