diff --git a/codeforlife/user/models/user.py b/codeforlife/user/models/user.py index 881d4bb..b579cdb 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 55c869f..a66c2f9 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,