summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authormahesh2017-04-07 16:48:25 +0530
committermahesh2017-04-07 16:48:25 +0530
commitde2a369a4908046eef41f01537fd39442e14365c (patch)
tree6b0dd1067987af463e67defd60a559fc4b49a479 /yaksh/views.py
parenta9d7b48b6a5a79bf619500463d89f03e8ca1b7bb (diff)
parentad73f7b938b7620ab4be202dc33c699cf5cb4ac5 (diff)
downloadonline_test-de2a369a4908046eef41f01537fd39442e14365c.tar.gz
online_test-de2a369a4908046eef41f01537fd39442e14365c.tar.bz2
online_test-de2a369a4908046eef41f01537fd39442e14365c.zip
Merge branch 'master' of https://github.com/fossee/online_test into kill_stray_processes
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 2adc2c3..db7498c 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -591,13 +591,18 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None):
@login_required
-def add_course(request):
+def add_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)
+ form = CourseForm(request.POST, instance=course)
if form.is_valid():
new_course = form.save(commit=False)
new_course.creator = user
@@ -608,7 +613,7 @@ def add_course(request):
{'form': form},
context_instance=ci)
else:
- form = CourseForm()
+ form = CourseForm(instance=course)
return my_render_to_response('yaksh/add_course.html', {'form': form},
context_instance=ci)
@@ -618,9 +623,14 @@ 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=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/')
@@ -676,6 +686,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=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')
@@ -859,7 +874,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