mirror of
https://github.com/kbenestad/ClubLedger.git
synced 2026-06-18 09:44:33 +00:00
Fix on_event deprecation, use lifespan handler
FastAPI 0.93+ deprecates @app.on_event; replaced with @asynccontextmanager lifespan pattern. Also cleaned up unused stdlib imports. https://claude.ai/code/session_01JuRTR5Xjx8emQsyerBgGU7
This commit is contained in:
parent
fa4884bdb4
commit
7af0dd0496
1 changed files with 7 additions and 8 deletions
15
main.py
15
main.py
|
|
@ -4,10 +4,8 @@ Admin configuration: edit the CONFIG dict below.
|
|||
"""
|
||||
|
||||
import sqlite3
|
||||
import hashlib
|
||||
import time
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
from contextlib import contextmanager, asynccontextmanager
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -122,17 +120,18 @@ def format_amount(pence: int) -> str:
|
|||
# FastAPI app
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
app = FastAPI(title=CONFIG["club_name"])
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
init_db()
|
||||
yield
|
||||
|
||||
app = FastAPI(title=CONFIG["club_name"], lifespan=lifespan)
|
||||
|
||||
# Serve static files
|
||||
static_dir = Path(__file__).parent / "static"
|
||||
static_dir.mkdir(exist_ok=True)
|
||||
app.mount("/static", StaticFiles(directory=str(static_dir)), name="static")
|
||||
|
||||
@app.on_event("startup")
|
||||
def on_startup():
|
||||
init_db()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Pydantic models
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue