Skip to content
Snippets Groups Projects
Commit 1fc558bd authored by Julian's avatar Julian
Browse files

Filter groups for TimetableManagement by group of selected timeGrid

parent fa81449b
No related branches found
No related tags found
1 merge request!29Resolve "Switch validity range and group select"
......@@ -259,8 +259,22 @@ class Query(graphene.ObjectType):
if not info.context.user.has_perm("lesrooster.plan_timetables_rule"):
return []
# This will fail if the ID is invalid, but won't, if it is empty
time_grid_obj: TimeGrid | None = TimeGrid.objects.get(pk=time_grid) if time_grid is not None else None
# If there is no time_grid, or it is a generic one, filter groups to have a fitting school_term
if time_grid_obj is None or time_grid_obj.group is None:
return (
Group.objects.filter(school_term__lr_validity_ranges__time_grids__id=time_grid)
.annotate(has_cg=Q(child_groups__isnull=False))
.order_by("-has_cg", "name")
)
group_id = time_grid_obj.group.pk
return (
Group.objects.filter(school_term__lr_validity_ranges__time_grids__id=time_grid)
Group.objects.filter(Q(pk=group_id) | Q(parent_groups=group_id) | Q(parent_groups__parent_groups=group_id))
.distinct()
.annotate(has_cg=Q(child_groups__isnull=False))
.order_by("-has_cg", "name")
)
......
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