From ff5fc201bf7f44a6dc9d6d93fee7bc0ce47d1be2 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 24 Feb 2015 11:21:48 +0530 Subject: On skip the answer will be saved. The user answer will be retrieved when the same question is loaded again later. --- testapp/exam/models.py | 3 +++ testapp/exam/views.py | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'testapp') diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 88ba9ef..0ad6021 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -105,6 +105,9 @@ class Answer(models.Model): # Is the answer correct. correct = models.BooleanField(default=False) + # Whether skipped or not. + skipped = models.BooleanField(default=False) + def __unicode__(self): return self.answer diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 8d7dd18..576405f 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -743,6 +743,10 @@ def question(request, q_id, attempt_no, questionpaper_id, success_msg=None): context = {'question': q, 'questions' : questions, 'paper': paper, 'user': user, 'quiz_name': quiz_name, 'time_left': time_left, 'success_msg': success_msg, 'to_attempt' : to_attempt, 'submitted' : submitted} + if q.type == 'code': + skipped_answer = paper.answers.filter(question=q, skipped=True) + if skipped_answer: + context['last_attempt'] = skipped_answer[0].answer ci = RequestContext(request) return my_render_to_response('exam/question.html', context, context_instance=ci) @@ -768,10 +772,23 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): return my_redirect('/exam/login/') question = get_object_or_404(Question, pk=q_id) snippet_code = request.POST.get('snippet') + user_code = request.POST.get('answer') skip = request.POST.get('skip', None) success_msg = False success = True if skip is not None: + if question.type == 'code': + user_answer = user_code # not taking snippet here. + old_skipped = paper.answers.filter(question=question, skipped=True) + if old_skipped: + skipped_answer = old_skipped[0] + skipped_answer.answer=user_answer + skipped_answer.save() + else: + skipped_answer = Answer(question=question, answer=user_answer, + correct=False, skipped=True) + skipped_answer.save() + paper.answers.add(skipped_answer) next_q = paper.skip() return show_question(request, next_q, attempt_no, questionpaper_id) @@ -788,7 +805,6 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): assign.save() user_answer = 'ASSIGNMENT UPLOADED' else: - user_code = request.POST.get('answer') user_answer = snippet_code + "\n" + user_code new_answer = Answer(question=question, answer=user_answer, @@ -839,6 +855,10 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): for num, value in enumerate(all_questions, 1): questions[value] = num questions = collections.OrderedDict(sorted(questions.items())) + old_answer = paper.answers.filter(question=question, skipped=True) + if old_answer: + old_answer[0].answer = user_code + old_answer[0].save() context = {'question': question, 'questions': questions, 'error_message': err_msg, 'paper': paper, 'last_attempt': user_code, -- cgit From da7014b32635f47d0fd66931ce5961e54f82ae94 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 24 Feb 2015 14:13:38 +0530 Subject: Answer is now saved from the question navigator as well --- testapp/exam/templates/exam/question.html | 20 ++++++++++++++------ testapp/exam/views.py | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html index 96e7bd6..5d03b37 100644 --- a/testapp/exam/templates/exam/question.html +++ b/testapp/exam/templates/exam/question.html @@ -48,7 +48,12 @@ function setSnippetHeight() ta.style.height = height; autoresize(); } - +function call_skip(url) +{ + form = document.forms["code"] + form.action = url + form.submit(); +} {% endblock script %} @@ -82,17 +87,18 @@ function setSnippetHeight() +