Skip to content

Commit

Permalink
fix: user queryset (#141)
Browse files Browse the repository at this point in the history
* fix: user queryset

* fix formatting
  • Loading branch information
SKairinos authored Oct 11, 2024
1 parent 66b05de commit fbac442
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit fbac442

Please sign in to comment.