diff --git a/codeforlife/user/serializers/user.py b/codeforlife/user/serializers/user.py index 6938fdbe..15eefdd6 100644 --- a/codeforlife/user/serializers/user.py +++ b/codeforlife/user/serializers/user.py @@ -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 @@ -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, } diff --git a/codeforlife/user/serializers/user_test.py b/codeforlife/user/serializers/user_test.py index a4fc38bf..a2985ac4 100644 --- a/codeforlife/user/serializers/user_test.py +++ b/codeforlife/user/serializers/user_test.py @@ -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, @@ -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, @@ -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, + }, )