generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
© Ocado Group | ||
Created on 29/01/2024 at 10:14:59(+00:00). | ||
""" | ||
|
||
from codeforlife.user.models import Class | ||
from codeforlife.user.serializers import StudentSerializer as _StudentSerializer | ||
from rest_framework import serializers | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring,too-many-ancestors | ||
class StudentSerializer(_StudentSerializer): | ||
klass = serializers.CharField(source="class_field.access_code") | ||
|
||
class Meta(_StudentSerializer.Meta): | ||
pass | ||
|
||
# pylint: disable-next=missing-function-docstring | ||
def validate_klass(self, value: str): | ||
if self.request_user.teacher is None: | ||
raise serializers.ValidationError( | ||
"Only a teacher can assign a student to class." | ||
) | ||
if self.request_user.teacher.school is None: | ||
raise serializers.ValidationError( | ||
"The requesting teacher must be in a school." | ||
) | ||
if not Class.objects.filter( | ||
access_code=value, | ||
teacher__school=self.request_user.teacher.school_id, | ||
).exists(): | ||
raise serializers.ValidationError( | ||
"Class must belong to the same school as requesting teacher." | ||
) | ||
|
||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
© Ocado Group | ||
Created on 29/01/2024 at 10:13:58(+00:00). | ||
""" | ||
|
||
from codeforlife.user.serializers import TeacherSerializer as _TeacherSerializer | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class TeacherSerializer(_TeacherSerializer): | ||
class Meta(_TeacherSerializer.Meta): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.