Remove all authentication (login, sessions, bcrypt, itsdangerous) since the app runs on a private homelab LAN. Replace with a profile picker landing page and cookie-based profile selection (1-year expiry). - Add Alembic migration to drop password_hash/is_admin columns - Delete auth service, auth routes, login template, and auth tests - Rewrite app/utils/auth.py with NoProfileSelectedError and require_active_profile dependency - Add profile creation flow (GET/POST /profiles/create) - Rewrite home page as profile picker with card layout - Update all route files to use profile dependency instead of admin auth - Remove bcrypt and itsdangerous from requirements - Remove admin_username/admin_password from config - Update all tests for new profile-based access model Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
"""4-week schedule calendar routes.
|
|
|
|
Displays a calendar view showing which workout day maps to which date.
|
|
"""
|
|
|
|
from datetime import date, timedelta
|
|
|
|
import structlog
|
|
from fastapi import APIRouter, Depends, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from sqlmodel import Session
|
|
|
|
from app.database import get_db_session
|
|
from app.models.user import User
|
|
from app.services.exercise_service import ExerciseService
|
|
from app.services.workout_session_service import WorkoutSessionService
|
|
from app.utils.auth import require_active_profile
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
router = APIRouter(prefix="/schedule", tags=["schedule"])
|
|
|
|
|
|
@router.get("", response_class=HTMLResponse)
|
|
async def schedule_view(
|
|
request: Request,
|
|
session: Session = Depends(get_db_session),
|
|
profile: User = Depends(require_active_profile),
|
|
):
|
|
"""Render the 4-week schedule calendar.
|
|
|
|
Shows a 4-week grid where each training day is mapped to a
|
|
calendar date. Days with completed sessions are highlighted.
|
|
"""
|
|
exercise_service = ExerciseService(session)
|
|
workout_days = exercise_service.list_workout_days()
|
|
|
|
# Build 4-week calendar starting from Monday of current week
|
|
today = date.today()
|
|
monday = today - timedelta(days=today.weekday())
|
|
|
|
weeks = []
|
|
completed_dates = set()
|
|
|
|
# Get completed sessions for highlighting
|
|
ws_service = WorkoutSessionService(session)
|
|
sessions_list = ws_service.list_sessions(
|
|
user_id=profile.id, limit=100,
|
|
)
|
|
completed_dates = {ws.date for ws in sessions_list}
|
|
|
|
# 4 workout days per week, 4 weeks
|
|
for week_num in range(4):
|
|
week_start = monday + timedelta(weeks=week_num)
|
|
week_data = {
|
|
"week_number": week_num + 1,
|
|
"days": [],
|
|
}
|
|
for day_offset, workout_day in enumerate(workout_days):
|
|
training_date = week_start + timedelta(days=day_offset)
|
|
is_today = training_date == today
|
|
is_completed = training_date in completed_dates
|
|
|
|
week_data["days"].append({
|
|
"workout_day": workout_day,
|
|
"date": training_date,
|
|
"is_today": is_today,
|
|
"is_completed": is_completed,
|
|
})
|
|
weeks.append(week_data)
|
|
|
|
templates = request.app.state.templates
|
|
return templates.TemplateResponse("pages/schedule.html", {
|
|
"request": request,
|
|
"weeks": weeks,
|
|
"active_profile": profile,
|
|
})
|