diff options
author | adityacp | 2018-01-15 16:30:26 +0530 |
---|---|---|
committer | adityacp | 2018-01-16 15:20:55 +0530 |
commit | 8006ffb4a5bd54aa960b24f1508d95844fa579de (patch) | |
tree | 5e03c42d8ec18d708b5e17c289310822c5581d51 /yaksh/views.py | |
parent | 3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff) | |
download | online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.gz online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.bz2 online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.zip |
Change in template, test_views, urls and views
- Allow teacher to edit questionpaper for a quiz
- Add test to check if teacher is allowed to edit questionpaper for a quiz
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 49249ca..21c79f3 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -324,6 +324,7 @@ def add_quiz(request, quiz_id=None, course_id=None): form = QuizForm(instance=quiz) context["quiz_id"] = quiz_id context["course_id"] = course_id + context["quiz"] = quiz context["form"] = form return my_render_to_response( 'yaksh/add_quiz.html', context, context_instance=ci @@ -1291,14 +1292,21 @@ def _remove_already_present(questionpaper_id, questions): @login_required @email_verified -def design_questionpaper(request, quiz_id, questionpaper_id=None): +def design_questionpaper(request, quiz_id, questionpaper_id=None, + course_id=None): user = request.user 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.creator == user: - raise Http404('This course does not belong to you') + if quiz_id: + quiz = get_object_or_404(Quiz, pk=quiz_id) + if quiz.creator != user and not course_id: + raise Http404('This quiz does not belong to you') + if course_id: + course = get_object_or_404(Course, pk=course_id) + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This quiz does not belong to you') + filter_form = QuestionFilterForm(user=user) questions = None marks = None @@ -1306,7 +1314,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None): if questionpaper_id is None: question_paper = QuestionPaper.objects.get_or_create(quiz_id=quiz_id)[0] else: - question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id) + question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id, + quiz_id=quiz_id) qpaper_form = QuestionPaperForm(instance=question_paper) if request.method == 'POST': |