NDOJ/judge/views/course.py

40 lines
1.1 KiB
Python
Raw Normal View History

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",
2023-07-06 15:39:16 +00:00
"CourseResourceEdit",
]
course_directory_file = ""
2023-07-06 15:39:16 +00:00
class CourseListMixin(object):
def get_queryset(self):
2023-07-06 15:39:16 +00:00
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)
2023-07-06 15:39:16 +00:00
def get_context_data(self, **kwargs):
2023-07-06 15:39:16 +00:00
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