From cb8d2728f9ec13ee8f2796c41d23287e4a29a813 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 23 Feb 2024 14:00:39 +0000 Subject: [PATCH] fix: remove base serializers --- codeforlife/user/serializers/__init__.py | 4 ++-- codeforlife/user/serializers/teacher.py | 7 +------ codeforlife/user/serializers/user.py | 11 +++-------- codeforlife/user/views/user.py | 4 ++-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/codeforlife/user/serializers/__init__.py b/codeforlife/user/serializers/__init__.py index 2a55b25..37903f0 100644 --- a/codeforlife/user/serializers/__init__.py +++ b/codeforlife/user/serializers/__init__.py @@ -6,5 +6,5 @@ from .klass import ClassSerializer from .school import SchoolSerializer from .student import StudentSerializer -from .teacher import BaseTeacherSerializer, TeacherSerializer -from .user import BaseUserSerializer, UserSerializer +from .teacher import TeacherSerializer +from .user import UserSerializer diff --git a/codeforlife/user/serializers/teacher.py b/codeforlife/user/serializers/teacher.py index feca6ac..4b2d554 100644 --- a/codeforlife/user/serializers/teacher.py +++ b/codeforlife/user/serializers/teacher.py @@ -10,7 +10,7 @@ # pylint: disable-next=missing-class-docstring -class BaseTeacherSerializer(ModelSerializer[AnyTeacher], t.Generic[AnyTeacher]): +class TeacherSerializer(ModelSerializer[AnyTeacher], t.Generic[AnyTeacher]): # pylint: disable-next=missing-class-docstring,too-few-public-methods class Meta: model = Teacher @@ -24,8 +24,3 @@ class Meta: "school": {"read_only": True}, "is_admin": {"read_only": True}, } - - -# pylint: disable-next=missing-class-docstring,too-many-ancestors -class TeacherSerializer(BaseTeacherSerializer[Teacher]): - pass diff --git a/codeforlife/user/serializers/user.py b/codeforlife/user/serializers/user.py index b70318d..bc613f5 100644 --- a/codeforlife/user/serializers/user.py +++ b/codeforlife/user/serializers/user.py @@ -12,13 +12,13 @@ # pylint: disable-next=missing-class-docstring -class BaseUserSerializer(ModelSerializer[AnyUser], t.Generic[AnyUser]): +class UserSerializer(ModelSerializer[AnyUser], t.Generic[AnyUser]): student = StudentSerializer( source="new_student", read_only=True, ) - teacher = TeacherSerializer( + teacher = TeacherSerializer[Teacher]( source="new_teacher", read_only=True, ) @@ -57,7 +57,7 @@ def to_representation(self, instance): try: teacher = ( - TeacherSerializer(instance.new_teacher).data + TeacherSerializer[Teacher](instance.new_teacher).data if instance.new_teacher else None ) @@ -74,8 +74,3 @@ def to_representation(self, instance): "student": student, "teacher": teacher, } - - -# pylint: disable-next=missing-class-docstring,too-many-ancestors -class UserSerializer(BaseUserSerializer[User]): - pass diff --git a/codeforlife/user/views/user.py b/codeforlife/user/views/user.py index 4f42558..8e7f94b 100644 --- a/codeforlife/user/views/user.py +++ b/codeforlife/user/views/user.py @@ -8,13 +8,13 @@ from ...views import ModelViewSet from ..filters import UserFilterSet from ..models import AnyUser, User -from ..serializers import BaseUserSerializer, UserSerializer +from ..serializers import UserSerializer # pylint: disable-next=missing-class-docstring,too-many-ancestors class UserViewSet(ModelViewSet[User]): http_method_names = ["get"] - serializer_class: t.Type[BaseUserSerializer] = UserSerializer + serializer_class = UserSerializer[User] filterset_class = UserFilterSet def get_queryset(