From 9bd7cbd6b451c193972c18d6548513fd0c9e0fa6 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Sun, 1 Sep 2019 21:02:27 +0200
Subject: [PATCH] Use ORM annotation to transfer week to table.

Hacka-di-hack!
---
 biscuit/apps/chronos/tables.py | 6 +-----
 biscuit/apps/chronos/views.py  | 4 ++--
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/biscuit/apps/chronos/tables.py b/biscuit/apps/chronos/tables.py
index 38625021..e7f53f84 100644
--- a/biscuit/apps/chronos/tables.py
+++ b/biscuit/apps/chronos/tables.py
@@ -26,8 +26,4 @@ class LessonsTable(tables.Table):
     lesson__teachers = tables.Column(accessor='lesson.teacher_names', verbose_name=_('Teachers'))
     lesson__subject = tables.Column(accessor='lesson.subject')
     room = tables.Column(accessor='room')
-    edit_substitution = tables.LinkColumn('edit_substitution_by_id', args=[A('id')], text=_('Substitution'))
-
-    def __init__(self, week, *args, **kwargs):
-        self.edit_substitution.args.append(week)
-        super().__init__(*args, **kwargs)
+    edit_substitution = tables.LinkColumn('edit_substitution_by_id', args=[A('id'), A('week')], text=_('Substitution'))
diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py
index bbb56809..455d06d2 100644
--- a/biscuit/apps/chronos/views.py
+++ b/biscuit/apps/chronos/views.py
@@ -99,10 +99,10 @@ def lessons_day(request: HttpRequest, when: Optional[str] = None) -> HttpRespons
     lesson_periods = LessonPeriod.objects.filter(
         lesson__date_start__lte=day, lesson__date_end__gte=day,
         period__weekday=weekday
-    ).all()
+    ).annotate(_week=week).all()
 
     # Build table
-    lessons_table = LessonsTable(week, lesson_periods)
+    lessons_table = LessonsTable(lesson_periods)
     RequestConfig(request).configure(lessons_table)
 
     context['lessons_table'] = lessons_table
-- 
GitLab