From fbac442c924a127a79147a6e6ba3819ab8c07e7a Mon Sep 17 00:00:00 2001 From: Stefan Kairinos Date: Fri, 11 Oct 2024 15:46:44 +0100 Subject: [PATCH] fix: user queryset (#141) * fix: user queryset * fix formatting --- codeforlife/user/models/user.py | 2 +- codeforlife/user/views/user.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/codeforlife/user/models/user.py b/codeforlife/user/models/user.py index 881d4bb9..b579cdb5 100644 --- a/codeforlife/user/models/user.py +++ b/codeforlife/user/models/user.py @@ -172,7 +172,7 @@ def filter_users(self, queryset: QuerySet[User]): # pylint: disable-next=missing-function-docstring def get_queryset(self): - return self.filter_users(super().get_queryset()) + return self.filter_users(super().get_queryset().filter(is_active=True)) # pylint: disable-next=missing-class-docstring,too-few-public-methods diff --git a/codeforlife/user/views/user.py b/codeforlife/user/views/user.py index 55c869f5..90aa9c8c 100644 --- a/codeforlife/user/views/user.py +++ b/codeforlife/user/views/user.py @@ -25,19 +25,22 @@ def get_queryset( self, user_class: t.Type[AnyUser] = User, # type: ignore[assignment] ): + # TODO: remove this in new schema and add to get_queryset + queryset = user_class.objects.filter(is_active=True) + user = self.request.auth_user if user.student: if user.student.class_field is None: - return user_class.objects.filter(pk=user.pk) + return queryset.filter(pk=user.pk) - return user_class.objects.filter( + return queryset.filter( Q(new_teacher=user.student.class_field.teacher) | Q(new_student__class_field=user.student.class_field) ).order_by("pk") user = self.request.teacher_user if user.teacher.school: - return user_class.objects.filter( + return queryset.filter( Q(new_teacher__school=user.teacher.school_id) | ( Q( @@ -62,7 +65,7 @@ def get_queryset( ) ).order_by("pk") - return user_class.objects.filter(pk=user.pk) + return queryset.filter(pk=user.pk) def get_bulk_queryset( # pragma: no cover self,