From e665c90805fc07b9553eb089e9dcda73e48e3e4f Mon Sep 17 00:00:00 2001 From: SKairinos Date: Mon, 5 Feb 2024 15:41:13 +0000 Subject: [PATCH] fix: add new props for new user --- codeforlife/serializers/base.py | 60 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/codeforlife/serializers/base.py b/codeforlife/serializers/base.py index 16af791b..24083884 100644 --- a/codeforlife/serializers/base.py +++ b/codeforlife/serializers/base.py @@ -12,7 +12,13 @@ from rest_framework.serializers import BaseSerializer as _BaseSerializer from ..request import Request -from ..user.models import User +from ..user.models import ( # TODO: add IndependentUser + NonSchoolTeacherUser, + SchoolTeacherUser, + StudentUser, + TeacherUser, + User, +) # pylint: disable-next=abstract-method @@ -28,15 +34,63 @@ def request(self): @property def request_user(self): """ - The user that made the request. Assumes the user has authenticated. + The user that made the request. + Assumes the user has authenticated. """ return t.cast(User, self.request.user) + @property + def request_teacher_user(self): + """ + The teacher-user that made the request. + Assumes the user has authenticated. + """ + + return t.cast(TeacherUser, self.request.user) + + @property + def request_school_teacher_user(self): + """ + The school-teacher-user that made the request. + Assumes the user has authenticated. + """ + + return t.cast(SchoolTeacherUser, self.request.user) + + @property + def request_non_school_teacher_user(self): + """ + The non-school-teacher-user that made the request. + Assumes the user has authenticated. + """ + + return t.cast(NonSchoolTeacherUser, self.request.user) + + @property + def request_student_user(self): + """ + The student-user that made the request. + Assumes the user has authenticated. + """ + + return t.cast(StudentUser, self.request.user) + + # TODO: uncomment when moving to new data models. + # @property + # def request_indy_user(self): + # """ + # The independent-user that made the request. + # Assumes the user has authenticated. + # """ + + # return t.cast(IndependentUser, self.request.user) + @property def request_anon_user(self): """ - The user that made the request. Assumes the user has not authenticated. + The user that made the request. + Assumes the user has not authenticated. """ return t.cast(AnonymousUser, self.request.user)