Skip to content

Commit

Permalink
fix: requesting_to_join_class
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 2, 2024
1 parent 04013c0 commit 7b7e421
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions codeforlife/user/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def to_representation(self, instance):
except Student.DoesNotExist:
student = None

try:
requesting_to_join_class = (
instance.new_student.pending_class_request.access_code
if instance.new_student
and instance.new_student.pending_class_request
else None
)
except Student.DoesNotExist:
requesting_to_join_class = None

try:
teacher = (
TeacherSerializer[Teacher](instance.new_teacher).data
Expand All @@ -87,6 +97,7 @@ def to_representation(self, instance):
"email": instance.email,
"is_active": instance.is_active,
"date_joined": instance.date_joined,
"requesting_to_join_class": requesting_to_join_class,
"student": student,
"teacher": teacher,
}
8 changes: 7 additions & 1 deletion codeforlife/user/serializers/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_to_representation__teacher(self):
self.assert_to_representation(
user,
new_data={
"requesting_to_join_class": None,
"teacher": {
"id": user.teacher.id,
"school": user.teacher.school.id,
Expand All @@ -39,6 +40,7 @@ def test_to_representation__student(self):
self.assert_to_representation(
user,
new_data={
"requesting_to_join_class": None,
"teacher": None,
"student": {
"id": user.student.id,
Expand All @@ -55,5 +57,9 @@ def test_to_representation__indy(self):

self.assert_to_representation(
user,
new_data={"teacher": None, "student": None},
new_data={
"requesting_to_join_class": None,
"teacher": None,
"student": None,
},
)

0 comments on commit 7b7e421

Please sign in to comment.