From da7014b32635f47d0fd66931ce5961e54f82ae94 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 24 Feb 2015 14:13:38 +0530 Subject: Answer is now saved from the question navigator as well --- testapp/exam/templates/exam/question.html | 20 ++++++++++++++------ testapp/exam/views.py | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html index 96e7bd6..5d03b37 100644 --- a/testapp/exam/templates/exam/question.html +++ b/testapp/exam/templates/exam/question.html @@ -48,7 +48,12 @@ function setSnippetHeight() ta.style.height = height; autoresize(); } - +function call_skip(url) +{ + form = document.forms["code"] + form.action = url + form.submit(); +} {% endblock script %} @@ -82,17 +87,18 @@ function setSnippetHeight() +
-

{{ question.summary }} (Marks : {{ question.points }})


@@ -117,7 +123,9 @@ function setSnippetHeight()

- {% csrf_token %} + {% csrf_token %} + + {% if question.type == "mcq" %} {% for option in question.options.strip.splitlines %} {{option}}
diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 576405f..ba48b60 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -754,6 +754,29 @@ def question(request, q_id, attempt_no, questionpaper_id, success_msg=None): def show_question(request, q_id, attempt_no, questionpaper_id, success_msg=None): """Show a question if possible.""" + user = request.user + q_paper = QuestionPaper.objects.get(id=questionpaper_id) + paper = AnswerPaper.objects.get(user=request.user, attempt_number=attempt_no, + question_paper=q_paper) + if not user.is_authenticated() or paper.end_time < datetime.datetime.now(): + return my_redirect('/exam/login/') + old_qid = request.POST.get('question_id') + if old_qid is not None: + + quest = Question.objects.get(pk=old_qid) + user_code = request.POST.get('answer') + if quest.type == 'code': + user_answer = user_code # not taking snippet here. + old_skipped = paper.answers.filter(question=quest, skipped=True) + if old_skipped: + skipped_answer = old_skipped[0] + skipped_answer.answer=user_answer + skipped_answer.save() + else: + skipped_answer = Answer(question=quest, answer=user_answer, + correct=False, skipped=True) + skipped_answer.save() + paper.answers.add(skipped_answer) if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' return complete(request, msg, attempt_no, questionpaper_id) -- cgit