Skip to content
Snippets Groups Projects
Commit 070f901f authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch '124-check-generation-of-regular-timetable' into 'master'

Resolve "Check generation of regular timetable"

Closes #124

See merge request !153
parents dd2bea55 7456c853
No related branches found
No related tags found
1 merge request!153Resolve "Check generation of regular timetable"
Pipeline #11805 canceled
{% load i18n %}
<div style="
{% with sub=lesson_period.get_substitution %}
{# Display background color only if lesson is not cancelled and it is not the old room #}
{% if not lesson_period.get_substitution.cancelled and not lesson_period.get_substitution.cancelled_for_teachers %}
{% if not smart %}
{% 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 %}
{% if not type.value == "room" or lesson_period.room == lesson_period.get_room or lesson_period.get_room == el %}
{% include "chronos/partials/subject_colour.html" with subject=lesson_period.lesson.subject %}
{% if sub and sub.subject %}
{% include "chronos/partials/subject_colour.html" with subject=sub.subject %}
{% else %}
{% include "chronos/partials/subject_colour.html" with subject=lesson_period.lesson.subject %}
{% endif %}
{% endif %}
{% endif %}
{% endwith %}
"
{# Add CSS class for sub when it's a sub #}
class="{% if lesson_period.get_substitution and smart %}lesson-with-sub{% endif %}"
......
......@@ -25,6 +25,7 @@ def build_timetable(
type_: Union[TimetableType, str],
obj: Union[Group, Room, Person],
date_ref: Union[CalendarWeek, date],
with_holidays: bool = True,
):
needed_breaks = []
......@@ -42,9 +43,9 @@ def build_timetable(
# Get matching holidays
if is_week:
holidays_per_weekday = Holiday.in_week(date_ref)
holidays_per_weekday = Holiday.in_week(date_ref) if with_holidays else {}
else:
holiday = Holiday.on_day(date_ref)
holiday = Holiday.on_day(date_ref) if with_holidays else None
# Get matching lesson periods
lesson_periods = LessonPeriod.objects
......@@ -421,8 +422,11 @@ def build_substitutions_list(wanted_day: date) -> List[dict]:
return rows
def build_weekdays(base: List[Tuple[int, str]], wanted_week: CalendarWeek) -> List[dict]:
holidays_per_weekday = Holiday.in_week(wanted_week)
def build_weekdays(
base: List[Tuple[int, str]], wanted_week: CalendarWeek, with_holidays: bool = True
) -> List[dict]:
if with_holidays:
holidays_per_weekday = Holiday.in_week(wanted_week)
weekdays = []
for key, name in base[TimePeriod.weekday_min : TimePeriod.weekday_max + 1]:
......@@ -431,8 +435,9 @@ def build_weekdays(base: List[Tuple[int, str]], wanted_week: CalendarWeek) -> Li
"key": key,
"name": name,
"date": wanted_week[key],
"holiday": holidays_per_weekday[key] if key in holidays_per_weekday else None,
}
if with_holidays:
weekday["holiday"] = holidays_per_weekday[key] if key in holidays_per_weekday else None
weekdays.append(weekday)
return weekdays
......@@ -140,15 +140,19 @@ def timetable(
wanted_week = TimePeriod.get_relevant_week_from_datetime()
# Build timetable
timetable = build_timetable(type_, el, wanted_week)
timetable = build_timetable(type_, el, wanted_week, with_holidays=is_smart)
context["timetable"] = timetable
# Add time periods
context["periods"] = TimePeriod.get_times_dict()
# Build lists with weekdays and corresponding dates (long and short variant)
context["weekdays"] = build_weekdays(TimePeriod.WEEKDAY_CHOICES, wanted_week)
context["weekdays_short"] = build_weekdays(TimePeriod.WEEKDAY_CHOICES_SHORT, wanted_week)
context["weekdays"] = build_weekdays(
TimePeriod.WEEKDAY_CHOICES, wanted_week, with_holidays=is_smart
)
context["weekdays_short"] = build_weekdays(
TimePeriod.WEEKDAY_CHOICES_SHORT, wanted_week, with_holidays=is_smart
)
context["weeks"] = get_weeks_for_year(year=wanted_week.year)
context["week"] = wanted_week
......
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