-
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
17 changed files
with
465 additions
and
291 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
Large diffs are not rendered by default.
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,20 @@ | ||
from rest_framework.pagination import ( | ||
LimitOffsetPagination as _LimitOffsetPagination, | ||
) | ||
from rest_framework.response import Response | ||
|
||
|
||
class LimitOffsetPagination(_LimitOffsetPagination): | ||
default_limit = 50 | ||
max_limit = 500 | ||
|
||
def get_paginated_response(self, data): | ||
return Response( | ||
{ | ||
"count": self.count, | ||
"offset": self.offset, | ||
"limit": self.limit, | ||
"max_limit": self.max_limit, | ||
"results": data, | ||
} | ||
) |
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 @@ | ||
from .user import UserFilter |
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,13 @@ | ||
from django_filters import rest_framework as filters | ||
|
||
from ..models import User | ||
|
||
|
||
class UserFilter(filters.FilterSet): | ||
student__klass = filters.CharFilter( | ||
"new_student__class_field__access_code", "exact" | ||
) | ||
|
||
class Meta: | ||
model = User | ||
fields = ["student__klass"] |
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,71 +1,73 @@ | ||
from uuid import uuid4 | ||
|
||
from django.db import models | ||
|
||
from .user import User | ||
from .classroom import Class | ||
|
||
|
||
class StudentModelManager(models.Manager): | ||
def get_random_username(self): | ||
while True: | ||
random_username = uuid4().hex[:30] # generate a random username | ||
if not User.objects.filter(username=random_username).exists(): | ||
return random_username | ||
|
||
def schoolFactory(self, klass, name, password, login_id=None): | ||
user = User.objects.create_user( | ||
username=self.get_random_username(), | ||
password=password, | ||
first_name=name, | ||
) | ||
|
||
return Student.objects.create( | ||
class_field=klass, user=user, login_id=login_id | ||
) | ||
|
||
def independentStudentFactory(self, name, email, password): | ||
user = User.objects.create_user( | ||
username=email, email=email, password=password, first_name=name | ||
) | ||
|
||
return Student.objects.create(user=user) | ||
|
||
|
||
class Student(models.Model): | ||
class_field = models.ForeignKey( | ||
Class, | ||
related_name="students", | ||
null=True, | ||
blank=True, | ||
on_delete=models.CASCADE, | ||
) | ||
# hashed uuid used for the unique direct login url | ||
login_id = models.CharField(max_length=64, null=True) | ||
user = models.OneToOneField( | ||
User, | ||
related_name="student", | ||
null=True, | ||
blank=True, | ||
on_delete=models.CASCADE, | ||
) | ||
pending_class_request = models.ForeignKey( | ||
Class, | ||
related_name="class_request", | ||
null=True, | ||
blank=True, | ||
on_delete=models.SET_NULL, | ||
) | ||
blocked_time = models.DateTimeField(null=True, blank=True) | ||
|
||
objects = StudentModelManager() | ||
|
||
def is_independent(self): | ||
return not self.class_field | ||
|
||
def __str__(self): | ||
return f"{self.user.first_name} {self.user.last_name}" | ||
|
||
|
||
def stripStudentName(name): | ||
return re.sub("[ \t]+", " ", name.strip()) | ||
# from uuid import uuid4 | ||
|
||
# from django.db import models | ||
|
||
# from .user import User | ||
# from .classroom import Class | ||
|
||
|
||
# class StudentModelManager(models.Manager): | ||
# def get_random_username(self): | ||
# while True: | ||
# random_username = uuid4().hex[:30] # generate a random username | ||
# if not User.objects.filter(username=random_username).exists(): | ||
# return random_username | ||
|
||
# def schoolFactory(self, klass, name, password, login_id=None): | ||
# user = User.objects.create_user( | ||
# username=self.get_random_username(), | ||
# password=password, | ||
# first_name=name, | ||
# ) | ||
|
||
# return Student.objects.create( | ||
# class_field=klass, user=user, login_id=login_id | ||
# ) | ||
|
||
# def independentStudentFactory(self, name, email, password): | ||
# user = User.objects.create_user( | ||
# username=email, email=email, password=password, first_name=name | ||
# ) | ||
|
||
# return Student.objects.create(user=user) | ||
|
||
|
||
# class Student(models.Model): | ||
# class_field = models.ForeignKey( | ||
# Class, | ||
# related_name="students", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.CASCADE, | ||
# ) | ||
# # hashed uuid used for the unique direct login url | ||
# login_id = models.CharField(max_length=64, null=True) | ||
# user = models.OneToOneField( | ||
# User, | ||
# related_name="student", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.CASCADE, | ||
# ) | ||
# pending_class_request = models.ForeignKey( | ||
# Class, | ||
# related_name="class_request", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.SET_NULL, | ||
# ) | ||
# blocked_time = models.DateTimeField(null=True, blank=True) | ||
|
||
# objects = StudentModelManager() | ||
|
||
# def is_independent(self): | ||
# return not self.class_field | ||
|
||
# def __str__(self): | ||
# return f"{self.user.first_name} {self.user.last_name}" | ||
|
||
|
||
# def stripStudentName(name): | ||
# return re.sub("[ \t]+", " ", name.strip()) | ||
|
||
from common.models import Student |
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,66 +1,68 @@ | ||
from django.db import models | ||
# from django.db import models | ||
|
||
from .user import User | ||
from .school import School | ||
# from .user import User | ||
# from .school import School | ||
|
||
|
||
class TeacherModelManager(models.Manager): | ||
def factory(self, first_name, last_name, email, password): | ||
user = User.objects.create_user( | ||
username=email, | ||
email=email, | ||
password=password, | ||
first_name=first_name, | ||
last_name=last_name, | ||
) | ||
# class TeacherModelManager(models.Manager): | ||
# def factory(self, first_name, last_name, email, password): | ||
# user = User.objects.create_user( | ||
# username=email, | ||
# email=email, | ||
# password=password, | ||
# first_name=first_name, | ||
# last_name=last_name, | ||
# ) | ||
|
||
return Teacher.objects.create(user=user) | ||
# return Teacher.objects.create(user=user) | ||
|
||
# Filter out non active teachers by default | ||
def get_queryset(self): | ||
return super().get_queryset().filter(user__is_active=True) | ||
# # Filter out non active teachers by default | ||
# def get_queryset(self): | ||
# return super().get_queryset().filter(user__is_active=True) | ||
|
||
|
||
class Teacher(models.Model): | ||
user = models.OneToOneField( | ||
User, | ||
related_name="teacher", | ||
null=True, | ||
blank=True, | ||
on_delete=models.CASCADE, | ||
) | ||
school = models.ForeignKey( | ||
School, | ||
related_name="school_teacher", | ||
null=True, | ||
blank=True, | ||
on_delete=models.SET_NULL, | ||
) | ||
is_admin = models.BooleanField(default=False) | ||
blocked_time = models.DateTimeField(null=True, blank=True) | ||
invited_by = models.ForeignKey( | ||
"self", | ||
related_name="invited_teachers", | ||
null=True, | ||
blank=True, | ||
on_delete=models.SET_NULL, | ||
) | ||
# class Teacher(models.Model): | ||
# user = models.OneToOneField( | ||
# User, | ||
# related_name="teacher", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.CASCADE, | ||
# ) | ||
# school = models.ForeignKey( | ||
# School, | ||
# related_name="school_teacher", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.SET_NULL, | ||
# ) | ||
# is_admin = models.BooleanField(default=False) | ||
# blocked_time = models.DateTimeField(null=True, blank=True) | ||
# invited_by = models.ForeignKey( | ||
# "self", | ||
# related_name="invited_teachers", | ||
# null=True, | ||
# blank=True, | ||
# on_delete=models.SET_NULL, | ||
# ) | ||
|
||
objects = TeacherModelManager() | ||
# objects = TeacherModelManager() | ||
|
||
def teaches(self, userprofile): | ||
if hasattr(userprofile, "student"): | ||
student = userprofile.student | ||
return ( | ||
not student.is_independent() | ||
and student.class_field.teacher == self | ||
) | ||
# def teaches(self, userprofile): | ||
# if hasattr(userprofile, "student"): | ||
# student = userprofile.student | ||
# return ( | ||
# not student.is_independent() | ||
# and student.class_field.teacher == self | ||
# ) | ||
|
||
def has_school(self): | ||
return self.school is not (None or "") | ||
# def has_school(self): | ||
# return self.school is not (None or "") | ||
|
||
def has_class(self): | ||
return self.class_teacher.exists() | ||
# def has_class(self): | ||
# return self.class_teacher.exists() | ||
|
||
def __str__(self): | ||
return f"{self.user.first_name} {self.user.last_name}" | ||
# def __str__(self): | ||
# return f"{self.user.first_name} {self.user.last_name}" | ||
|
||
from common.models import Teacher |
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.