From 6da53ebaf87b4bec382cdce336783d92b295e3f8 Mon Sep 17 00:00:00 2001 From: Jonas Gaffke Date: Sun, 21 Jan 2024 22:01:04 +0100 Subject: [PATCH] fix overcrowded view see #631 to use itertools.groupby() the iterable needs to be sorted see https://docs.python.org/3/library/itertools.html#itertools.groupby --- pycroft/lib/facilities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pycroft/lib/facilities.py b/pycroft/lib/facilities.py index 8e00fdd1d..866cb6ea8 100644 --- a/pycroft/lib/facilities.py +++ b/pycroft/lib/facilities.py @@ -69,6 +69,7 @@ def get_overcrowded_rooms(building_id: int = None) -> dict[int, list[User]]: ) users = session.session.scalars(stmt).unique().all() + users = sorted(users, key=lambda u: u.room.id) return {k: list(v) for k, v in groupby(users, lambda u: u.room.id)}