From 95b02a1ecc921a09794954b27607d76321593ebe Mon Sep 17 00:00:00 2001 From: Shawn Date: Fri, 22 May 2026 19:43:50 -0400 Subject: [PATCH] fix: dynamic VALID_CATEGORIES from DB + populate categories table - server.py: VALID_CATEGORIES now loaded from categories table at startup (was hardcoded to {Furniture, Appliances, Utensils, Equipment, Other}) - categories table now includes: Bev, Snack, GF Bev, GF Food, Snack/bev, Snack/food, Food - Cleared GPS for MID 60006 per user request --- server.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 8b0e768..a88430c 100644 --- a/server.py +++ b/server.py @@ -32,12 +32,23 @@ from typing import Optional, List # ─── Config ───────────────────────────────────────────────────────────────── -VALID_CATEGORIES = {"Furniture", "Appliances", "Utensils & Serveware", "Equipment", "Other"} -VALID_STATUSES = {"active", "maintenance", "retired"} DB_PATH = os.environ.get("CANTEEN_DB_PATH", str(Path(__file__).parent / "assets.db")) UPLOADS_DIR = Path(os.environ.get("CANTEEN_UPLOADS_DIR", str(Path(__file__).parent / "uploads"))) STATIC_DIR = Path(__file__).parent / "static" +def _load_categories() -> set: + """Load valid category names from the categories lookup table.""" + try: + conn = sqlite3.connect(DB_PATH) + names = {r[0] for r in conn.execute("SELECT name FROM categories").fetchall()} + conn.close() + return names if names else {"Other"} + except Exception: + return {"Furniture", "Appliances", "Utensils & Serveware", "Equipment", "Other"} + +VALID_CATEGORIES = _load_categories() +VALID_STATUSES = {"active", "maintenance", "retired"} + # ─── Database ───────────────────────────────────────────────────────────────