diff --git a/schoolapps/timetable/templates/timetable/substitution.html b/schoolapps/timetable/templates/timetable/substitution.html index c89bb6ecfc66748ce69eb38c915b0db607f83290..053c55a0258150f4c030b61ea2fcfdf59049bc04 100755 --- a/schoolapps/timetable/templates/timetable/substitution.html +++ b/schoolapps/timetable/templates/timetable/substitution.html @@ -26,8 +26,8 @@ <table class="substitutions striped"> <thead> <tr> + <th><i class="material-icons">people</i></th> <th><i class="material-icons">access_time</i></th> - <th>Klassen</th> <th>Lehrer</th> <th>Fach</th> <th>Raum</th> @@ -37,7 +37,7 @@ </thead> <tbody> {% for sub in sub_table %} - <tr class="{{ sub.css_class }}"> + <tr class="{{ sub.color }}-text"> <td> {{ sub.classes }} </td> @@ -47,15 +47,82 @@ </strong> </td> <td> - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ sub.teacher_full|safe }}">{{ sub.teacher|safe }}</span> + {% if sub.sub.type == 1 %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.teacher_old.name }}"> + + <s>{{ sub.sub.teacher_old.shortcode }}</s> + </span> + {% elif sub.sub.teacher_new and sub.sub.teacher_old %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.teacher_old.name }} → {{ sub.sub.teacher_new.name }}"> + + <s>{{ sub.sub.teacher_old.shortcode }}</s> → + <strong>{{ sub.sub.teacher_new.shortcode }}</strong> + </span> + {% elif sub.sub.teacher_new and not sub.sub.teacher_old %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.teacher_new.name }}"> + + <strong>{{ sub.sub.teacher_new.shortcode }}</strong> + </span> + {% elif sub.sub.teacher_old %} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.teacher_old.name }}"> + + <strong>{{ sub.sub.teacher_old.shortcode }}</strong> + </span> + {% endif %} + {# <span class="tooltipped" data-position="bottom"#} + {# data-tooltip="{{ sub.teacher_full|safe }}">{{ sub.teacher|safe }}</span>#} </td> <td> - {{ sub.subject|safe }} + {% if sub.sub.type == 3 %} + <strong>Aufsicht</strong> + {% elif not sub.sub.subject_new and not sub.sub.subject_old %} + {% elif sub.sub.type == 1 or sub.sub.type == 2 %} + <s>{{ sub.sub.subject_old.shortcode }}</s> + {% elif sub.sub.subject_new and sub.sub.subject_old %} + <s>{{ sub.sub.subject_old.shortcode }}</s> → + <strong>{{ sub.sub.subject_new.shortcode }}</strong> + {% elif sub.sub.subject_new and not sub.sub.subject_old %} + <strong>{{ sub.sub.subject_new.shortcode }}</strong> + {% else %} + <strong>{{ sub.sub.subject_old.shortcode }}</strong> + {% endif %} + {# {{ sub.subject|safe }}#} </td> <td> - <span class="tooltipped" data-position="bottom" - data-tooltip="{{ sub.room_full|safe }}">{{ sub.room|safe }}</span> + {% if sub.sub.type == 3 %} + {# Supervisement #} + {{ sub.sub.corridor.name }} + {% elif sub.sub.type == 1 or sub.sub.type == 2 %} + {# Canceled lesson: no room #} + {% elif sub.sub.roow_new and sub.sub.room_old %} + {# New and old room available #} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.room_old.name }} → {{ sub.sub.room_new.name }}"> + <s>{{ sub.sub.room_old.shortcode }}</s> → <strong>{{ sub.sub.room_new.shortcode }}</strong> + </span> + {% elif sub.sub.room_new and not sub.sub.room_old %} + {# Only new room available #} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.room_new.name }}"> + {{ sub.sub.room_new.shortcode }} + </span> + {% elif not sub.sub.room_new and not sub.sub.room_old %} + {# Nothing to view #} + {% else %} + {# Only old room available #} + <span class="tooltipped" data-position="bottom" + data-tooltip="{{ sub.sub.room_old.name }}"> + {{ sub.sub.room_old.shortcode }} + </span> + {% endif %} + {# <span class="tooltipped" data-position="bottom"#} + {# data-tooltip="{{ sub.sub.room }}">#} + {# {{ sub.sub.room }}#} + {# </span>#} </td> <td> {% if sub.badge %} diff --git a/schoolapps/untisconnect/sub.py b/schoolapps/untisconnect/sub.py index ef8ba86ca7d0137059dfc9f56015654049349010..81a8b0abc72efb00dea1decbe17dd4e6393b25b0 100644 --- a/schoolapps/untisconnect/sub.py +++ b/schoolapps/untisconnect/sub.py @@ -12,6 +12,12 @@ TYPE_CORRIDOR = 3 def parse_type_of_untis_flags(flags): + """ + Get type of substitution by parsing UNTIS flags + :param flags: UNTIS flags (string) + :return: type (int, constants are provided) + """ + type_ = TYPE_SUBSTITUTION if "E" in flags: type_ = TYPE_CANCELLATION @@ -20,6 +26,7 @@ def parse_type_of_untis_flags(flags): return type_ +# Build cache drive = build_drive() @@ -51,6 +58,8 @@ class Substitution(object): def create(self, db_obj): self.filled = True + + # Metadata self.id = db_obj.substitution_id self.lesson_id = db_obj.lesson_idsubst self.date = untis_date_to_date(db_obj.date) @@ -58,10 +67,7 @@ class Substitution(object): self.type = parse_type_of_untis_flags(db_obj.flags) self.text = db_obj.text - # Lesson - # Teacher - # print(db_obj.teacher_idlessn) if db_obj.teacher_idlessn != 0: self.teacher_old = drive["teachers"][db_obj.teacher_idlessn] @@ -77,8 +83,7 @@ class Substitution(object): 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) - # print(self.room_old) + # Subject self.subject_old = self.lesson_element.subject if self.lesson_element is not None else None if db_obj.subject_idsubst != 0: @@ -88,35 +93,32 @@ class Substitution(object): self.subject_new = None # Room - # self.rooms_old = self.lesson_element.rooms if self.lesson_element is not None else [] - # if len(self.rooms_old) >= 1: - # self.room_old = self.rooms_old[0] - if db_obj.room_idsubst != 0: self.room_new = drive["rooms"][db_obj.room_idsubst] if self.room_old is not None and self.room_old.id == self.room_new.id: self.room_new = None - # if self.rooms_old - # print(self.room_new) - # print("CORRIDOR") - # print(self.corridor) + # Supervisement if db_obj.corridor_id != 0: self.corridor = drive["corridors"][db_obj.corridor_id] self.type = TYPE_CORRIDOR - # Classes + # Classes self.classes = [] class_ids = untis_split_first(db_obj.classids, conv=int) - # print(class_ids) for id in class_ids: self.classes.append(drive["classes"][id]) - # print(self.classes) def substitutions_sorter(sub): + """ + Sorting helper (sort function) for substitutions + :param sub: Substitution to sort + :return: A string for sorting by + """ + # First, sort by class sort_by = "".join(class_.name for class_ in sub.classes) @@ -132,6 +134,7 @@ def substitutions_sorter(sub): class SubRow(object): def __init__(self): + self.sub = None self.color = "black" self.css_class = "black-text" self.lesson = "" @@ -147,7 +150,6 @@ class SubRow(object): def generate_teacher_row(sub, full=False): - # print(sub.id) teacher = "" if sub.type == 1: teacher = "<s>{}</s>".format(sub.teacher_old.shortcode if not full else sub.teacher_old.name) @@ -203,10 +205,18 @@ def generate_room_row(sub, full=False): def generate_sub_table(subs): + """ + Parse substitutions and prepare than for displaying in plan + :param subs: Substitutions to parse + :return: A list of SubRow objects + """ + sub_rows = [] for sub in subs: sub_row = SubRow() + sub_row.sub = sub + # Color sub_row.color = "black" if sub.type == 1 or sub.type == 2: sub_row.css_class = "green-text" @@ -215,13 +225,13 @@ def generate_sub_table(subs): sub_row.css_class = "blue-text" sub_row.color = "blue" + # Format lesson if sub.type == 3: - sub_row.lesson = "{}./{}".format(sub.lesson - 1, sub.lesson) + sub_row.lesson = "{}./{}.".format(sub.lesson - 1, sub.lesson) else: sub_row.lesson = "{}.".format(sub.lesson) - # for class_ in sub.classes: - # sub_row.classes += class_.name + # Classes sub_row.classes = format_classes(sub.classes) sub_row.teacher = generate_teacher_row(sub) @@ -231,21 +241,17 @@ def generate_sub_table(subs): sub_row.room = generate_room_row(sub) sub_row.room_full = generate_room_row(sub, full=True) - # if DEBUG: - # # Add id only if debug mode is on - # if sub.text: - # sub_row.text = sub.text + " " + str(sub.id) - # else: - # sub_row.text = str(sub.id) - # else: + # Hint text sub_row.text = sub.text + # Badge sub_row.badge = None if sub.type == 1: sub_row.badge = "Schüler frei" elif sub.type == 2: sub_row.badge = "Lehrer frei" + # Debugging information sub_row.extra = "{} {}".format(sub.id, sub.lesson_id) sub_rows.append(sub_row)