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)
+7
View File
@@ -50,6 +50,13 @@ def get_today_items(db: Session, user_id: int, target_date: date) -> tuple[list[
return build_items, quit_items
def get_yesterday_missed_items(db: Session, user_id: int) -> list[TodayItem]:
"""어제 예정되어 있었지만 아직 체크하지 않은 습관 목록 (형성+중단 합쳐서, /today 화면의 소급 체크용)."""
yesterday = date.today() - timedelta(days=1)
build_items, quit_items = get_today_items(db, user_id, yesterday)
return [item for item in build_items + quit_items if not item.checked]
def toggle_check(db: Session, habit_id: int, log_date: date) -> bool:
"""체크 상태를 반전시키고 토글 후의 체크 여부를 반환한다.
@@ -24,6 +24,15 @@
</div>
</div>
{% if yesterday_missed %}
<h2>어제 놓친 습관</h2>
<div class="card">
{% for item in yesterday_missed %}
{% include "partials/yesterday_item.html" %}
{% endfor %}
</div>
{% endif %}
<h2>형성 습관</h2>
<div class="card">
{% for item in build_items %}
@@ -0,0 +1,16 @@
<div class="habit-item">
<div class="habit-item-main">
<button
type="button"
class="check-indicator"
hx-post="/today/{{ item.habit_id }}/toggle-yesterday"
hx-target="#today-content"
hx-swap="innerHTML"
aria-label="{{ item.name }} 어제 체크"
></button>
<div>
<div class="habit-item-name">{{ item.name }}</div>
{% if item.condition_text %}<div class="habit-item-condition">{{ item.condition_text }}</div>{% endif %}
</div>
</div>
</div>