2023-02-08 15:42:09 +00:00
|
|
|
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",
|
2023-02-08 15:42:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
course_directory_file = ""
|
|
|
|
|
2023-07-06 15:39:16 +00:00
|
|
|
|
2023-02-08 15:42:09 +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()
|
|
|
|
|
2023-02-08 15:42:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-02-08 15:42:09 +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 = [], []
|
2023-02-08 15:42:09 +00:00
|
|
|
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
|