from __future__ import annotations from datetime import datetime from zoneinfo import ZoneInfo from fastapi.templating import Jinja2Templates from app.settings import APP_NAME, ROOT templates = Jinja2Templates(directory=str(ROOT / "app" / "templates")) BERLIN = ZoneInfo("Europe/Berlin") def dt(value: datetime | None, fmt: str = "%d.%m.%Y %H:%M") -> str: if not value: return "–" if value.tzinfo is None: from datetime import timezone value = value.replace(tzinfo=timezone.utc) return value.astimezone(BERLIN).strftime(fmt) templates.env.filters["dt"] = dt templates.env.globals["APP_NAME"] = APP_NAME def _live() -> bool: from app.services import deploy return deploy.live_enabled() templates.env.globals["deploy_live"] = _live def _static_v(name: str) -> str: """Cache-Busting: Änderungszeit der Datei als Query-Parameter, damit Browser nach einem Deploy nie veraltete JS/CSS-Dateien nutzen.""" try: return str(int((ROOT / "app" / "static" / name).stat().st_mtime)) except OSError: return "0" templates.env.globals["static_v"] = _static_v