diff --git a/aleksis/apps/chronos/managers.py b/aleksis/apps/chronos/managers.py index e4387402ec83f8887e4d447962e99c0b8385e866..d52c750d5575910fa50299628ab6735ddb7d142b 100644 --- a/aleksis/apps/chronos/managers.py +++ b/aleksis/apps/chronos/managers.py @@ -27,21 +27,27 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): def for_teacher(self, teacher: Union[int, Person]) -> "LessonEventQuerySet": """Get all lesson events for a certain person as teacher (including amends).""" - amended = self.filter(Q(amended_by__isnull=False) & (Q(teachers=teacher))).values_list( - "amended_by__pk", flat=True - ) + from .models import LessonEvent + + amended = LessonEvent.objects.filter( + amended_by__isnull=False, teachers=teacher + ).values_list("amended_by__pk", flat=True) return self.filter(Q(teachers=teacher) | Q(pk__in=amended)).distinct() def for_participant(self, person: Union[int, Person]) -> "LessonEventQuerySet": """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_by__pk", flat=True - ) + from .models import LessonEvent + + amended = LessonEvent.objects.filter( + amended_by__isnull=False, groups__members=person + ).values_list("amended_by__pk", flat=True) return self.filter(Q(groups__members=person) | Q(pk__in=amended)).distinct() def for_group(self, group: Union[int, Group]) -> "LessonEventQuerySet": """Get all lesson events for a certain group (including amends/as parent group).""" - amended = self.filter( + from .models import LessonEvent + + amended = LessonEvent.objects.filter( Q(amended_by__isnull=False) & (Q(groups=group) | Q(groups__parent_groups=group)) ).values_list("amended_by__pk", flat=True) return self.filter( @@ -50,21 +56,27 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): def for_room(self, room: Union[int, Room]) -> "LessonEventQuerySet": """Get all lesson events for a certain room (including amends).""" - amended = self.filter(Q(amended_by__isnull=False) & (Q(rooms=room))).values_list( - "amended_by__pk", flat=True - ) + from .models import LessonEvent + + amended = LessonEvent.objects.filter( + Q(amended_by__isnull=False) & (Q(rooms=room)) + ).values_list("amended_by__pk", flat=True) return self.filter(Q(rooms=room) | Q(pk__in=amended)).distinct() def for_course(self, course: Union[int, Course]) -> "LessonEventQuerySet": """Get all lesson events for a certain course (including amends).""" - amended = self.filter(Q(amended_by__isnull=False) & (Q(course=course))).values_list( + from .models import LessonEvent + + amended = LessonEvent.objects.filter(amended_by__isnull=False, course=course).values_list( "amended_by__pk", flat=True ) return self.filter(Q(course=course) | Q(pk__in=amended)).distinct() def for_person(self, person: Union[int, Person]) -> "LessonEventQuerySet": """Get all lesson events for a certain person (as teacher/participant, including amends).""" - amended = self.filter( + from .models import LessonEvent + + amended = LessonEvent.objects.filter( Q(amended_by__isnull=False) & (Q(teachers=person) | Q(groups__members=person)) ).values_list("amended_by__pk", flat=True) return self.filter( @@ -78,7 +90,9 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): teacher/participant/group owner/parent group owner, including those amended. """ - amended = self.filter( + from .models import LessonEvent + + amended = LessonEvent.objects.filter( Q(amended_by__isnull=False) & ( Q(teachers=person)