diff --git a/aleksis/apps/chronos/templates/chronos/partials/lesson.html b/aleksis/apps/chronos/templates/chronos/partials/lesson.html index 5b7ceb6c511f43087f2f76af5429967131682d92..523b3c62a6885f8dbc06def6daeda62246cb241e 100644 --- a/aleksis/apps/chronos/templates/chronos/partials/lesson.html +++ b/aleksis/apps/chronos/templates/chronos/partials/lesson.html @@ -1,12 +1,20 @@ {% 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 %}" diff --git a/aleksis/apps/chronos/util/build.py b/aleksis/apps/chronos/util/build.py index 483df4d37a3030ff5f7255500e93d86eb0bbdd2c..d2f7214826fec61b3351758231cadfcf1194bed0 100644 --- a/aleksis/apps/chronos/util/build.py +++ b/aleksis/apps/chronos/util/build.py @@ -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 diff --git a/aleksis/apps/chronos/views.py b/aleksis/apps/chronos/views.py index 43eabf9e03f8d477ca3a9d3ca51bcd0a384d1b6a..4ddc0c73b7d8f24b5b6adc8d0a6a9aaeaf3e0d9f 100644 --- a/aleksis/apps/chronos/views.py +++ b/aleksis/apps/chronos/views.py @@ -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