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