From 7977f840175ff3004e23407f0b7b267947826cee Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Mon, 3 Jun 2019 09:11:12 +0200 Subject: [PATCH] Bug fix --- biscuit/apps/untis/parse.py | 26 +++++++++++++------------- biscuit/apps/untis/sub.py | 7 ++++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/biscuit/apps/untis/parse.py b/biscuit/apps/untis/parse.py index 7df3cb5..31a719a 100755 --- a/biscuit/apps/untis/parse.py +++ b/biscuit/apps/untis/parse.py @@ -172,25 +172,25 @@ def get_lesson_element_by_id_and_teacher(lesson_id, teacher, hour=None, weekday= return None, None el = None i = 0 - # print(lesson.elements) - for i, element in enumerate(lesson.elements): - # print(element.teacher.shortcode) - if element.teacher.id == teacher.id: - el = element - break + + if teacher is not None: + for i, element in enumerate(lesson.elements): + if element.teacher is not None: + if element.teacher.id == teacher.id: + el = element + break + elif len(lesson.elements) > 0: + el = lesson.elements[0] + else: + el = None + t = None - # print(lesson.times) - # print(weekday) - # print(hour) for time in lesson.times: - # print("DAY", time.day, time.hour) if time.day == weekday and time.hour == hour: t = time - # print(t) + room = None if t is not None and len(t.rooms) > i: - # print(t.rooms) - # print(len(t.rooms)) room = t.rooms[i] if el is not None: diff --git a/biscuit/apps/untis/sub.py b/biscuit/apps/untis/sub.py index ef8ba86..56c99be 100644 --- a/biscuit/apps/untis/sub.py +++ b/biscuit/apps/untis/sub.py @@ -65,6 +65,7 @@ class Substitution(object): if db_obj.teacher_idlessn != 0: self.teacher_old = drive["teachers"][db_obj.teacher_idlessn] + # print(self.teacher_new, self.teacher_old, self.lesson_id, self.id) if db_obj.teacher_idsubst != 0: self.teacher_new = drive["teachers"][db_obj.teacher_idsubst] @@ -75,6 +76,8 @@ class Substitution(object): self.teacher_old = self.teacher_new self.teacher_new = None + print(self.teacher_old, self.teacher_new) + self.lesson_element, self.room_old = get_lesson_element_by_id_and_teacher(self.lesson_id, self.teacher_old, self.lesson, self.date.weekday() + 1) # print(self.lesson) @@ -149,7 +152,9 @@ class SubRow(object): def generate_teacher_row(sub, full=False): # print(sub.id) teacher = "" - if sub.type == 1: + if not sub.teacher_old and not sub.teacher_new: + teacher = "" + elif sub.type == 1: teacher = "<s>{}</s>".format(sub.teacher_old.shortcode if not full else sub.teacher_old.name) elif sub.teacher_new and sub.teacher_old: -- GitLab