Skip to content
Snippets Groups Projects
Commit cb846ef4 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Improve teacher filtering mechanism when generating substitutions from absences

parent 15ed1bb4
No related branches found
No related tags found
1 merge request!329Introduce substitution to do list
Pipeline #193169 failed
...@@ -876,6 +876,13 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): ...@@ -876,6 +876,13 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet):
) )
return self.filter(Q(teachers=teacher) | Q(pk__in=amended)).distinct() return self.filter(Q(teachers=teacher) | Q(pk__in=amended)).distinct()
def for_teachers(self, teachers: list[Union[int, Person]]) -> "LessonEventQuerySet":
"""Get all lesson events for a list of persons as teacher (including amends)."""
amended = self.filter(Q(amended_by__isnull=False) & (Q(teachers__in=teachers))).values_list(
"amended_by__pk", flat=True
)
return self.filter(Q(teachers__in=teachers) | Q(pk__in=amended)).distinct()
def for_participant(self, person: Union[int, Person]) -> "LessonEventQuerySet": def for_participant(self, person: Union[int, Person]) -> "LessonEventQuerySet":
"""Get all lesson events the person participates in (including amends).""" """Get all lesson events the person participates in (including amends)."""
amended = self.filter(Q(amended_by__isnull=False) | Q(groups__members=person)).values_list( amended = self.filter(Q(amended_by__isnull=False) | Q(groups__members=person)).values_list(
......
...@@ -1664,6 +1664,12 @@ class LessonEvent(CalendarEvent): ...@@ -1664,6 +1664,12 @@ class LessonEvent(CalendarEvent):
if teacher: if teacher:
event_queryset = event_queryset.for_teacher(teacher) event_queryset = event_queryset.for_teacher(teacher)
else:
affected_teachers = Person.objects.filter(
Q(kolego_absences__datetime_start__lte=date_end)
& Q(kolego_absences__datetime_end__gte=date_start)
)
event_queryset = event_queryset.for_teachers(affected_teachers)
events = LessonEvent.get_single_events( events = LessonEvent.get_single_events(
start=date_start, end=date_end, request=request, with_reference_object=True, queryset=event_queryset start=date_start, end=date_end, request=request, with_reference_object=True, queryset=event_queryset
......
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