diff --git a/app.py b/app.py index 1edeee8..d2f4843 100644 --- a/app.py +++ b/app.py @@ -37,10 +37,11 @@ def create_app(config_object="config"): @app.route("/battery/add", methods=["GET", "POST"]) def battery_add(): if request.method == "POST": - brand = request.form.get("brand", "").strip() - notes = request.form.get("notes", "").strip() or None + f = request.form + brand = f.get("brand", "").strip() + notes = f.get("notes", "").strip() or None try: - count = max(1, min(50, int(request.form.get("count", 1) or 1))) + count = max(1, min(50, int(f.get("count", 1) or 1))) except (ValueError, TypeError): count = 1 @@ -51,10 +52,24 @@ def create_app(config_object="config"): form_brand="", form_count=1, form_notes=notes or "", brands=brands), 400 + def _int(key): + v = f.get(key, "").strip() + try: + return int(v) if v else None + 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 + 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)) + db.add(Battery(label=label, brand=brand, status="available", notes=notes, + size=size, chemistry=chemistry, + capacity_mah=capacity_mah, purchase_date=purchase_date)) db.commit() flash(f"Added {count} {brand} batter{'y' if count == 1 else 'ies'}.", "success") return redirect(url_for("dashboard")) diff --git a/templates/battery_add.html b/templates/battery_add.html index 9c4f117..7ea8f73 100644 --- a/templates/battery_add.html +++ b/templates/battery_add.html @@ -6,29 +6,72 @@
-
- - - -
-
- - - Labels are auto-generated (e.g. Eneloop 001, Eneloop 002) +
+ +
+ + + +
+ +
+ + + Labels are auto-generated (e.g. Eneloop 001, Eneloop 002) +
+ +
+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+
- +
@@ -39,9 +82,9 @@