Put the day's first menu line in Pack lunch notes #4
No files matched your search
@@ -8,6 +8,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
||||
### Added
|
||||
|
||||
- The server prints its version, commit and commit date, then its settings, when it starts (the API key only as set or unset).
|
||||
- A "Pack lunch" event's notes are the day's first menu line, for example "Orange Chicken".
|
||||
|
||||
## [0.0.2] - 2026-11-06
|
||||
|
||||
|
||||
@@ -541,6 +541,7 @@ class PicksIn(BaseModel):
|
||||
|
||||
def set_pick(conn, child, day, picked):
|
||||
"""A pick is a 'Pack lunch' event for that child: picking creates or restores it (same UID), unpicking deletes it.
|
||||
The event's notes are the menu's first line (the main dish), so the calendar shows what's being skipped.
|
||||
Returns False when picking a day with no school lunch (no menu, no school, or no lunch)."""
|
||||
entry = next(iter(lunch_days(conn, child["id"], day, day)), None)
|
||||
if picked and (entry is None or entry["greyed"]):
|
||||
@@ -548,13 +549,16 @@ def set_pick(conn, child, day, picked):
|
||||
existing = db.one(conn, "SELECT e.* FROM event e JOIN event_child ec ON ec.event_id = e.id WHERE ec.child_id = ?"
|
||||
" AND e.kind = 'pack_lunch' AND e.date = ? ORDER BY e.id LIMIT 1", (child["id"], day.isoformat()))
|
||||
status = "confirmed" if picked else "deleted"
|
||||
notes = next((m["items"][0] for m in entry["menus"] if m["items"]), None) if entry else None
|
||||
if existing and existing["status"] != status:
|
||||
conn.execute("UPDATE event SET status = ?, sequence = sequence + 1, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now')"
|
||||
" WHERE id = ?", (status, existing["id"]))
|
||||
# Re-picking refreshes the notes from the menu, in case it was fixed since.
|
||||
conn.execute("UPDATE event SET status = ?, notes = COALESCE(?, notes), sequence = sequence + 1,"
|
||||
" updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') WHERE id = ?", (status, notes if picked else None, existing["id"]))
|
||||
elif not existing and picked:
|
||||
event_id = conn.execute(
|
||||
"INSERT INTO event (uid, source_id, date, all_day, title, kind, status) VALUES (?, ?, ?, 1, ?, 'pack_lunch', 'confirmed')",
|
||||
(scans.new_uid(), entry["menus"][0]["source_id"], day.isoformat(), f"Pack lunch — {child['display_name']}")).lastrowid
|
||||
"INSERT INTO event (uid, source_id, date, all_day, title, notes, kind, status)"
|
||||
" VALUES (?, ?, ?, 1, ?, ?, 'pack_lunch', 'confirmed')",
|
||||
(scans.new_uid(), entry["menus"][0]["source_id"], day.isoformat(), f"Pack lunch — {child['display_name']}", notes)).lastrowid
|
||||
conn.execute("INSERT INTO event_child VALUES (?, ?)", (event_id, child["id"]))
|
||||
return True
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ def test():
|
||||
days = c.post("/api/lunch", json={"child_id": sam, "date": "2026-10-05", "picked": True}).json()
|
||||
assert next(d for d in days if d["date"] == "2026-10-05")["picked"] is True
|
||||
pack = [e for e in c.get("/api/events", params={"calendar_id": cal}).json() if e["kind"] == "pack_lunch"]
|
||||
assert len(pack) == 1 and pack[0]["title"] == "Pack lunch — Sam" and pack[0]["all_day"] is True
|
||||
assert len(pack) == 1 and pack[0]["title"] == "Pack lunch — Sam" and pack[0]["all_day"] is True and pack[0]["notes"] == "Pork Chopette"
|
||||
c.post("/api/lunch", json={"child_id": sam, "date": "2026-10-05", "picked": False})
|
||||
c.post("/api/lunch", json={"child_id": sam, "date": "2026-10-05", "picked": True})
|
||||
pack2 = [e for e in c.get("/api/events", params={"calendar_id": cal}).json() if e["kind"] == "pack_lunch"]
|
||||
|
||||
Reference in new issue
Block a user