From 821a2e129f61dd34784567203f00eaeea19b97c5 Mon Sep 17 00:00:00 2001
From: mirabilos <thorsten.glaser@teckids.org>
Date: Wed, 4 Sep 2019 19:16:57 +0200
Subject: [PATCH] Annotate lesson_periods with whether they have documentation.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Advances #9.

An alternative way of writing…

	foo.filter(a, ~Q(b))

… is…

	foo.filter(a).exclude(b)

… if this way is disturbing to the reader.
---
 biscuit/apps/alsijil/views.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/biscuit/apps/alsijil/views.py b/biscuit/apps/alsijil/views.py
index d429dcfe5..7058e31bc 100644
--- a/biscuit/apps/alsijil/views.py
+++ b/biscuit/apps/alsijil/views.py
@@ -102,7 +102,12 @@ def group_week(request: HttpRequest, week: Optional[int] = None) -> HttpResponse
         raise Http404(_('You must select a group to see the week summary.'))
 
     # Get all lesson periods for the selected group
-    lesson_periods = LessonPeriod.objects.filter(
+    lesson_periods = LessonPeriod.objects.annotate(
+        has_documentation=Exists(LessonDocumentation.objects.filter(
+            lesson_period=OuterRef('pk'),
+            ~Q(topic__exact='')
+        ))
+    ).filter(
         lesson__date_start__lte=week_start,
         lesson__date_end__gte=week_end
     ).select_related(
-- 
GitLab