Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user queryset #141

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codeforlife/user/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions codeforlife/user/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down