From 45cfca69a8af52fb838de48706ed5e4ddc1b1042 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 29 Aug 2016 17:37:23 +0530 Subject: Answer saved again after correctly submitted, fixed. Removed javascript that makes user wait for 2 seconds when the code question is correct. All the other html elements are accessible by user during the wait. This also caused the duplicate save during the wait, as they can skip at that point and the answer is saved again. Added a check that if question is already answered then do not save it. This also resolves the monitor(use data) page problem of showing marks obtained zero even when it is correct. Removed skipped answers from the monitor page. --- yaksh/templates/yaksh/question.html | 21 +++++++-------------- yaksh/templates/yaksh/user_data.html | 10 +++++++--- yaksh/views.py | 23 +++++++++++------------ 3 files changed, 25 insertions(+), 29 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 73d851a..9a0f899 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -85,19 +85,6 @@ function call_skip(url) form.action = url form.submit(); } - {% if error_message == 'Correct Output'%} - {% if paper.questions_left %} - window.setTimeout(function() - { - location.href="{{ URL_ROOT }}/exam/{{ paper.current_question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" - }, 2000); - {% else %} - window.setTimeout(function() - { - location.href="{{ URL_ROOT }}/exam/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" - }, 2000); - {% endif %} - {% endif %} {% endblock script %} @@ -165,11 +152,17 @@ function call_skip(url) {% if question.type == "mcq" %} + {% if error_message %} +

{{ error_message }}

+ {% endif %} {% for test_case in test_cases %} {{ test_case.options }}
{% endfor %} {% endif %} {% if question.type == "mcc" %} + {% if error_message %} +

{{ error_message }}

+ {% endif %} {% for test_case in test_cases %} {{ test_case.options }}
@@ -188,7 +181,7 @@ function call_skip(url) {% endif %} - {% if question.type == "mcq" or question.type == "mcc "%} + {% if question.type == "mcq" or question.type == "mcc"%}
   {% elif question.type == "upload" %}
   diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index 04544f9..2e7db50 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -56,11 +56,15 @@ User IP address: {{ paper.user_ip }}

Student answer: {{ answers.0 }}

{% else %}{# non-mcq questions #} -
 
-{% for answer in answers %}################################################################################
+{% for answer in answers %}
+{% if not answer.skipped %}
+
+###############################################################################
 {{ answer.answer.strip }}
 # Autocheck: {{ answer.error }}
-{% endfor %}
+
+{% endif %} +{% endfor %} {% endif %} {% with answers|last as answer %}

Marks: {{answer.marks}}

diff --git a/yaksh/views.py b/yaksh/views.py index 2ee964f..fd47ca5 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -454,6 +454,10 @@ def skip(request, q_id, next_q=None, attempt_num=None, questionpaper_id=None): paper = get_object_or_404(AnswerPaper, user=request.user, attempt_number=attempt_num, question_paper=questionpaper_id) question = get_object_or_404(Question, pk=q_id) + if question in paper.questions_answered.all(): + next_q = paper.next_question(q_id) + return show_question(request, next_q, paper) + if request.method == 'POST' and question.type == 'code': user_code = request.POST.get('answer') new_answer = Answer(question=question, answer=user_code, @@ -506,7 +510,9 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): correct=False) new_answer.save() paper.answers.add(new_answer) - + if not user_answer: + msg = "Please submit a valid option or code" + return show_question(request, question, paper, msg) # If we were not skipped, we were asked to check. For any non-mcq # questions, we obtain the results via XML-RPC with the code executed # safely in a separate process (the code_server.py) running as nobody. @@ -527,17 +533,8 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): new_answer.save() return show_question(request, question, paper, result.get('error')) else: - # Display the same question if user_answer is None - if not user_answer: - msg = "Please submit a valid option or code" - return show_question(request, question, paper, msg) - elif question.type == 'code' and user_answer: - msg = "Correct Output" - paper.completed_question(question.id) - return show_question(request, question, paper, msg) - else: - next_q = paper.completed_question(question.id) - return show_question(request, next_q, paper) + next_q = paper.completed_question(question.id) + return show_question(request, next_q, paper) else: return show_question(request, question, paper) @@ -560,11 +557,13 @@ def validate_answer(user, user_answer, question, json_data=None): expected_answer = question.get_test_case(correct=True).options if user_answer.strip() == expected_answer.strip(): correct = True + result['error'] = 'Correct answer' elif question.type == 'mcc': expected_answers = [] for opt in question.get_test_cases(correct=True): expected_answers.append(opt.options) if set(user_answer) == set(expected_answers): + result['error'] = 'Correct answer' correct = True elif question.type == 'code': user_dir = get_user_dir(user) -- cgit