summaryrefslogtreecommitdiff
path: root/routers/films.py
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-15 01:50:15 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-15 01:50:15 -0700
commit20c1d02b40bcb9abb5882d0503e596c82e9819bb (patch)
treea2e8918b7f742b23a580daff7f844c576f31c33d /routers/films.py
parent19f2fc05387ed0d7ad5f5fcb2fa92573ece1eae0 (diff)
Refine Lumi stats and detail UX
Diffstat (limited to 'routers/films.py')
-rw-r--r--routers/films.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/routers/films.py b/routers/films.py
index 56f50c5..21feab8 100644
--- a/routers/films.py
+++ b/routers/films.py
@@ -220,6 +220,34 @@ def _group_films_by_month(films: list[Film]) -> list[dict]:
return grouped
+def _shelf_snapshot(films: list[Film], shelf: str) -> list[dict[str, str | int]]:
+ if shelf == "diary":
+ rated = sum(1 for film in films if film.stars)
+ latest_watch = next((film.date_watched for film in films if film.date_watched), None)
+ return [
+ {"label": "Entries", "value": len(films)},
+ {"label": "Rated", "value": rated},
+ {"label": "Latest", "value": latest_watch.isoformat() if latest_watch else "Not set"},
+ ]
+
+ if shelf == "queue":
+ with_posters = sum(1 for film in films if film.poster_url)
+ with_notes = sum(1 for film in films if film.notes)
+ return [
+ {"label": "Queued", "value": len(films)},
+ {"label": "With posters", "value": with_posters},
+ {"label": "With notes", "value": with_notes},
+ ]
+
+ rated = sum(1 for film in films if film.stars)
+ with_notes = sum(1 for film in films if film.notes)
+ return [
+ {"label": "Entries", "value": len(films)},
+ {"label": "Rated", "value": rated},
+ {"label": "With notes", "value": with_notes},
+ ]
+
+
def _render_shelf(
shelf: str,
request: Request,
@@ -228,6 +256,7 @@ def _render_shelf(
):
query = _get_shelf_query(db, shelf)
total_films = query.count()
+ shelf_snapshot = _shelf_snapshot(query.all(), shelf)
films = query.limit(20).all()
has_more = total_films > 20
@@ -245,6 +274,7 @@ def _render_shelf(
"grouped_films": grouped_films,
"active_shelf": shelf,
"shelf_meta": SHELF_META[shelf],
+ "shelf_snapshot": shelf_snapshot,
"total_films": total_films,
"has_more": has_more,
**notices,
@@ -483,6 +513,7 @@ async def film_detail(film_id: int, request: Request, db: Session = Depends(get_
"request": request,
"film": film,
"active_shelf": film.shelf,
+ "shelf_meta": SHELF_META.get(film.shelf, SHELF_META["diary"]),
"tmdb_context": tmdb_context,
"rewatch_history": rewatch_history,
"ratings": ratings,