Spaces:
Sleeping
Sleeping
| """Resolve which program is the default for scheduling and /api/today.""" | |
| from __future__ import annotations | |
| from sqlmodel import Session, select | |
| from tracker.config import TrackerConfig | |
| from tracker.models import Program | |
| def resolve_active_program(session: Session, config: TrackerConfig) -> Program | None: | |
| """Return the configured active program, or the first program row if unset or invalid. | |
| When ``config.active_program_id`` is set and exists in the DB, use it. Otherwise | |
| fall back to ``select(Program).limit(1)`` for backward compatibility. | |
| """ | |
| if config.active_program_id is not None: | |
| program = session.get(Program, config.active_program_id) | |
| if program is not None: | |
| return program | |
| return session.exec(select(Program).limit(1)).first() | |