Add storage location field to bulk add form
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user