diff options
author | adityacp | 2017-10-05 16:24:38 +0530 |
---|---|---|
committer | adityacp | 2017-10-06 12:44:34 +0530 |
commit | f30b65e85cba5d3f25b11787530afbee957ce599 (patch) | |
tree | c3ce7f1c53594b8529b23a60493ac448094de2a9 /yaksh/models.py | |
parent | a626f3792d03ccd96a1c49c7096076950d020c5a (diff) | |
download | online_test-f30b65e85cba5d3f25b11787530afbee957ce599.tar.gz online_test-f30b65e85cba5d3f25b11787530afbee957ce599.tar.bz2 online_test-f30b65e85cba5d3f25b11787530afbee957ce599.zip |
Change Answerpaper model method to get shuffled questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 4859d3e..1cc0634 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from datetime import datetime, timedelta import json +import random import ruamel.yaml from ruamel.yaml.scalarstring import PreservedScalarString from ruamel.yaml.comments import CommentedMap @@ -851,6 +852,8 @@ class QuestionPaper(models.Model): questions = self.get_ordered_questions() for question_set in self.random_questions.all(): questions += question_set.get_random_questions() + if self.shuffle_questions: + return self.get_shuffled_questions(questions) return questions def make_answerpaper(self, user, ip, attempt_num): @@ -941,9 +944,14 @@ class QuestionPaper(models.Model): for que_id in que_order: ques.append(self.fixed_questions.get(id=que_id)) else: - ques = self.fixed_questions.all() + ques = list(self.fixed_questions.all()) return ques + def get_shuffled_questions(self, questions): + """Get shuffled questions if auto suffle is enabled""" + random.shuffle(questions) + return questions + def __str__(self): return "Question Paper for " + self.quiz.description |