diff options
author | prathamesh | 2017-11-10 11:18:58 +0530 |
---|---|---|
committer | prathamesh | 2017-11-10 11:18:58 +0530 |
commit | 886f544ac44d831c7844ca42edb4cb97bc3b6313 (patch) | |
tree | 87e2dff0a1efa36501c4c72969db5a8be6bad975 /yaksh/models.py | |
parent | 2eeddaf3bc2eaf9af3fe3e08caec12ff8bc9071a (diff) | |
parent | cfcb2ed39c724639fe17338e29e327d08ae641b2 (diff) | |
download | online_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.tar.gz online_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.tar.bz2 online_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.zip |
Merge branch 'master' of https://github.com/FOSSEE/online_test into upload_users_csv
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() |