From 216031440bfe304ad51013950f49e88258ed9fde Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Mon, 29 Apr 2013 11:05:39 +0530 Subject: Added a separate textarea for non-editable code for snippet feature --- testapp/exam/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testapp/exam') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 5a5f5fe..0767d67 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -476,8 +476,8 @@ def automatic_questionpaper(request, questionpaper_id=None): context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} - return my_render_to_response\( - 'exam/automatic_questionpaper.html', context, + return my_render_to_response\ + ('exam/automatic_questionpaper.html', context, context_instance=RequestContext(request)) else: tags = Tag.objects.all() -- cgit From 71c2ad9ff8adc43f6d576571eceda07758e19ca9 Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Tue, 30 Apr 2013 12:23:37 +0530 Subject: Snippet feature implemented --- testapp/exam/views.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'testapp/exam') 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) -- cgit From 77321c3590301a8550b8b351b6e8bbb382dc8947 Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Mon, 1 Jul 2013 12:48:12 +0530 Subject: made changes as per the comments on pull request --- testapp/exam/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'testapp/exam') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 6c977ee..4956f84 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -695,16 +695,15 @@ def check(request, q_id, questionpaper_id=None): # 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.""" + # 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) - new_answer.save() - paper.answers.add(new_answer) + + 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 -- cgit