diff --git a/app.py b/app.py index e07fc99..1edeee8 100644 --- a/app.py +++ b/app.py @@ -77,14 +77,31 @@ def create_app(config_object="config"): # Battery — edit notes # ------------------------------------------------------------------ # - @app.route("/battery//edit-notes", methods=["POST"]) - def battery_edit_notes(battery_id): + @app.route("/battery//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)) # ------------------------------------------------------------------ # diff --git a/models.py b/models.py index 9b6e334..95110cd 100644 --- a/models.py +++ b/models.py @@ -37,6 +37,15 @@ class Battery(Base): device_id = Column(Integer, ForeignKey("device.id", ondelete="SET NULL"), nullable=True) notes = Column(Text, nullable=True) + # Optional metadata + size = Column(String(20), nullable=True) # AA, AAA, 18650, CR2032 … + chemistry = Column(String(20), nullable=True) # NiMH, Alkaline, Li-ion … + capacity_mah = Column(Integer, nullable=True) # nominal capacity in mAh + tested_capacity_mah = Column(Integer, nullable=True) # last measured capacity in mAh + tested_date = Column(String(10), nullable=True) # YYYY-MM-DD of last test + charge_cycles = Column(Integer, nullable=True) # number of charge cycles + purchase_date = Column(String(10), nullable=True) # YYYY-MM-DD when purchased + device = relationship("Device", back_populates="batteries") def is_available(self): diff --git a/templates/battery_detail.html b/templates/battery_detail.html index 47b2d8f..634c82e 100644 --- a/templates/battery_detail.html +++ b/templates/battery_detail.html @@ -4,6 +4,15 @@ {% block content %}

{{ battery.label }}

+{% macro meta_row(label, value) %} +{% if value %} + + {{ label }} + {{ value }} + +{% endif %} +{% endmacro %} +
@@ -28,17 +37,117 @@ {% endif %} + {{ meta_row("Size", battery.size) }} + {{ meta_row("Chemistry", battery.chemistry) }} + {% if battery.capacity_mah %} + + + + + {% elif battery.tested_capacity_mah %} + + + + + {% endif %} + {{ meta_row("Charge Cycles", battery.charge_cycles) }} + {{ meta_row("Purchase Date", battery.purchase_date) }} + {% if battery.notes %} + + + + + {% endif %}
Capacity + {{ battery.capacity_mah }} mAh + {% if battery.tested_capacity_mah %} + {% set pct = (battery.tested_capacity_mah / battery.capacity_mah * 100)|round|int %} + {% if pct >= 80 %}{% set health_color = "#166534" %} + {% elif pct >= 60 %}{% set health_color = "#92400e" %} + {% else %}{% set health_color = "#991b1b" %} + {% endif %} + → tested {{ battery.tested_capacity_mah }} mAh ({{ pct }}%) + {% if battery.tested_date %}on {{ battery.tested_date }}{% endif %} + {% endif %} +
Tested Capacity + {{ battery.tested_capacity_mah }} mAh + {% if battery.tested_date %}on {{ battery.tested_date }}{% endif %} +
Notes{{ battery.notes }}
- +
-

Notes

-
-
- +

Edit Details

+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
- + +
+ + +
+ +
@@ -67,4 +176,18 @@
← Back to Dashboard + + {% endblock %} diff --git a/templates/dashboard.html b/templates/dashboard.html index 5953047..89b29c0 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -51,6 +51,7 @@ Label Brand + Size Status Assigned To Actions @@ -62,6 +63,7 @@ {{ b.label }} {{ b.brand }} + {{ b.size or '—' }} {{ b.status|capitalize }} @@ -94,7 +96,7 @@ {% else %} - No batteries found. Add some. + No batteries found. Add some. {% endfor %} diff --git a/tests/test_acceptance.py b/tests/test_acceptance.py index cecaeb6..56c201b 100644 --- a/tests/test_acceptance.py +++ b/tests/test_acceptance.py @@ -90,7 +90,7 @@ def test_battery_detail_not_found(client): # ------------------------------------------------------------------ # def test_edit_notes(seeded_client): - seeded_client.post("/battery/1/edit-notes", data={"notes": "test note here"}) + seeded_client.post("/battery/1/edit-details", data={"notes": "test note here"}) resp = seeded_client.get("/battery/1") assert b"test note here" in resp.data