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

Add option to show parent groups of affected groups and fix layout accordingly

parent 60ad9b7d
No related branches found
No related tags found
1 merge request!111Resolve "Show only the parent groups in 'Affected groups'"
Pipeline #4883 passed
......@@ -57,3 +57,13 @@ class SubstitutionsShowHeaderBox(BooleanPreference):
default = True
verbose_name = _("Show header box in substitution views")
help_text = _("The header box shows affected teachers/groups.")
@site_preferences_registry.register
class AffectedGroupsUseParentGroups(BooleanPreference):
section = chronos
name = "affected_groups_parent_groups"
default = True
verbose_name = _(
"Show parent groups in header box in substitution views instead of original groups"
)
{% if groups.count == 1 and groups.0.parent_groups.all and request.site.preferences.chronos__use_parent_groups %}
{% include "chronos/partials/groups_part.html" with groups=groups.0.parent_groups.all %}
{% include "chronos/partials/groups_part.html" with groups=groups.0.parent_groups.all no_collapsible=no_collapsible %}
{% else %}
{% include "chronos/partials/groups_part.html" with groups=groups %}
{% include "chronos/partials/groups_part.html" with groups=groups no_collapsible=no_collapsible %}
{% endif %}
{% if groups.count > request.site.preferences.chronos__shorten_groups_limit and request.user.person.preferences.chronos__shorten_groups %}
{% if groups.count > request.site.preferences.chronos__shorten_groups_limit and request.user.person.preferences.chronos__shorten_groups and not no_collapsible %}
{% include "components/text_collapsible.html" with template="chronos/partials/group.html" qs=groups %}
{% else %}
{% for group in groups %}
......
......@@ -23,7 +23,7 @@
</strong>
</div>
<div class="col s12 m9 black-text-a">
{% include "chronos/partials/groups.html" with groups=absent_groups %}
{% include "chronos/partials/groups.html" with groups=absent_groups no_collapsible=True %}
</div>
</div>
{% endif %}
......@@ -47,7 +47,7 @@
</strong>
</div>
<div class="col s12 m9 black-text-a">
{% include "chronos/partials/groups.html" with groups=affected_groups %}
{% include "chronos/partials/groups.html" with groups=affected_groups no_collapsible=True %}
</div>
</div>
{% endif %}
......
from datetime import datetime, timedelta
from typing import Optional
from django.db.models import Count
from django.db.models import Count, Q
from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
......@@ -311,7 +311,15 @@ def substitutions(
day_contexts[day]["absent_teachers"] = absences.absent_teachers()
day_contexts[day]["absent_groups"] = absences.absent_groups()
day_contexts[day]["affected_teachers"] = subs.affected_teachers()
day_contexts[day]["affected_groups"] = subs.affected_groups()
affected_groups = subs.affected_groups()
if get_site_preferences()["chronos__affected_groups_parent_groups"]:
groups_with_parent_groups = affected_groups.filter(parent_groups__isnull=False)
groups_without_parent_groups = affected_groups.filter(parent_groups__isnull=True)
affected_groups = Group.objects.filter(
Q(child_groups__pk__in=groups_with_parent_groups.values_list("pk", flat=True))
| Q(pk__in=groups_without_parent_groups.values_list("pk", flat=True))
).distinct()
day_contexts[day]["affected_groups"] = affected_groups
if not is_print:
context = day_contexts[wanted_day]
......
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