From 13d6472d9ac5cd0d522becb6467345776980cd38 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Fri, 23 Aug 2019 18:42:26 +0200
Subject: [PATCH] Make filters incremental.

---
 biscuit/apps/chronos/views.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py
index c458fa56..d7c22fcc 100644
--- a/biscuit/apps/chronos/views.py
+++ b/biscuit/apps/chronos/views.py
@@ -20,18 +20,21 @@ from .util import current_week
 def timetable(request: HttpRequest) -> HttpResponse:
     context = {}
 
-    lesson_periods = LessonPeriod.objects.all()
+    if request.GET:
+        lesson_periods = LessonPeriod.objects.all()
 
-    if 'group' in request.GET:
-        lesson_periods = lesson_periods.filter(
-            lesson__groups__pk=int(request.GET['group']))
-    elif 'teacher' in request.GET:
-        lesson_periods = lesson_periods.filter(
-            lesson__teachers__pk=int(request.GET['teacher']))
-    elif 'room' in request.GET:
-        lesson_periods = lesson_periods.filter(
-            room__pk=int(request.GET['room']))
+        # Incrementally filter lesson periods by GET parameters
+        if 'group' in request.GET:
+            lesson_periods = lesson_periods.filter(
+                lesson__groups__pk=int(request.GET['group']))
+        if 'teacher' in request.GET:
+            lesson_periods = lesson_periods.filter(
+                lesson__teachers__pk=int(request.GET['teacher']))
+        if 'room' in request.GET:
+            lesson_periods = lesson_periods.filter(
+                room__pk=int(request.GET['room']))
     else:
+        # Redirect to a selected view if no filter provided
         if request.user.person:
             if request.user.person.primary_group:
                 return redirect(reverse('timetable') + '?group=%d' % request.user.person.primary_group.pk)
-- 
GitLab