Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions yaksh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ class Meta:
model = Course
fields = [
'name', 'enrollment', 'active', 'code', 'instructions',
'start_enroll_time', 'end_enroll_time', 'grading_system',
'view_grade'
'start_enroll_time', 'end_enroll_time', 'start_date_time',
'end_date_time', 'grading_system', 'view_grade'
]

def save(self, commit=True, *args, **kwargs):
Expand Down Expand Up @@ -440,9 +440,15 @@ def __init__(self, user, *args, **kwargs):
{'class': form_input_class, 'placeholder': 'Course instructions'}
)
self.fields['start_enroll_time'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Course Start DateTime'}
{'class': form_input_class, 'placeholder': 'Enrollment Start DateTime'}
)
self.fields['end_enroll_time'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Enrollment End DateTime'}
)
self.fields['start_date_time'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Course Start DateTime'}
)
self.fields['end_date_time'].widget.attrs.update(
{'class': form_input_class, 'placeholder': 'Course End DateTime'}
)
self.fields['grading_system'].widget.attrs.update(
Expand Down
24 changes: 23 additions & 1 deletion yaksh/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,23 @@ class Course(models.Model):
null=True
)

# The start date of the course enrollment.
start_date_time = models.DateTimeField(
"Start Date and Time of the course",
default=timezone.now,
null=True
)

# The end date and time of the course enrollment
end_date_time = models.DateTimeField(
"End Date and Time of the course",
default=datetime(
2199, 1, 1,
tzinfo=pytz.timezone(timezone.get_current_timezone_name())
),
null=True
)

grading_system = models.ForeignKey(GradingSystem, null=True, blank=True,
on_delete=models.CASCADE)

Expand Down Expand Up @@ -982,6 +999,11 @@ def get_requests(self):
def is_active_enrollment(self):
return self.start_enroll_time <= timezone.now() < self.end_enroll_time

def is_active(self):
return self.active and (
self.start_date_time <= timezone.now() < self.end_date_time
)

def enroll(self, was_rejected, *users):
self.students.add(*users)
if not was_rejected:
Expand Down Expand Up @@ -3256,7 +3278,7 @@ def has_quiz_time_exhausted(self):
return not self.quiz.active or self.quiz.is_expired()

def is_course_exhausted(self):
return not self.course.active or not self.course.is_active_enrollment()
return not self.course.active or not self.course.is_active()

def is_special_attempt_required(self):
return (self.has_student_attempts_exhausted() or
Expand Down
2 changes: 1 addition & 1 deletion yaksh/templates/yaksh/quizzes_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>{{title}}</h2>
</a>
{% endif %}
{% else %}
{% if course.data.active %}
{% if course.is_active %}
{% if course.data.is_active_enrollment %}
{% if course.data.is_self_enroll %}
<a class="btn btn-primary" href="{% url 'yaksh:self_enroll' course.data.id %}">Enroll</a>
Expand Down
15 changes: 8 additions & 7 deletions yaksh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def quizlist_user(request, enrolled=None, msg=None):
courses_data.append(
{
'data': course,
'is_active': course.is_active(),
'completion_percentage': _percent,
}
)
Expand Down Expand Up @@ -585,7 +586,7 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None,
return quizlist_user(request, msg=msg)

# if course is active and is not expired
if not course.active or not course.is_active_enrollment():
if not course.active or not course.is_active():
msg = "{0} is either expired or not active".format(course.name)
if is_moderator(user) and course.is_trial:
return prof_manage(request, msg=msg)
Expand Down Expand Up @@ -1104,7 +1105,7 @@ def add_course(request, course_id=None):
def enroll_request(request, course_id):
user = request.user
course = get_object_or_404(Course, pk=course_id)
if not course.is_active_enrollment() and course.hidden:
if not (course.is_active_enrollment() or not course.is_active()) and course.hidden:
msg = (
'Unable to add enrollments for this course, please contact your '
'instructor/administrator.'
Expand Down Expand Up @@ -1203,7 +1204,7 @@ def enroll_user(request, course_id, user_id=None, was_rejected=False):
raise Http404('You are not allowed to view this page')

course = get_object_or_404(Course, id=course_id)
if not course.is_active_enrollment():
if not course.is_active_enrollment() or not course.is_active():
msg = (
'Enrollment for this course has been closed,'
' please contact your '
Expand Down Expand Up @@ -1245,7 +1246,7 @@ def enroll_reject_user(request,
raise Http404('You are not allowed to view this page')
course = get_object_or_404(Course, id=course_id)

if not course.is_active_enrollment():
if not course.is_active_enrollment() or not course.is_active():
msg = (
'Enrollment for this course has been closed,'
' please contact your '
Expand Down Expand Up @@ -2767,7 +2768,7 @@ def show_lesson(request, lesson_id, module_id, course_id):
course = Course.objects.get(id=course_id)
if user not in course.students.all():
raise Http404('This course does not belong to you')
if not course.active or not course.is_active_enrollment():
if not course.is_active() or not course.is_active_enrollment():
msg = "{0} is either expired or not active".format(course.name)
return quizlist_user(request, msg=msg)
learn_module = course.learning_module.get(id=module_id)
Expand Down Expand Up @@ -3145,7 +3146,7 @@ def view_module(request, module_id, course_id, msg=None):
if user not in course.students.all():
raise Http404('You are not enrolled for this course!')
context = {}
if not course.active or not course.is_active_enrollment():
if not course.is_active() or not course.is_active_enrollment():
msg = "{0} is either expired or not active".format(course.name)
return course_modules(request, course_id, msg)
learning_module = course.learning_module.get(id=module_id)
Expand Down Expand Up @@ -3189,7 +3190,7 @@ def course_modules(request, course_id, msg=None):
msg = 'You are not enrolled for this course!'
return quizlist_user(request, msg=msg)

if not course.active or not course.is_active_enrollment():
if not course.is_active() or not course.is_active_enrollment():
msg = "{0} is either expired or not active".format(course.name)
return quizlist_user(request, msg=msg)
learning_modules = course.get_learning_modules()
Expand Down