From d804aa9bd6ef75f876ae001f51bb97bc6c65ab2b Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Sat, 31 Aug 2019 22:50:50 +0200
Subject: [PATCH] Add row_attr helper to highlight lessons with subsitutions.
 Advances #19, #12.

---
 biscuit/apps/chronos/tables.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/biscuit/apps/chronos/tables.py b/biscuit/apps/chronos/tables.py
index 7b5968b8..e48e9c4f 100644
--- a/biscuit/apps/chronos/tables.py
+++ b/biscuit/apps/chronos/tables.py
@@ -2,6 +2,14 @@ from django.utils.translation import ugettext_lazy as _
 import django_tables2 as tables
 from django_tables2.utils import A
 
+
+def _css_class_from_lesson_state(record: Optional[LessonPeriod] = None, table: Optional[LessonTable] = None) -> str:
+    if record.get_substitution(table._week):
+        return 'table-warning'
+    else:
+        return ''
+
+
 class LessonsTable(tables.Table):
     class Meta:
         attrs = {'class': 'table table-striped table-bordered table-hover table-responsive-xl'}
@@ -15,3 +23,6 @@ class LessonsTable(tables.Table):
     def __init__(self, week, *args, **kwargs):
         self._week = week
         super().__init__(*args, **kwargs)
+
+    class Meta:
+        row_attrs = {'class': _css_class_from_lesson_state}
-- 
GitLab