From 171a82aa3ef07fc9344c8c5b42542bec0a3ca5ab Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 30 Mar 2017 18:10:09 +0530 Subject: Multiple changes to Course: - Allow a start and end time for Course enrollment - Allow Course to be editable --- yaksh/views.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 2adc2c3..7208e82 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -613,11 +613,44 @@ def add_course(request): context_instance=ci) +@login_required +def edit_course(request, course_id=None): + user = request.user + ci = RequestContext(request) + if course_id: + course = Course.objects.get(id=course_id) + else: + course = None + + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + if request.method == 'POST': + form = CourseForm(request.POST, instance=course) + if form.is_valid(): + new_course = form.save(commit=False) + new_course.creator = user + new_course.save() + return my_redirect('/exam/manage/') + else: + return my_render_to_response('yaksh/add_course.html', + {'form': form}, + context_instance=ci) + else: + form = CourseForm(instance=course) + return my_render_to_response('yaksh/add_course.html', {'form': form}, + context_instance=ci) + + @login_required def enroll_request(request, course_id): user = request.user ci = RequestContext(request) course = get_object_or_404(Course, pk=course_id) + if not course.is_active_enrollment: + msg = 'Enrollment for this course has been closed, please contact your '\ + 'instructor/administrator.' + return complete(request, msg, attempt_num, questionpaper_id=None) + course.request(user) if is_moderator(user): return my_redirect('/exam/manage/') @@ -676,6 +709,11 @@ def enroll(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, pk=course_id) + if not course.is_active_enrollment: + msg = 'Enrollment for this course has been closed, please contact your '\ + 'instructor/administrator.' + return complete(request, msg, attempt_num, questionpaper_id=None) + if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') -- cgit From c1bdc56f889e60a246e6fccb450f339b68897395 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 4 Apr 2017 10:35:05 +0530 Subject: Check if user is teacher or moderator for creating QuestionPaper --- yaksh/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 2adc2c3..247aca4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -661,8 +661,7 @@ def course_detail(request, course_id): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, pk=course_id) - if not course.is_creator(user) and not course.is_teacher(user): - raise Http404('This course does not belong to you') + return my_render_to_response('yaksh/course_detail.html', {'course': course}, context_instance=ci) @@ -859,7 +858,9 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - + quiz = Quiz.objects.get(id=quiz_id) + if not quiz.course.is_creator(user) and not quiz.course.is_teacher(user): + raise Http404('This course does not belong to you') filter_form = QuestionFilterForm(user=user) questions = None marks = None -- cgit From 09756c7db9341aace9e9ac25c9078c8cd4bf8399 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 4 Apr 2017 10:42:22 +0530 Subject: Fix failing test views test --- yaksh/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 247aca4..661d472 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -661,7 +661,8 @@ def course_detail(request, course_id): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, pk=course_id) - + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') return my_render_to_response('yaksh/course_detail.html', {'course': course}, context_instance=ci) -- cgit From 1a6653567bdf58b5b70e874822cae6a1116b942f Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 5 Apr 2017 18:31:56 +0530 Subject: Add multiple fixes based on code review --- yaksh/views.py | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 7208e82..275cb6f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -591,30 +591,7 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None): @login_required -def add_course(request): - user = request.user - ci = RequestContext(request) - if not is_moderator(user): - raise Http404('You are not allowed to view this page') - if request.method == 'POST': - form = CourseForm(request.POST) - if form.is_valid(): - new_course = form.save(commit=False) - new_course.creator = user - new_course.save() - return my_redirect('/exam/manage/') - else: - return my_render_to_response('yaksh/add_course.html', - {'form': form}, - context_instance=ci) - else: - form = CourseForm() - return my_render_to_response('yaksh/add_course.html', {'form': form}, - context_instance=ci) - - -@login_required -def edit_course(request, course_id=None): +def add_course(request, course_id=None): user = request.user ci = RequestContext(request) if course_id: @@ -649,11 +626,11 @@ def enroll_request(request, course_id): if not course.is_active_enrollment: msg = 'Enrollment for this course has been closed, please contact your '\ 'instructor/administrator.' - return complete(request, msg, attempt_num, questionpaper_id=None) + return complete(request, msg, attempt_num=None, questionpaper_id=None) course.request(user) if is_moderator(user): - return my_redirect('/exam/manage/') + return my_redirect('/exam/manage/courses') else: return my_redirect('/exam/quizzes/') @@ -712,7 +689,7 @@ def enroll(request, course_id, user_id=None, was_rejected=False): if not course.is_active_enrollment: msg = 'Enrollment for this course has been closed, please contact your '\ 'instructor/administrator.' - return complete(request, msg, attempt_num, questionpaper_id=None) + return complete(request, msg, attempt_num=None, questionpaper_id=None) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') -- cgit