summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
authorHardik Ghaghada2013-07-01 13:03:42 +0530
committerHardik Ghaghada2013-07-01 13:03:42 +0530
commit1ab56ae99e06500fe89aeb571f05527d745cf9bd (patch)
tree4c0f0b7a3271e2f95c47d2bdb6e16a89859e1292 /testapp/exam
parent2e2123067d2477602d5e05fab02b7d36396f2d1f (diff)
parent77321c3590301a8550b8b351b6e8bbb382dc8947 (diff)
downloadonline_test-1ab56ae99e06500fe89aeb571f05527d745cf9bd.tar.gz
online_test-1ab56ae99e06500fe89aeb571f05527d745cf9bd.tar.bz2
online_test-1ab56ae99e06500fe89aeb571f05527d745cf9bd.zip
resolved conflicts
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/views.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 1d5d6f6..4c47004 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -684,14 +684,24 @@ def check(request, q_id, questionpaper_id=None):
question = get_object_or_404(Question, pk=q_id)
q_paper = QuestionPaper.objects.get(id=questionpaper_id)
paper = AnswerPaper.objects.get(user=request.user, question_paper=q_paper)
- answer = request.POST.get('answer')
+ snippet_code = request.POST.get('snippet')
+ user_answer = request.POST.get('answer')
skip = request.POST.get('skip', None)
if skip is not None:
next_q = paper.skip()
return show_question(request, next_q, questionpaper_id)
+
+ if question.type == 'mcq':
+ # Add the answer submitted, regardless of it being correct or not.
+ new_answer = Answer(question=question, answer=user_answer,
+ correct=False)
+
+ else:
+ # Add the answer submitted with the Snippet code (correct or incorrect)
+ answer_check = snippet_code + "\n" + user_answer
+ new_answer = Answer(question=question, answer=answer_check,
+ correct=False)
- # Add the answer submitted, regardless of it being correct or not.
- new_answer = Answer(question=question, answer=answer, correct=False)
new_answer.save()
paper.answers.add(new_answer)
@@ -700,7 +710,7 @@ def check(request, q_id, questionpaper_id=None):
# safely in a separate process (the code_server.py) running as nobody.
if question.type == 'mcq':
success = True # Only one attempt allowed for MCQ's.
- if answer.strip() == question.test.strip():
+ if user_answer.strip() == question.test.strip():
new_answer.correct = True
new_answer.marks = question.points
new_answer.error = 'Correct answer'
@@ -708,7 +718,7 @@ def check(request, q_id, questionpaper_id=None):
new_answer.error = 'Incorrect answer'
else:
user_dir = get_user_dir(user)
- success, err_msg = code_server.run_code(answer, question.test,
+ success, err_msg = code_server.run_code(answer_check, question.test,
user_dir, question.type)
new_answer.error = err_msg
if success:
@@ -725,7 +735,7 @@ def check(request, q_id, questionpaper_id=None):
if not paper.question_paper.quiz.active:
return complete(request, reason='The quiz has been deactivated!')
context = {'question': question, 'error_message': err_msg,
- 'paper': paper, 'last_attempt': answer,
+ 'paper': paper, 'last_attempt': user_answer,
'quiz_name': paper.question_paper.quiz.description,
'time_left': time_left}
ci = RequestContext(request)