diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index 70fb2bed8810c338ef2e0afbc3a25e5ae4febc4f..8cfdb3fec8e2f10f9bd4636374804f86deb3622c 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -207,6 +207,21 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet): _period_path = "lesson_period__" _subst_path = "" + def affected_lessons(self): + """ Return all lessons which are affected by selected substitutions """ + + return Lesson.objects.filter(lesson_periods__substitutions__in=self) + + def affected_teachers(self): + """ Return all teachers which are affected by selected substitutions (as substituted or substituting) """ + + return Person.objects.filter(Q(lessons_as_teacher__in=self.affected_lessons()) | Q(lesson_substitutions__in=self)) + + def affected_groups(self): + """ Return all groups which are affected by selected substitutions """ + + return Group.objects.filter(lessons__in=self.affected_lessons()) + class TimePeriod(models.Model): WEEKDAY_CHOICES = list(enumerate(i18n_day_names_lazy())) diff --git a/aleksis/apps/chronos/settings.py b/aleksis/apps/chronos/settings.py index 1ae08d71d21171078752c8f2d80b719b2668e4cc..2c861857f006770095861fdfdd249195a3477c16 100644 --- a/aleksis/apps/chronos/settings.py +++ b/aleksis/apps/chronos/settings.py @@ -1,8 +1,18 @@ from django.utils.translation import gettext_lazy as _ CONSTANCE_CONFIG = { - "CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER": (2, _("Number of days shown on substitutions print view")), + "CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER": ( + 2, + _("Number of days shown on substitutions print view"), + ), + "CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX": ( + True, + _("The header box shows affected teachers/groups."), + ), } CONSTANCE_CONFIG_FIELDSETS = { - "Chronos settings": ("CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER",), + "Chronos settings": ( + "CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER", + "CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX", + ), } diff --git a/aleksis/apps/chronos/static/css/chronos/timetable.css b/aleksis/apps/chronos/static/css/chronos/timetable.css index 324272585c7a0447c8f2e901fafbfb7be94dfa7a..16846c6059e92d49a8ba89258a7b259793c427b0 100644 --- a/aleksis/apps/chronos/static/css/chronos/timetable.css +++ b/aleksis/apps/chronos/static/css/chronos/timetable.css @@ -108,3 +108,7 @@ table.substitutions td, table.substitutions th { margin: 2px; letter-spacing: 0.3pt; } + +.black-text-a a { + color: black; +} diff --git a/aleksis/apps/chronos/templates/chronos/partials/headerbox.html b/aleksis/apps/chronos/templates/chronos/partials/headerbox.html new file mode 100644 index 0000000000000000000000000000000000000000..bc5bd0f34891d644fbaf4f5e2c065f2be450dec9 --- /dev/null +++ b/aleksis/apps/chronos/templates/chronos/partials/headerbox.html @@ -0,0 +1,33 @@ +{% load i18n %} + +{% if affected_teachers and affected_groups %} + <div class="{% if not print %}card{% endif %}"> + <div class="{% if not print %}card-content{% endif %}"> + {% if affected_teachers %} + <div class="row no-margin"> + <div class="col s12 m3"> + <strong class="truncate"> + {% trans "Affected teachers" %} + </strong> + </div> + <div class="col s12 m9 black-text-a"> + {% include "chronos/partials/teachers.html" with teachers=affected_teachers %} + </div> + </div> + {% endif %} + {% if affected_groups %} + <div class="row no-margin"> + <div class="col s12 m3"> + <strong class="truncate"> + {% trans "Affected groups" %} + </strong> + </div> + <div class="col s12 m9 black-text-a"> + {% include "chronos/partials/groups.html" with groups=affected_groups %} + </div> + </div> + {% endif %} + </div> + </div> + {% if print %}<br/>{% endif %} +{% endif %} diff --git a/aleksis/apps/chronos/templates/chronos/substitutions.html b/aleksis/apps/chronos/templates/chronos/substitutions.html index 32e98c56d705fc815f709a7cbcc063c5206cb191..0dc5e242852375b05ff6f48e2b35430d61510727 100644 --- a/aleksis/apps/chronos/templates/chronos/substitutions.html +++ b/aleksis/apps/chronos/templates/chronos/substitutions.html @@ -26,22 +26,7 @@ <div class="row no-print"> <div class="col s12 m6 l8"> - {% if header_info.is_box_needed %} - <div class="card"> - <div class="card-content"> - {% for row in header_info.rows %} - <div class="row no-margin"> - <div class="col s3"> - <strong class="truncate">{{ row.0 }}</strong> - </div> - <div class="col s9"> - {{ row.1 }} - </div> - </div> - {% endfor %} - </div> - </div> - {% endif %} + {% include "chronos/partials/headerbox.html" %} {# {% include "chronos/hintsinsub.html" %}#} </div> diff --git a/aleksis/apps/chronos/templates/chronos/substitutions_print.html b/aleksis/apps/chronos/templates/chronos/substitutions_print.html index 2a4e474bb2fc407f1297efb754d984140fc30fd0..bc041f24c2c366b6ae2764afde621a2e8802a291 100644 --- a/aleksis/apps/chronos/templates/chronos/substitutions_print.html +++ b/aleksis/apps/chronos/templates/chronos/substitutions_print.html @@ -18,20 +18,7 @@ {# {% include "timetable/hintsinsubprint.html" %}#} - {# <div style="margin-bottom: 20px">#} - {# {% if c.header_info.is_box_needed %}#} - {# {% for row in c.header_info.rows %}#} - {# <div class="row no-margin">#} - {# <div class="col s3 no-padding">#} - {# <strong>{{ row.0 }}</strong>#} - {# </div>#} - {# <div class="col s9 no-padding">#} - {# {{ row.1 }}#} - {# </div>#} - {# </div>#} - {# {% endfor %}#} - {# {% endif %}#} - {# </div>#} + {% include "chronos/partials/headerbox.html" with affected_teachers=c.affected_teachers affected_groups=c.affected_groups print=1 %} <table class="substitutions"> <thead> diff --git a/aleksis/apps/chronos/views.py b/aleksis/apps/chronos/views.py index cbeb7e85e7877e6ac5b17e41aabf3f81c253a103..d885886ee35ed22f9b0690fa627a9d100cf190cf 100644 --- a/aleksis/apps/chronos/views.py +++ b/aleksis/apps/chronos/views.py @@ -320,9 +320,12 @@ def substitutions( day_contexts = {wanted_day: {"day": wanted_day}} for day in day_contexts: - day_contexts[day]["substitutions"] = LessonSubstitution.objects.on_day( - day - ).order_by("lesson_period__lesson__groups", "lesson_period__period") + subs = LessonSubstitution.objects.on_day(day).order_by("lesson_period__lesson__groups", "lesson_period__period") + day_contexts[day]["substitutions"] = subs + + if config.CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX: + day_contexts[day]["affected_teachers"] = subs.affected_teachers() + day_contexts[day]["affected_groups"] = subs.affected_groups() if not is_print: context = day_contexts[wanted_day]