-
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
11 changed files
with
149 additions
and
111 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# from uuid import uuid4 | ||
# from datetime import timedelta | ||
|
||
# from django.db import models | ||
# from django.utils import timezone | ||
|
||
# from .teacher import Teacher | ||
|
||
|
||
# class ClassModelManager(models.Manager): | ||
# def all_members(self, user): | ||
# members = [] | ||
# if hasattr(user, "teacher"): | ||
# members.append(user.teacher) | ||
# if user.teacher.has_school(): | ||
# classes = user.teacher.class_teacher.all() | ||
# for c in classes: | ||
# members.extend(c.students.all()) | ||
# else: | ||
# c = user.student.class_field | ||
# members.append(c.teacher) | ||
# members.extend(c.students.all()) | ||
# return members | ||
|
||
# # Filter out non active classes by default | ||
# def get_queryset(self): | ||
# return super().get_queryset().filter(is_active=True) | ||
|
||
|
||
# class Class(models.Model): | ||
# name = models.CharField(max_length=200) | ||
# teacher = models.ForeignKey( | ||
# Teacher, related_name="class_teacher", on_delete=models.CASCADE | ||
# ) | ||
# access_code = models.CharField(max_length=5, null=True) | ||
# classmates_data_viewable = models.BooleanField(default=False) | ||
# always_accept_requests = models.BooleanField(default=False) | ||
# accept_requests_until = models.DateTimeField(null=True) | ||
# creation_time = models.DateTimeField(default=timezone.now, null=True) | ||
# is_active = models.BooleanField(default=True) | ||
# created_by = models.ForeignKey( | ||
# Teacher, | ||
# null=True, | ||
# blank=True, | ||
# related_name="created_classes", | ||
# on_delete=models.SET_NULL, | ||
# ) | ||
|
||
# objects = ClassModelManager() | ||
|
||
# def __str__(self): | ||
# return self.name | ||
|
||
# @property | ||
# def active_game(self): | ||
# games = self.game_set.filter(game_class=self, is_archived=False) | ||
# if len(games) >= 1: | ||
# assert ( | ||
# len(games) == 1 | ||
# ) # there should NOT be more than one active game | ||
# return games[0] | ||
# return None | ||
|
||
# def has_students(self): | ||
# students = self.students.all() | ||
# return students.count() != 0 | ||
|
||
# def get_requests_message(self): | ||
# if self.always_accept_requests: | ||
# external_requests_message = ( | ||
# "This class is currently set to always accept requests." | ||
# ) | ||
# elif ( | ||
# self.accept_requests_until is not None | ||
# and (self.accept_requests_until - timezone.now()) >= timedelta() | ||
# ): | ||
# external_requests_message = ( | ||
# "This class is accepting external requests until " | ||
# + self.accept_requests_until.strftime("%d-%m-%Y %H:%M") | ||
# + " " | ||
# + timezone.get_current_timezone_name() | ||
# ) | ||
# else: | ||
# external_requests_message = ( | ||
# "This class is not currently accepting external requests." | ||
# ) | ||
|
||
# return external_requests_message | ||
|
||
# def anonymise(self): | ||
# self.name = uuid4().hex | ||
# self.access_code = "" | ||
# self.is_active = False | ||
# self.save() | ||
|
||
# # Remove independent students' requests to join this class | ||
# self.class_request.clear() | ||
|
||
# class Meta(object): | ||
# verbose_name_plural = "classes" | ||
|
||
from common.models import Class |
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,4 @@ | ||
from .klass import ClassSerializer | ||
from .student import StudentSerializer | ||
from .teacher import TeacherSerializer | ||
from .user import UserSerializer |
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 @@ | ||
from rest_framework import serializers | ||
|
||
from ..models import Class | ||
|
||
|
||
class ClassSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Class | ||
fields = "__all__" | ||
extra_kwargs = { | ||
"id": {"read_only": True}, | ||
} |
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 +1,2 @@ | ||
from .klass import ClassViewSet | ||
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from ..models import Class, User | ||
from ..serializers import ClassSerializer | ||
|
||
|
||
class ClassViewSet(ModelViewSet): | ||
serializer_class = ClassSerializer | ||
|
||
def get_queryset(self): | ||
user: User = self.request.user | ||
if user.teacher is None: | ||
return Class.objects.filter(students=user) | ||
elif 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) |
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