Refine planner filters and compact selection cards
This commit is contained in:
+22
-1
@@ -1482,7 +1482,12 @@ def fetch_plan_candidates(daypart_id: int, query: str | None = None):
|
||||
""",
|
||||
params,
|
||||
).fetchall()
|
||||
return decorate_items(rows)
|
||||
items = decorate_items(rows)
|
||||
return [
|
||||
item
|
||||
for item in items
|
||||
if item["kind"] != "meal" or meal_matches_daypart(item, daypart_id)
|
||||
]
|
||||
|
||||
|
||||
def fetch_home_food_ids() -> set[int]:
|
||||
@@ -1561,6 +1566,22 @@ def item_matches_daypart(item: dict, daypart_id: int | None) -> bool:
|
||||
return any(int(daypart["id"]) == int(daypart_id) for daypart in dayparts_meta)
|
||||
|
||||
|
||||
def meal_matches_daypart(item: dict, daypart_id: int | None) -> bool:
|
||||
if item.get("kind") != "meal" or daypart_id is None:
|
||||
return True
|
||||
|
||||
dayparts_meta = item.get("dayparts_meta") or []
|
||||
if dayparts_meta:
|
||||
return any(int(daypart["id"]) == int(daypart_id) for daypart in dayparts_meta)
|
||||
|
||||
raw_meal_type = (item.get("meal_type") or "").strip()
|
||||
if not raw_meal_type:
|
||||
return False
|
||||
|
||||
expected_meal_type = meal_type_for_daypart(daypart_id)
|
||||
return normalize_meal_type(raw_meal_type, "snack") == expected_meal_type
|
||||
|
||||
|
||||
def normalized_component_signature(component_ids: list[int]) -> tuple[int, ...]:
|
||||
return tuple(sorted({int(component_id) for component_id in component_ids}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user