diff --git a/.env b/.env index 3502fb9..748a898 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ SPIELE_SESSION_SECRET=48ebf7ddae261a931652b5a55cff708aa21cf4936a8bdeb287eeac7cec4ee3e2 SPIELE_INITIAL_ADMIN_PASSWORD=3fb93f84014ff45406b36ec3 +SPIELE_BGG_TOKEN=6fa6f9f6-32fd-443d-a5c3-ac2527f6a6fc diff --git a/plugins/neuheiten/__init__.py b/plugins/neuheiten/__init__.py index 6c7e8df..14c4f4e 100644 --- a/plugins/neuheiten/__init__.py +++ b/plugins/neuheiten/__init__.py @@ -94,6 +94,7 @@ class NeuheitenPlugin(BasePlugin): user: User = Depends(require_user), q: str = "", status: str = "", + jahr: int | None = None, sort: str = STANDARD_SORTIERUNG[0], richtung: str = STANDARD_SORTIERUNG[1], meldung: str = "", @@ -118,6 +119,26 @@ class NeuheitenPlugin(BasePlugin): ) if status.strip(): abfrage = abfrage.where(Neuheit.status == status.strip()) + # Erscheinungsjahr-Filter: Standard „aktuelles Jahr und neuer“. + jahr_standard = datetime.now(timezone.utc).year + if jahr is None: + jahr_filter = jahr_standard + abfrage = abfrage.where( + or_( + Neuheit.erscheinungsjahr >= jahr_standard, + Neuheit.erscheinungsjahr.is_(None), # ohne Jahr nicht wegfiltern + ) + ) + else: + jahr_filter = jahr + abfrage = abfrage.where(Neuheit.erscheinungsjahr >= jahr) + jahr_optionen = [ + j for j in db.scalars( + select(Neuheit.erscheinungsjahr).distinct().order_by( + Neuheit.erscheinungsjahr.desc() + ) + ) if j is not None + ] gesamt = db.scalar(select(func.count()).select_from(abfrage.subquery())) or 0 eintraege = db.scalars( abfrage.order_by(spalte_sortiert, Neuheit.id.asc()) @@ -138,6 +159,9 @@ class NeuheitenPlugin(BasePlugin): "eintraege": eintraege, "q": q, "status_filter": status, + "jahr_filter": jahr_filter, + "jahr_standard": jahr_standard, + "jahr_optionen": jahr_optionen, "sort": sort if sort in SORTIERBAR else STANDARD_SORTIERUNG[0], "richtung": "ab" if abwaerts else "auf", "status_optionen": status_optionen, diff --git a/plugins/neuheiten/templates/neuheiten/index.html b/plugins/neuheiten/templates/neuheiten/index.html index 749cd52..261e29f 100644 --- a/plugins/neuheiten/templates/neuheiten/index.html +++ b/plugins/neuheiten/templates/neuheiten/index.html @@ -121,7 +121,7 @@
@@ -131,6 +131,13 @@ {% endfor %} + diff --git a/src/redaktionskern/app.py b/src/redaktionskern/app.py index 810d06a..dae878b 100644 --- a/src/redaktionskern/app.py +++ b/src/redaktionskern/app.py @@ -16,6 +16,7 @@ from pathlib import Path from fastapi import FastAPI, Request from fastapi.responses import RedirectResponse +from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from jinja2 import ChoiceLoader, Environment, FileSystemLoader, select_autoescape from sqlalchemy import func, select @@ -109,6 +110,10 @@ def create_app(settings: Settings | None = None) -> FastAPI: redoc_url=None, openapi_url=None, ) + # Statische Kern-Dateien (z. B. „Powered by BGG“-Logo, Pflicht für + # öffentliche BGG-XML-API-Anwendungen). + statisch = Path(__file__).parent / "static" + app.mount("/static", StaticFiles(directory=statisch), name="statisch") app.state.settings = settings app.state.engine = engine app.state.session_factory = session_factory diff --git a/src/redaktionskern/static/powered-by-bgg.png b/src/redaktionskern/static/powered-by-bgg.png new file mode 100644 index 0000000..1aa7e30 Binary files /dev/null and b/src/redaktionskern/static/powered-by-bgg.png differ diff --git a/src/redaktionskern/templates/base.html b/src/redaktionskern/templates/base.html index e2849c3..f806e3a 100644 --- a/src/redaktionskern/templates/base.html +++ b/src/redaktionskern/templates/base.html @@ -73,6 +73,12 @@ diff --git a/tests/test_covers.py b/tests/test_covers.py index 887abf2..1d0e391 100644 --- a/tests/test_covers.py +++ b/tests/test_covers.py @@ -435,7 +435,8 @@ def test_neuheitenliste_rendert_platzhalter_ohne_bild(app, client): melde_an(client) antwort = client.get("/neuheiten") assert antwort.status_code == 200 - assert "")[0] + assert "Alt<" not in antwort.text + + def test_unbekannte_sortierung_faellt_auf_standard_zurueck(client): melde_an(client) antwort = client.get("/neuheiten?sort=hack&richtung=auf")