diff options
-rw-r--r-- | testapp/exam/views.py | 29 | ||||
-rw-r--r-- | testapp/templates/exam/question.html | 4 |
2 files changed, 22 insertions, 11 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) diff --git a/testapp/templates/exam/question.html b/testapp/templates/exam/question.html index 3506c93..0fe7345 100644 --- a/testapp/templates/exam/question.html +++ b/testapp/templates/exam/question.html @@ -87,9 +87,9 @@ function update_time() {% endfor %} {% else %} - <textarea tabindex=1 rows="7" style="width:750px;margin-bottom:15px;" readonly=yes name="snippet" id="snippet" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt.strip}}{% else %}{% if question.type == "bash" %} #!/bin/bash{% else %}{{ question.snippet }}{% endif %}{% endif %}</textarea> + <textarea tabindex=1 rows="3" style="width:750px;margin-bottom:15px;height:auto;" readonly=yes name="snippet" id="snippet" wrap="off">{% if last_attempt %}{% else %}{% if question.type == "bash" %} #!/bin/bash{% else %}{{ question.snippet }}{% endif %}{% endif %}</textarea> - <textarea tabindex=1 rows="10" style="width:750px;margin-bottom:10px;" name="answer" id="answer" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt.strip}}{% else %}{% if question.type == "bash" %} #!/bin/bash{% else %}{% endif %}{% endif %}</textarea> + <textarea tabindex=1 rows="10" style="width:750px;margin-bottom:10px;" name="answer" id="answer" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt.strip}}{% else %}{% if question.type == "bash" %}{% else %}{% endif %}{% endif %}</textarea> <br> <script type="text/javascript"> |