add retroactive check for yesterday's missed habits on /today

Users often only realize a habit was missed the next day; a same-day-only
check made it impossible to record it after the fact.
This commit is contained in:
2026-07-17 20:15:38 +09:00
parent cee589bb3e
commit d0dd530e26
6 changed files with 111 additions and 0 deletions
+21
View File
@@ -51,6 +51,7 @@ def _today_context(db: Session, user_id: int, **extra) -> dict:
return {
"build_items": build_items,
"quit_items": quit_items,
"yesterday_missed": log_service.get_yesterday_missed_items(db, user_id),
"total_count": len(all_items),
"checked_count": sum(1 for item in all_items if item.checked),
**extra,
@@ -89,6 +90,26 @@ def toggle_today_page(request: Request, habit_id: int, db: Session = Depends(get
)
@router.post("/today/{habit_id}/toggle-yesterday")
def toggle_yesterday_page(request: Request, habit_id: int, db: Session = Depends(get_db)):
current = _current_user_or_redirect(request, db)
if isinstance(current, RedirectResponse):
return current
habit = habit_service.get_habit(db, habit_id, current.id)
if habit is None:
return Response(status_code=404)
yesterday = date.today() - timedelta(days=1)
_, milestone_streak = log_service.toggle_check_and_celebrate(db, habit, yesterday)
extra = {"celebrate_habit_name": habit.name, "celebrate_streak": milestone_streak} if milestone_streak else {}
return templates.TemplateResponse(
request,
"partials/today_content.html",
{"logged_in": True, "current_user": current, **_today_context(db, current.id, **extra)},
)
@router.get("/habits")
def habits_page(request: Request, tab: str = "build", db: Session = Depends(get_db)):
current = _current_user_or_redirect(request, db)