diff options
author | adityacp | 2017-01-13 09:47:05 +0530 |
---|---|---|
committer | GitHub | 2017-01-13 09:47:05 +0530 |
commit | 0e3e0cdbf322df9b5c8b7da0301cebe71eadcbe9 (patch) | |
tree | 8969f5db3aeb70350e089e97fb5e37bd0e4db1ab /yaksh/models.py | |
parent | 7fb288ffd992c912a8e2288aa97d6c6ceeedf1a1 (diff) | |
parent | 57a5d99c7ed5aed498943686b2c951bdaba3852a (diff) | |
download | online_test-0e3e0cdbf322df9b5c8b7da0301cebe71eadcbe9.tar.gz online_test-0e3e0cdbf322df9b5c8b7da0301cebe71eadcbe9.tar.bz2 online_test-0e3e0cdbf322df9b5c8b7da0301cebe71eadcbe9.zip |
Merge pull request #179 from maheshgudi/mcq_bugfix
Fixed a bug which would mark all MCQ and MCC questions' answers as correct
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d65970b..271ed6d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1059,28 +1059,25 @@ class AnswerPaper(models.Model): For code questions success is True only if the answer is correct. """ - result = {'success': True, 'error': ['Incorrect answer'], 'weight': 0.0} - correct = False + result = {'success': False, 'error': ['Incorrect answer'], 'weight': 0.0} if user_answer is not None: if question.type == 'mcq': expected_answer = question.get_test_case(correct=True).options if user_answer.strip() == expected_answer.strip(): - correct = True + result['success'] = True result['error'] = ['Correct answer'] elif question.type == 'mcc': expected_answers = [] for opt in question.get_test_cases(correct=True): expected_answers.append(opt.options) if set(user_answer) == set(expected_answers): + result['success'] = True result['error'] = ['Correct answer'] - correct = True elif question.type == 'code': user_dir = self.user.profile.get_user_dir() json_result = code_server.run_code(question.language, json_data, user_dir) result = json.loads(json_result) - if result.get('success'): - correct = True - return correct, result + return result def regrade(self, question_id): try: @@ -1105,10 +1102,10 @@ class AnswerPaper(models.Model): answer = user_answer.answer json_data = question.consolidate_answer_data(answer) \ if question.type == 'code' else None - correct, result = self.validate_answer(answer, question, json_data) - user_answer.correct = correct + result = self.validate_answer(answer, question, json_data) + user_answer.correct = result.get('success') user_answer.error = result.get('error') - if correct: + if result.get('success'): user_answer.marks = (question.points * result['weight'] / question.get_maximum_test_case_weight()) \ if question.partial_grading and question.type == 'code' else question.points |