From ba817cda209787e4bc959aac8d16726a8aea1ed9 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 4 Oct 2017 18:58:55 +0530 Subject: Update non-code and non-upload answers instead of creating a new one --- yaksh/models.py | 5 +++++ yaksh/views.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index d9e07fd..0d67397 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1284,6 +1284,11 @@ class AnswerPaper(models.Model): }] return q_a + def get_latest_answer(self,question_id): + all_answers = self.answers.filter(question=question_id) + if all_answers: + return all_answers[0] + def get_questions(self): return self.questions.filter(active=True) diff --git a/yaksh/views.py b/yaksh/views.py index a58b59e..c4ddcd1 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -597,11 +597,17 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): else: user_answer = request.POST.get('answer') if not user_answer: - msg = ["Please submit a valid option or code"] + msg = "Please submit a valid option or code" return show_question( request, current_question, paper, notification=msg ) - new_answer = Answer( + if current_question in paper.get_questions_answered()\ + and current_question.type not in ['code', 'upload']: + new_answer = paper.get_latest_answer(current_question.id) + new_answer.answer = user_answer + new_answer.correct = False + else: + new_answer = Answer( question=current_question, answer=user_answer, correct=False, error=json.dumps([]) ) -- cgit