summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/models.py10
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