summaryrefslogtreecommitdiff
path: root/testapp/exam/views.py
diff options
context:
space:
mode:
authorHardik Ghaghada2013-04-30 12:23:37 +0530
committerHardik Ghaghada2013-04-30 12:23:37 +0530
commit71c2ad9ff8adc43f6d576571eceda07758e19ca9 (patch)
treef6269b6d2a477b5ea2613998df4caf2c46d57072 /testapp/exam/views.py
parent216031440bfe304ad51013950f49e88258ed9fde (diff)
downloadonline_test-71c2ad9ff8adc43f6d576571eceda07758e19ca9.tar.gz
online_test-71c2ad9ff8adc43f6d576571eceda07758e19ca9.tar.bz2
online_test-71c2ad9ff8adc43f6d576571eceda07758e19ca9.zip
Snippet feature implemented
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r--testapp/exam/views.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 0767d67..6c977ee 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -684,23 +684,34 @@ 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)
-
- # 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)
+
+ 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)
+ new_answer.save()
+ paper.answers.add(new_answer)
+ else:
+ """Add the answer submitted with the Snippet code,
+ regardless of it being correct or not."""
+ answer_check = snippet_code + "\n" + user_answer
+ new_answer = Answer(question=question, answer=answer_check,
+ correct=False)
+ new_answer.save()
+ paper.answers.add(new_answer)
# 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.
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 +719,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 +736,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)