Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: python dev level control #2386

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 71 additions & 71 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 20 additions & 43 deletions cfl_common/common/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import typing as t
from datetime import timedelta
from uuid import uuid4

Expand All @@ -7,6 +8,10 @@
from django.utils import timezone
from django_countries.fields import CountryField

if t.TYPE_CHECKING:
from django.db.models import ManyToManyField
from game.models import Worksheet

Check warning on line 13 in cfl_common/common/models.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/models.py#L12-L13

Added lines #L12 - L13 were not covered by tests


class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
Expand Down Expand Up @@ -43,9 +48,7 @@

class School(models.Model):
name = models.CharField(max_length=200, unique=True)
country = CountryField(
blank_label="(select country)", null=True, blank=True
)
country = CountryField(blank_label="(select country)", null=True, blank=True)
# TODO: Create an Address model to house address details
county = models.CharField(max_length=50, blank=True, null=True)
creation_time = models.DateTimeField(default=timezone.now, null=True)
Expand All @@ -68,11 +71,7 @@

def admins(self):
teachers = self.teacher_school.all()
return (
[teacher for teacher in teachers if teacher.is_admin]
if teachers
else None
)
return [teacher for teacher in teachers if teacher.is_admin] if teachers else None

def anonymise(self):
self.name = uuid4().hex
Expand Down Expand Up @@ -130,10 +129,7 @@
def teaches(self, userprofile):
if hasattr(userprofile, "student"):
student = userprofile.student
return (
not student.is_independent()
and student.class_field.teacher == self
)
return not student.is_independent() and student.class_field.teacher == self

def has_school(self):
return self.school is not (None or "")
Expand Down Expand Up @@ -165,14 +161,10 @@
null=True,
on_delete=models.SET_NULL,
)
invited_teacher_first_name = models.CharField(
max_length=150
) # Same as User model
invited_teacher_first_name = models.CharField(max_length=150) # Same as User model
# TODO: Make not nullable once data has been transferred
_invited_teacher_first_name = models.BinaryField(null=True, blank=True)
invited_teacher_last_name = models.CharField(
max_length=150
) # Same as User model
invited_teacher_last_name = models.CharField(max_length=150) # Same as User model
# TODO: Make not nullable once data has been transferred
_invited_teacher_last_name = models.BinaryField(null=True, blank=True)
# TODO: Switch to a CharField to be able to hold hashed value
Expand Down Expand Up @@ -222,10 +214,10 @@


class Class(models.Model):
locked_worksheets: "ManyToManyField[Worksheet]"

name = models.CharField(max_length=200)
teacher = models.ForeignKey(
Teacher, related_name="class_teacher", on_delete=models.CASCADE
)
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)
Expand All @@ -249,9 +241,7 @@
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
assert len(games) == 1 # there should NOT be more than one active game

Check warning on line 244 in cfl_common/common/models.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/models.py#L244

Added line #L244 was not covered by tests
return games[0]
return None

Expand All @@ -261,23 +251,16 @@

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 currently set to always accept requests."

Check warning on line 254 in cfl_common/common/models.py

View check run for this annotation

Codecov / codecov/patch

cfl_common/common/models.py#L254

Added line #L254 was not covered by tests
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."
)
external_requests_message = "This class is not currently accepting external requests."

return external_requests_message

Expand All @@ -299,9 +282,7 @@
login_time = models.DateTimeField(default=timezone.now)
school = models.ForeignKey(School, null=True, on_delete=models.SET_NULL)
class_field = models.ForeignKey(Class, null=True, on_delete=models.SET_NULL)
login_type = models.CharField(
max_length=100, null=True
) # for student login
login_type = models.CharField(max_length=100, null=True) # for student login

def __str__(self):
return f"{self.user} login: {self.login_time} type: {self.login_type}"
Expand Down Expand Up @@ -330,9 +311,7 @@
)

def independentStudentFactory(self, name, email, password):
user = User.objects.create_user(
username=email, email=email, password=password, first_name=name
)
user = User.objects.create_user(username=email, email=email, password=password, first_name=name)

user_profile = UserProfile.objects.create(user=user)

Expand Down Expand Up @@ -391,9 +370,7 @@
JOIN = "join"
RELEASE = "release"

student = models.ForeignKey(
Student, related_name="student", on_delete=models.CASCADE
)
student = models.ForeignKey(Student, related_name="student", on_delete=models.CASCADE)
# either "release" or "join"
action_type = models.CharField(max_length=64)
action_time = models.DateTimeField(default=timezone.now)
Expand Down
Loading
Loading