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
This commit is contained in:
@@ -32,12 +32,23 @@ from typing import Optional, List
|
|||||||
|
|
||||||
# ─── Config ─────────────────────────────────────────────────────────────────
|
# ─── 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"))
|
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")))
|
UPLOADS_DIR = Path(os.environ.get("CANTEEN_UPLOADS_DIR", str(Path(__file__).parent / "uploads")))
|
||||||
STATIC_DIR = Path(__file__).parent / "static"
|
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 ───────────────────────────────────────────────────────────────
|
# ─── Database ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user