fix: tolerante GUI-Filter, sichtbare Bedienelemente, fixierte Navigation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,28 @@ def _latest_projection(session: Session) -> ProjectionResult | None:
|
||||
).scalars().first()
|
||||
|
||||
|
||||
def _opt_int(value: str | None) -> int | None:
|
||||
"""Wandelt einen GUI-Query-Parameter tolerant in int|None um. HTML-Formulare
|
||||
senden bei nicht ausgefüllten Feldern leere Strings statt gar keinen
|
||||
Parameter - das darf nie zu einem 422 fuehren, sondern degradiert zu None."""
|
||||
if value is None or not value.strip():
|
||||
return None
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def _opt_date(value: str | None) -> date | None:
|
||||
"""Wie _opt_int, nur fuer date-Felder (ISO-Format aus <input type=date>)."""
|
||||
if value is None or not value.strip():
|
||||
return None
|
||||
try:
|
||||
return date.fromisoformat(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@router.get("/", dependencies=[Depends(gui_session)])
|
||||
def index(request: Request, session: Session = Depends(get_session)):
|
||||
accounts = session.execute(select(Account)).scalars().all()
|
||||
@@ -77,15 +99,23 @@ def index(request: Request, session: Session = Depends(get_session)):
|
||||
@router.get("/buchungen", dependencies=[Depends(gui_session)])
|
||||
def buchungen(
|
||||
request: Request,
|
||||
account_id: int | None = None,
|
||||
date_from: date | None = None,
|
||||
date_to: date | None = None,
|
||||
category_id: int | None = None,
|
||||
account_id: str | None = None,
|
||||
date_from: str | None = None,
|
||||
date_to: str | None = None,
|
||||
category_id: str | None = None,
|
||||
q: str | None = None,
|
||||
status: str = "confirmed",
|
||||
page: int = 1,
|
||||
session: Session = Depends(get_session),
|
||||
):
|
||||
# HTML-Filterformular sendet leere Strings fuer nicht ausgefuellte Felder -
|
||||
# daher hier bewusst str|None statt int|None/date|None und tolerante
|
||||
# Konvertierung, statt FastAPI vor dem Handler mit 422 abbrechen zu lassen.
|
||||
# Die API-Routen (/api/transactions) bleiben strikt typisiert.
|
||||
account_id = _opt_int(account_id)
|
||||
date_from = _opt_date(date_from)
|
||||
date_to = _opt_date(date_to)
|
||||
category_id = _opt_int(category_id)
|
||||
page = max(1, page)
|
||||
total = count_transactions(
|
||||
account_id=account_id,
|
||||
|
||||
Reference in New Issue
Block a user