diff --git a/aleksis/apps/chronos/templates/chronos/partials/subs/period.html b/aleksis/apps/chronos/templates/chronos/partials/subs/period.html index 7d09cbebe5a320e98892ff637b99ae224e6f94f9..ef1d2838373b1537444aa6f2248ddc4c0e644267 100644 --- a/aleksis/apps/chronos/templates/chronos/partials/subs/period.html +++ b/aleksis/apps/chronos/templates/chronos/partials/subs/period.html @@ -1,6 +1,8 @@ <strong> - {% if type == "substitution" %} + {% if type == "substitution" and item.start_period == item.end_period %} {{ el.lesson_period.period.period }}. + {% elif type == "substitution" %} + {{ item.start_period }}.–{{ item.end_period }}. {% elif type == "extra_lesson" %} {{ el.period.period }}. {% elif type == "event" %} diff --git a/aleksis/apps/chronos/templates/chronos/substitutions.html b/aleksis/apps/chronos/templates/chronos/substitutions.html index cb47a88ca14f750229987a0be0e175ad5cf32dd1..82e5d40313828032d46a8ece311ab132f60ae388 100644 --- a/aleksis/apps/chronos/templates/chronos/substitutions.html +++ b/aleksis/apps/chronos/templates/chronos/substitutions.html @@ -64,7 +64,7 @@ {% include "chronos/partials/subs/groups.html" with type=item.type el=item.el %} </td> <td> - {% include "chronos/partials/subs/period.html" with type=item.type el=item.el %} + {% include "chronos/partials/subs/period.html" with type=item.type el=item.el item=item %} </td> <td> {% include "chronos/partials/subs/teachers.html" with type=item.type el=item.el %} diff --git a/aleksis/apps/chronos/templates/chronos/substitutions_print.html b/aleksis/apps/chronos/templates/chronos/substitutions_print.html index 29853991b8465d29c35f670728dcf1ac71fbdcdc..adfdfebe7362e3dab8fc901ba7ec828f241b1f83 100644 --- a/aleksis/apps/chronos/templates/chronos/substitutions_print.html +++ b/aleksis/apps/chronos/templates/chronos/substitutions_print.html @@ -57,7 +57,7 @@ {% include "chronos/partials/subs/groups.html" with type=item.type el=item.el %} </td> <td> - {% include "chronos/partials/subs/period.html" with type=item.type el=item.el %} + {% include "chronos/partials/subs/period.html" with type=item.type el=item.el item=item %} </td> <td> {% include "chronos/partials/subs/teachers.html" with type=item.type el=item.el %} diff --git a/aleksis/apps/chronos/util/build.py b/aleksis/apps/chronos/util/build.py index 08800d32c79b11e0556d32dcd0ebd691e90bf447..db23417ddcb0e57b5f8e054b60f1edd4dbe463de 100644 --- a/aleksis/apps/chronos/util/build.py +++ b/aleksis/apps/chronos/util/build.py @@ -245,19 +245,42 @@ def build_substitutions_list(wanted_day: date) -> List[dict]: "lesson_period__lesson__groups", "lesson_period__period" ) - for sub in subs: + start_period = None + for i, sub in enumerate(subs): if not sub.cancelled_for_teachers: sort_a = sub.lesson_period.lesson.group_names else: sort_a = f"Z.{sub.lesson_period.lesson.teacher_names}" + # Get next substitution + next_sub = subs[i + 1] if i + 1 < len(subs) else None + + # Check if next substitution is equal with this substitution + if ( + next_sub + and sub.comment == next_sub.comment + and sub.cancelled == next_sub.cancelled + and sub.subject == next_sub.subject + and sub.room == next_sub.room + and sub.lesson_period.lesson == next_sub.lesson_period.lesson + and set(sub.teachers.all()) == set(next_sub.teachers.all()) + ): + if not start_period: + start_period = sub.lesson_period.period.period + continue + row = { "type": "substitution", "sort_a": sort_a, "sort_b": str(sub.lesson_period.period.period), "el": sub, + "start_period": start_period if start_period else sub.lesson_period.period.period, + "end_period": sub.lesson_period.period.period, } + if start_period: + start_period = None + rows.append(row) # Get supervision substitutions