diff options
Diffstat (limited to 'routers/films.py')
| -rw-r--r-- | routers/films.py | 31 |
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, |
