Public Access
fix: test-email actually sends; vote page pre-checks existing votes; lowercase MealPlanItemStatus everywhere
- /api/admin/test-email now calls get_email_backend().send() instead of only logging.
- /api/meals/vote/{id} GET now queries MealPlanVote and renders 'already voted' confirmation if found.
- api/meals.py: fix remaining uppercase MealPlanItemStatus enum ref (DENIED, APPROVED, PENDING).
- Fixes the 'all meals show as pending' status regression and the 'Error: Already voted' bug.
This commit is contained in:
@@ -126,7 +126,7 @@ def step_email(run: "WeeklyRun", db: "Session") -> None:
|
||||
# Preload ingredient names for all pending items
|
||||
ing_ids: set = set()
|
||||
for _item in plan.items:
|
||||
if _item.approval_status == MealPlanItemStatus.PENDING and _item.recipe:
|
||||
if _item.approval_status == MealPlanItemStatus.pending and _item.recipe:
|
||||
for _ing in (_item.recipe.ingredients or []):
|
||||
if "ingredient_id" in _ing:
|
||||
ing_ids.add(_ing["ingredient_id"])
|
||||
@@ -141,7 +141,7 @@ def step_email(run: "WeeklyRun", db: "Session") -> None:
|
||||
# Build shopping list preview once (shared across all member emails)
|
||||
all_ingredients: dict[str, tuple[str, str, str, str]] = {}
|
||||
for item in plan.items:
|
||||
if item.approval_status != MealPlanItemStatus.PENDING:
|
||||
if item.approval_status != MealPlanItemStatus.pending:
|
||||
continue
|
||||
for ing in (item.recipe.ingredients or [] if item.recipe else []):
|
||||
ing_name = ingredient_names.get(str(ing.get("ingredient_id", "")), ing.get("name", "unknown")).strip()
|
||||
@@ -193,7 +193,7 @@ def step_email(run: "WeeklyRun", db: "Session") -> None:
|
||||
for member in members:
|
||||
item_html_parts = []
|
||||
for item in plan.items:
|
||||
if item.approval_status != MealPlanItemStatus.PENDING:
|
||||
if item.approval_status != MealPlanItemStatus.pending:
|
||||
continue
|
||||
token = issue_token(item.id, member.id)
|
||||
vote_url = (
|
||||
@@ -317,11 +317,11 @@ def step_deadline(run: "WeeklyRun", db: "Session") -> None:
|
||||
|
||||
resolved = 0
|
||||
for item in plan.items:
|
||||
if item.approval_status == MealPlanItemStatus.PENDING:
|
||||
if item.approval_status == MealPlanItemStatus.pending:
|
||||
item.approval_status = (
|
||||
MealPlanItemStatus.APPROVED
|
||||
MealPlanItemStatus.approved
|
||||
if policy == "approve"
|
||||
else MealPlanItemStatus.DENIED
|
||||
else MealPlanItemStatus.denied
|
||||
)
|
||||
resolved += 1
|
||||
|
||||
@@ -351,7 +351,7 @@ def step_finalize(run: "WeeklyRun", db: "Session") -> None:
|
||||
approved_items = [
|
||||
item
|
||||
for item in (plan.items if plan else [])
|
||||
if item.approval_status == MealPlanItemStatus.APPROVED
|
||||
if item.approval_status == MealPlanItemStatus.approved
|
||||
]
|
||||
|
||||
members = (
|
||||
@@ -482,7 +482,7 @@ def step_reminder(run: "WeeklyRun", db: "Session") -> None:
|
||||
pending_item_ids = [
|
||||
item.id
|
||||
for item in plan.items
|
||||
if item.approval_status == MealPlanItemStatus.PENDING
|
||||
if item.approval_status == MealPlanItemStatus.pending
|
||||
]
|
||||
if not pending_item_ids:
|
||||
run.reminded_at = datetime.now(timezone.utc)
|
||||
@@ -512,7 +512,7 @@ def step_reminder(run: "WeeklyRun", db: "Session") -> None:
|
||||
unvoted = [
|
||||
item
|
||||
for item in plan.items
|
||||
if item.approval_status == MealPlanItemStatus.PENDING
|
||||
if item.approval_status == MealPlanItemStatus.pending
|
||||
and item.id not in voted_ids
|
||||
]
|
||||
if not unvoted:
|
||||
|
||||
@@ -182,7 +182,7 @@ def generate_meal_plan(
|
||||
recipe_id=scored_recipe.recipe_id,
|
||||
day_of_week=index + 1, # Mon=1, Tue=2, Wed=3 by default
|
||||
meal_type=MealType.DINNER,
|
||||
approval_status=MealPlanItemStatus.PENDING,
|
||||
approval_status=MealPlanItemStatus.pending,
|
||||
estimated_cost=scored_recipe.cost.total_cost,
|
||||
)
|
||||
db.add(item)
|
||||
|
||||
Reference in New Issue
Block a user