summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2017-10-04 18:38:41 +0530
committerankitjavalkar2017-10-04 18:38:41 +0530
commit1e00b0d30c6bef05ef24d9a1b149986276608afd (patch)
treea90d6772175b356632e78dd9e311352efb164357
parent347cfa08bf8c0200fb088ac374bc9c58a66d9673 (diff)
downloadonline_test-1e00b0d30c6bef05ef24d9a1b149986276608afd.tar.gz
online_test-1e00b0d30c6bef05ef24d9a1b149986276608afd.tar.bz2
online_test-1e00b0d30c6bef05ef24d9a1b149986276608afd.zip
Fix bug to prevent saving a code question answer on skip
-rw-r--r--yaksh/views.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index e6da2fc..a58b59e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -506,12 +506,15 @@ def skip(request, q_id, next_q=None, attempt_num=None, questionpaper_id=None):
question = get_object_or_404(Question, pk=q_id)
if request.method == 'POST' and question.type == 'code':
- user_code = request.POST.get('answer')
- new_answer = Answer(question=question, answer=user_code,
- correct=False, skipped=True,
- error=json.dumps([]))
- new_answer.save()
- paper.answers.add(new_answer)
+ if not paper.answers.filter(question=question, correct=True).exists():
+ user_code = request.POST.get('answer')
+ new_answer = Answer(
+ question=question, answer=user_code,
+ correct=False, skipped=True,
+ error=json.dumps([])
+ )
+ new_answer.save()
+ paper.answers.add(new_answer)
if next_q is not None:
next_q = get_object_or_404(Question, pk=next_q)
else: