This commit is contained in:
zhaospei 2023-01-31 22:54:03 +07:00
parent 51006bc773
commit 037feef8f8
3 changed files with 60 additions and 37 deletions

File diff suppressed because one or more lines are too long

View file

@ -55,4 +55,4 @@ class Migration(migrations.Migration):
('course', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='judge.course', verbose_name='course')),
],
),
]
]

View file

@ -14,11 +14,20 @@ __all__ = [
course_directory_file = ""
class Course(models.Model):
name = models.CharField(max_length=128, verbose_name=_("course name"),)
name = models.CharField(
max_length=128,
verbose_name=_("course name"),
)
about = models.TextField(verbose_name=_("organization description"))
ending_time = models.DateTimeField(verbose_name=_("ending time"),)
is_public = models.BooleanField(verbose_name=_("publicly visible"), default=False,)
ending_time = models.DateTimeField(
verbose_name=_("ending time"),
)
is_public = models.BooleanField(
verbose_name=_("publicly visible"),
default=False,
)
organizations = models.ManyToManyField(
Organization,
blank=True,
@ -34,23 +43,27 @@ class Course(models.Model):
RegexValidator("^[-a-zA-Z0-9]+$", _("Only alphanumeric and hyphens"))
],
)
is_open = models.BooleanField(verbose_name=_("public registration"), default=False,)
is_open = models.BooleanField(
verbose_name=_("public registration"),
default=False,
)
image_url = models.CharField(
verbose_name=_("course image"),
default="",
max_length=150,
verbose_name=_("course image"),
default="",
max_length=150,
blank=True,
)
def __str__(self):
return self.name
@classmethod
def is_editable_by(course, profile):
if (profile.is_superuser):
if profile.is_superuser:
return True
userquery = CourseRole.objects.filter(course=course, user=profile)
if userquery.exists():
if (userquery[0].role == 'AS' or userquery[0].role == 'TE'):
if userquery[0].role == "AS" or userquery[0].role == "TE":
return True
return False
@ -64,31 +77,32 @@ class Course(models.Model):
@classmethod
def get_students(course):
return CourseRole.objects.filter(course=course, role='ST').values('user')
return CourseRole.objects.filter(course=course, role="ST").values("user")
@classmethod
def get_assistants(course):
return CourseRole.objects.filter(course=course, role='AS').values('user')
@classmethod
def get_teachers(course):
return CourseRole.objects.filter(course=course, role='TE').values('user')
@classmethod
def add_student(course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role='ST')
@classmethod
def add_teachers(course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role='TE')
def get_assistants(course):
return CourseRole.objects.filter(course=course, role="AS").values("user")
@classmethod
def add_assistants(course, profiles):
@classmethod
def get_teachers(course):
return CourseRole.objects.filter(course=course, role="TE").values("user")
@classmethod
def add_student(course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role='AS')
CourseRole.make_role(course=course, user=profile, role="ST")
@classmethod
def add_teachers(course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="TE")
@classmethod
def add_assistants(course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="AS")
class CourseRole(models.Model):
course = models.OneToOneField(
Course,
@ -102,10 +116,12 @@ class CourseRole(models.Model):
on_delete=models.CASCADE,
related_name=_("user_of_course"),
)
class RoleInCourse(models.TextChoices):
STUDENT = 'ST', _("Student")
ASSISTANT = 'AS', _("Assistant")
TEACHER = 'TE', _("Teacher")
STUDENT = "ST", _("Student")
ASSISTANT = "AS", _("Assistant")
TEACHER = "TE", _("Teacher")
role = models.CharField(
max_length=2,
choices=RoleInCourse.choices,
@ -124,6 +140,7 @@ class CourseRole(models.Model):
couresrole.role = role
couresrole.save()
class CourseResource(models.Model):
course = models.OneToOneField(
Course,
@ -143,7 +160,11 @@ class CourseResource(models.Model):
max_length=150,
)
order = models.IntegerField(null=True, default=None)
is_public = models.BooleanField(verbose_name=_("publicly visible"), default=False,)
is_public = models.BooleanField(
verbose_name=_("publicly visible"),
default=False,
)
class CourseAssignment(models.Model):
course = models.OneToOneField(
@ -157,4 +178,6 @@ class CourseAssignment(models.Model):
verbose_name=_("contest"),
on_delete=models.CASCADE,
)
points = models.FloatField(verbose_name=_("points"),)
points = models.FloatField(
verbose_name=_("points"),
)