-
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
12 changed files
with
176 additions
and
88 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
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,4 @@ | ||
""" | ||
© Ocado Group | ||
Created on 24/01/2024 at 13:52:24(+00:00). | ||
""" |
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
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
""" | ||
© Ocado Group | ||
Created on 24/01/2024 at 13:52:02(+00:00). | ||
""" | ||
|
||
from .klass import ClassViewSet | ||
from .school import SchoolViewSet | ||
from .user import UserViewSet |
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 |
---|---|---|
@@ -1,23 +1,32 @@ | ||
""" | ||
© Ocado Group | ||
Created on 24/01/2024 at 13:47:53(+00:00). | ||
""" | ||
|
||
import typing as t | ||
|
||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from ...views import ModelViewSet | ||
from ..models import Class, User | ||
from ..permissions import IsSchoolMember | ||
from ..serializers import ClassSerializer | ||
|
||
|
||
class ClassViewSet(ModelViewSet): | ||
# pylint: disable-next=missing-class-docstring,too-few-public-methods | ||
class ClassViewSet(ModelViewSet[Class]): | ||
http_method_names = ["get"] | ||
lookup_field = "access_code" | ||
serializer_class = ClassSerializer | ||
permission_classes = [IsAuthenticated, IsSchoolMember] | ||
|
||
# pylint: disable-next=missing-function-docstring | ||
def get_queryset(self): | ||
user: User = self.request.user | ||
user = t.cast(User, self.request.user) | ||
if user.is_student: | ||
return Class.objects.filter(students=user.student) | ||
elif user.teacher.is_admin: | ||
if user.teacher.is_admin: | ||
# TODO: add school field to class object | ||
return Class.objects.filter(teacher__school=user.teacher.school) | ||
else: | ||
return Class.objects.filter(teacher=user.teacher) | ||
|
||
return Class.objects.filter(teacher=user.teacher) |
Oops, something went wrong.