Merge branch 'LQDJudge:master' into master
This commit is contained in:
commit
5a4bac2911
7 changed files with 97 additions and 7 deletions
|
@ -64,6 +64,7 @@ from judge.views import (
|
||||||
widgets,
|
widgets,
|
||||||
internal,
|
internal,
|
||||||
resolver,
|
resolver,
|
||||||
|
course,
|
||||||
)
|
)
|
||||||
from judge.views.problem_data import (
|
from judge.views.problem_data import (
|
||||||
ProblemDataView,
|
ProblemDataView,
|
||||||
|
@ -486,6 +487,7 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
||||||
|
url(r"^course/", paged_list_view(course.CourseList, "course_list" )),
|
||||||
url(
|
url(
|
||||||
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
||||||
contests.ContestCalendar.as_view(),
|
contests.ContestCalendar.as_view(),
|
||||||
|
|
|
@ -39,6 +39,7 @@ from judge.models import (
|
||||||
Submission,
|
Submission,
|
||||||
Ticket,
|
Ticket,
|
||||||
VolunteerProblemVote,
|
VolunteerProblemVote,
|
||||||
|
Course,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,3 +65,4 @@ admin.site.register(Profile, ProfileAdmin)
|
||||||
admin.site.register(Submission, SubmissionAdmin)
|
admin.site.register(Submission, SubmissionAdmin)
|
||||||
admin.site.register(Ticket, TicketAdmin)
|
admin.site.register(Ticket, TicketAdmin)
|
||||||
admin.site.register(VolunteerProblemVote, VolunteerProblemVoteAdmin)
|
admin.site.register(VolunteerProblemVote, VolunteerProblemVoteAdmin)
|
||||||
|
admin.site.register(Course)
|
||||||
|
|
18
judge/migrations/0150_alter_profile_timezone.py
Normal file
18
judge/migrations/0150_alter_profile_timezone.py
Normal file
File diff suppressed because one or more lines are too long
|
@ -68,7 +68,7 @@ class Course(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_accessible_by(course, profile):
|
def is_accessible_by(cls,course, profile):
|
||||||
userqueryset = CourseRole.objects.filter(course=course, user=profile)
|
userqueryset = CourseRole.objects.filter(course=course, user=profile)
|
||||||
if userqueryset.exists():
|
if userqueryset.exists():
|
||||||
return True
|
return True
|
||||||
|
@ -76,29 +76,29 @@ class Course(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_students(course):
|
def get_students(cls,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(cls,course):
|
||||||
return CourseRole.objects.filter(course=course, role="AS").values("user")
|
return CourseRole.objects.filter(course=course, role="AS").values("user")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_teachers(course):
|
def get_teachers(cls,course):
|
||||||
return CourseRole.objects.filter(course=course, role="TE").values("user")
|
return CourseRole.objects.filter(course=course, role="TE").values("user")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_student(course, profiles):
|
def add_student(cls,course, profiles):
|
||||||
for profile in profiles:
|
for profile in profiles:
|
||||||
CourseRole.make_role(course=course, user=profile, role="ST")
|
CourseRole.make_role(course=course, user=profile, role="ST")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_teachers(course, profiles):
|
def add_teachers(cls,course, profiles):
|
||||||
for profile in profiles:
|
for profile in profiles:
|
||||||
CourseRole.make_role(course=course, user=profile, role="TE")
|
CourseRole.make_role(course=course, user=profile, role="TE")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_assistants(course, profiles):
|
def add_assistants(cls,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="AS")
|
||||||
|
|
||||||
|
|
37
judge/views/course.py
Normal file
37
judge/views/course.py
Normal 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
|
||||||
|
|
12
templates/course/base.html
Normal file
12
templates/course/base.html
Normal 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>
|
19
templates/course/list.html
Normal file
19
templates/course/list.html
Normal 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>
|
Loading…
Reference in a new issue