diff options
author | mahesh | 2017-11-10 03:20:58 +0530 |
---|---|---|
committer | mahesh | 2017-11-10 03:20:58 +0530 |
commit | a3b8e78fec5ab542675ca99949b2810e95536c21 (patch) | |
tree | a2df4edf6bbf91dac70a8940cb4ca1e405e25ccc /yaksh/models.py | |
parent | 0bb6a4984d1e97c50a4e8da9394798c4c9a1e589 (diff) | |
parent | cfcb2ed39c724639fe17338e29e327d08ae641b2 (diff) | |
download | online_test-a3b8e78fec5ab542675ca99949b2810e95536c21.tar.gz online_test-a3b8e78fec5ab542675ca99949b2810e95536c21.tar.bz2 online_test-a3b8e78fec5ab542675ca99949b2810e95536c21.zip |
Merge branch 'master' of https://github.com/fossee/online_test into beautify_assertions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d02b6d6..d698232 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -82,6 +82,8 @@ test_status = ( ('completed', 'Completed'), ) +FIXTURES_DIR_PATH = os.path.join(settings.BASE_DIR, 'yaksh', 'fixtures') + def get_assignment_dir(instance, filename): upload_dir = instance.question_paper.quiz.description.replace(" ", "_") @@ -544,7 +546,7 @@ class Question(models.Model): def create_demo_questions(self, user): zip_file_path = os.path.join( - settings.FIXTURE_DIRS, 'demo_questions.zip' + FIXTURES_DIR_PATH, 'demo_questions.zip' ) files, extract_path = extract_files(zip_file_path) self.read_yaml(extract_path, user, files) @@ -840,6 +842,13 @@ class QuestionPaper(models.Model): objects = QuestionPaperManager() + def get_question_bank(self): + ''' Gets all the questions in the question paper''' + questions = list(self.fixed_questions.all()) + for random_set in self.random_questions.all(): + questions += list(random_set.questions.all()) + return questions + def _create_duplicate_questionpaper(self, quiz): new_questionpaper = QuestionPaper.objects.create(quiz=quiz, shuffle_questions=self.shuffle_questions, @@ -1201,6 +1210,15 @@ class AnswerPaper(models.Model): objects = AnswerPaperManager() + def get_per_question_score(self, question_id): + if question_id not in self.get_questions().values_list('id', flat=True): + return 'NA' + answer = self.get_latest_answer(question_id) + if answer: + return answer.marks + else: + return 0 + def current_question(self): """Returns the current active question to display.""" unanswered_questions = self.questions_unanswered.all() |