summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorCruiseDevice2019-01-03 16:08:50 +0530
committerCruiseDevice2019-01-28 13:07:02 +0530
commitf72b744db670d88c095200832a638b69f514f55c (patch)
tree0cc697b405fd2123d3c6e727e0c70cfd12e7eed3 /yaksh/models.py
parentae5e8ca5eb5d47afb14ba83e665de6f10e46bdac (diff)
downloadonline_test-f72b744db670d88c095200832a638b69f514f55c.tar.gz
online_test-f72b744db670d88c095200832a638b69f514f55c.tar.bz2
online_test-f72b744db670d88c095200832a638b69f514f55c.zip
Code refactor
- Move get_question_by_index() and get_question_by_type() from views.py to models.py . - Change variable names.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 427b584..98a63b0 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -2091,6 +2091,21 @@ class AnswerPaper(models.Model):
def get_previous_answers(self, question):
return self.answers.filter(question=question).order_by('-id')
+ def get_question_by_index(self, all_ordered_questions, questions_by_type):
+ return [index+1 for index, item in enumerate(all_ordered_questions)
+ if item in set(questions_by_type)]
+
+ def get_questions_by_type(self, all_ordered_questions, objective_types):
+ questions_by_type = []
+ for types in objective_types:
+ for question in all_ordered_questions:
+ if question.type == types:
+ questions_by_type.append(question)
+ return self.get_question_by_index(
+ all_ordered_questions,
+ questions_by_type
+ )
+
def validate_answer(self, user_answer, question, json_data=None, uid=None,
server_port=SERVER_POOL_PORT):
"""