Skip to content
Snippets Groups Projects
Verified Commit 25e46744 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Show lessons replaced by events as cancelled in all timetables

parent 937800a9
No related branches found
No related tags found
1 merge request!258Resolve "Events should lead to the cancellation of lessons"
Pipeline #72881 passed with warnings
...@@ -24,6 +24,8 @@ Fixed ...@@ -24,6 +24,8 @@ Fixed
~~~~~ ~~~~~
* Optimize exam model and add reference to exams at extra lessons. * Optimize exam model and add reference to exams at extra lessons.
* Lessons weren't shown as cancelled on teacher or room timetables
if events had replaced them.
`2.3`_ - 2022-03-21 `2.3`_ - 2022-03-21
------------------- -------------------
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{# Display background color only if lesson is not cancelled and it is not the old room #} {# Display background color only if lesson is not cancelled and it is not the old room #}
{% if not smart %} {% if not smart %}
{% include "chronos/partials/subject_colour.html" with subject=lesson_period.lesson.subject %} {% include "chronos/partials/subject_colour.html" with subject=lesson_period.lesson.subject %}
{% elif not sub.cancelled and not lesson_period.get_substitution.cancelled_for_teachers %} {% elif not sub.cancelled and not lesson_period.get_substitution.cancelled_for_teachers and not lesson_period.replaced_by_event %}
{% if not type.value == "room" or lesson_period.room == lesson_period.get_room or lesson_period.get_room == el %} {% if not type.value == "room" or lesson_period.room == lesson_period.get_room or lesson_period.get_room == el %}
{% if sub and sub.subject %} {% if sub and sub.subject %}
{% include "chronos/partials/subject_colour.html" with subject=sub.subject %} {% include "chronos/partials/subject_colour.html" with subject=sub.subject %}
...@@ -17,10 +17,15 @@ ...@@ -17,10 +17,15 @@
{% endwith %} {% endwith %}
" "
{# Add CSS class for sub when it's a sub #} {# Add CSS class for sub when it's a sub #}
class="{% if lesson_period.get_substitution and smart %}lesson-with-sub{% endif %}" class="{% if smart %}{% if lesson_period.get_substitution or lesson_period.replaced_by_event %}lesson-with-sub{% endif %}{% endif %}"
> >
<p> <p>
{% if lesson_period.get_substitution and smart %} {% if lesson_period.replaced_by_event and smart %}
{% include "chronos/partials/groups.html" with groups=lesson_period.lesson.groups.all %}
{% include "chronos/partials/subject.html" with subject=lesson_period.lesson.subject %}
<br/>
<span class="badge new green">{% trans "Cancelled due to an event" %}</span>
{% elif lesson_period.get_substitution and smart %}
{% with sub=lesson_period.get_substitution %} {% with sub=lesson_period.get_substitution %}
{# SUBSTITUTION #} {# SUBSTITUTION #}
{% if type.value == "room" and lesson_period.room != lesson_period.get_room and lesson_period.get_room != el %} {% if type.value == "room" and lesson_period.room != lesson_period.get_room and lesson_period.get_room != el %}
......
...@@ -119,11 +119,6 @@ def build_timetable( ...@@ -119,11 +119,6 @@ def build_timetable(
else: else:
events = events.on_day(date_ref) events = events.on_day(date_ref)
if is_person:
events = events.filter_from_person(obj)
else:
events = events.filter_from_type(type_, obj)
events = events.only( events = events.only(
"id", "id",
"title", "title",
...@@ -136,8 +131,15 @@ def build_timetable( ...@@ -136,8 +131,15 @@ def build_timetable(
"period_to__weekday", "period_to__weekday",
"period_to__period", "period_to__period",
) )
if is_person:
events_to_display = events.filter_from_person(obj)
else:
events_to_display = events.filter_from_type(type_, obj)
# Sort events in a dict # Sort events in a dict
events_per_period = {} events_per_period = {}
events_for_replacement_per_period = {}
for event in events: for event in events:
if is_week and event.date_start < date_ref[TimePeriod.weekday_min]: if is_week and event.date_start < date_ref[TimePeriod.weekday_min]:
# If start date not in current week, set weekday and period to min # If start date not in current week, set weekday and period to min
...@@ -175,16 +177,30 @@ def build_timetable( ...@@ -175,16 +177,30 @@ def build_timetable(
period_to = TimePeriod.period_max period_to = TimePeriod.period_max
for period in range(period_from, period_to + 1): for period in range(period_from, period_to + 1):
if period not in events_per_period: # The following events are possibly replacing some lesson periods
events_per_period[period] = {} if is_week else [] if period not in events_for_replacement_per_period:
events_for_replacement_per_period[period] = {} if is_week else []
if is_week and weekday not in events_per_period[period]: if is_week and weekday not in events_for_replacement_per_period[period]:
events_per_period[period][weekday] = [] events_for_replacement_per_period[period][weekday] = []
if not is_week: if not is_week:
events_per_period[period].append(event) events_for_replacement_per_period[period].append(event)
else: else:
events_per_period[period][weekday].append(event) events_for_replacement_per_period[period][weekday].append(event)
# and the following will be displayed in the timetable
if event in events_to_display:
if period not in events_per_period:
events_per_period[period] = {} if is_week else []
if is_week and weekday not in events_per_period[period]:
events_per_period[period][weekday] = []
if not is_week:
events_per_period[period].append(event)
else:
events_per_period[period][weekday].append(event)
if type_ == TimetableType.TEACHER: if type_ == TimetableType.TEACHER:
# Get matching supervisions # Get matching supervisions
...@@ -297,6 +313,11 @@ def build_timetable( ...@@ -297,6 +313,11 @@ def build_timetable(
if period in events_per_period if period in events_per_period
else [] else []
) )
events_for_replacement_for_this_period = (
events_for_replacement_per_period[period].get(weekday, [])
if period in events_for_replacement_per_period
else []
)
lesson_periods_for_this_period = ( lesson_periods_for_this_period = (
lesson_periods_per_period[period].get(weekday, []) lesson_periods_per_period[period].get(weekday, [])
if period in lesson_periods_per_period if period in lesson_periods_per_period
...@@ -305,19 +326,21 @@ def build_timetable( ...@@ -305,19 +326,21 @@ def build_timetable(
# Add lesson periods # Add lesson periods
if lesson_periods_for_this_period: if lesson_periods_for_this_period:
if events_for_this_period: if events_for_replacement_for_this_period:
# If there is a event in this period, # If there is a event in this period,
# we have to check whether the actual lesson is taking place. # we have to check whether the actual lesson is taking place.
lesson_periods_to_keep = []
for lesson_period in lesson_periods_for_this_period: for lesson_period in lesson_periods_for_this_period:
if not lesson_period.is_replaced_by_event( replaced_by_event = lesson_period.is_replaced_by_event(
events_for_this_period, events_for_replacement_for_this_period,
[obj] if type_ == TimetableType.GROUP else None, [obj] if type_ == TimetableType.GROUP else None,
)
lesson_period.replaced_by_event = replaced_by_event
if not replaced_by_event or (
replaced_by_event and not type_ == TimetableType.GROUP
): ):
lesson_periods_to_keep.append(lesson_period) col.append(lesson_period)
col += lesson_periods_to_keep
else: else:
col += lesson_periods_for_this_period col += lesson_periods_for_this_period
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment