From 6285a317f885fc830e57a0696cc41f064c999e44 Mon Sep 17 00:00:00 2001
From: Dominik George <nik@naturalnet.de>
Date: Mon, 16 Sep 2019 12:07:43 +0200
Subject: [PATCH] Turn around loop tofetch data only once.

---
 biscuit/apps/alsijil/views.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py
index 95a400cc4..38bc9959e 100644
--- a/biscuit/apps/alsijil/views.py
+++ b/biscuit/apps/alsijil/views.py
@@ -218,11 +218,11 @@ def full_register_group(request: HttpRequest, id_: int) -> HttpResponse:
 
     weeks = CalendarWeek.weeks_within(group.school.current_term.date_start, group.school.current_term.date_end)
     periods_by_day = {}
-    for week in weeks:
-        for day in week:
-            periods_by_day[day] = lesson_periods.filter(
-                period__weekday=day.isoweekday()
-            )
+    for lesson_period in lesson_periods:
+        for week in weeks:
+            day = week[lesson_period.period.weekday - 1]
+            if lesson_period.lesson.date_start <= day and lesson_period.lesson.date_end >= day:
+                periods_by_day.setdefault(day, []).append(lesson_period)
 
     context['group'] = group
     context['weeks'] = weeks
-- 
GitLab