Merge pull request #58 from LQDJudge/courseLuzi

Add initial implementation for course
This commit is contained in:
Phuoc Dinh Le 2023-02-08 10:22:37 -06:00 committed by GitHub
commit f489287707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 7 deletions

View file

@ -64,6 +64,7 @@ from judge.views import (
widgets,
internal,
resolver,
course,
)
from judge.views.problem_data import (
ProblemDataView,
@ -486,6 +487,7 @@ urlpatterns = [
),
),
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
url(r"^course/", paged_list_view(course.CourseList, "course_list" )),
url(
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
contests.ContestCalendar.as_view(),

View file

@ -39,6 +39,7 @@ from judge.models import (
Submission,
Ticket,
VolunteerProblemVote,
Course,
)
@ -64,3 +65,4 @@ admin.site.register(Profile, ProfileAdmin)
admin.site.register(Submission, SubmissionAdmin)
admin.site.register(Ticket, TicketAdmin)
admin.site.register(VolunteerProblemVote, VolunteerProblemVoteAdmin)
admin.site.register(Course)

File diff suppressed because one or more lines are too long

View file

@ -68,7 +68,7 @@ class Course(models.Model):
return False
@classmethod
def is_accessible_by(course, profile):
def is_accessible_by(cls,course, profile):
userqueryset = CourseRole.objects.filter(course=course, user=profile)
if userqueryset.exists():
return True
@ -76,29 +76,29 @@ class Course(models.Model):
return False
@classmethod
def get_students(course):
def get_students(cls,course):
return CourseRole.objects.filter(course=course, role="ST").values("user")
@classmethod
def get_assistants(course):
def get_assistants(cls,course):
return CourseRole.objects.filter(course=course, role="AS").values("user")
@classmethod
def get_teachers(course):
def get_teachers(cls,course):
return CourseRole.objects.filter(course=course, role="TE").values("user")
@classmethod
def add_student(course, profiles):
def add_student(cls,course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="ST")
@classmethod
def add_teachers(course, profiles):
def add_teachers(cls,course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="TE")
@classmethod
def add_assistants(course, profiles):
def add_assistants(cls,course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="AS")

37
judge/views/course.py Normal file
View file

@ -0,0 +1,37 @@
from django.db import models
from judge.models.course import Course
from django.views.generic import ListView
__all__ = [
"CourseList",
"CourseDetail",
"CourseResource",
"CourseResourceDetail",
"CourseStudentResults",
"CourseEdit",
"CourseResourceDetailEdit",
"CourseResourceEdit",
]
course_directory_file = ""
class CourseListMixin(object):
def get_queryset(self):
return Course.objects.filter(is_open = "true").values()
class CourseList(ListView):
model = Course
template_name = "course/list.html"
queryset = Course.objects.filter(is_public=True).filter(is_open=True)
def get_context_data(self, **kwargs):
context = super(CourseList,self).get_context_data(**kwargs)
available , enrolling = [] , []
for course in Course.objects.filter(is_public=True).filter(is_open=True):
if Course.is_accessible_by(course, self.request.profile):
enrolling.append(course)
else:
available.append(course)
context["available"] = available
context["enrolling"] = enrolling
return context

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courses</title>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Enrolling</h1>
{% for course in enrolling %}
<h2> {{ course }} </h2>
{% endfor %}
<h1> Available </h1>
{% for course in available %}
<h2> {{ course }} </h2>
{% endfor %}
</body>
</html>