diff --git a/erpnext/education/doctype/question/question.py b/erpnext/education/doctype/question/question.py index 57d8de4d651..8cd23983ce9 100644 --- a/erpnext/education/doctype/question/question.py +++ b/erpnext/education/doctype/question/question.py @@ -14,20 +14,20 @@ class Question(Document): self.check_minimum_one_correct_answer() def check_at_least_one_option(self): - if len(self.get_all_children()) <= 1: + if len(self.options) <= 1: frappe.throw(_("A question must have more than one options")) else: pass def check_minimum_one_correct_answer(self): - correct_options = [question.is_correct for question in self.get_all_children()] + correct_options = [option.is_correct for option in self.options] if bool(sum(correct_options)): pass else: frappe.throw(_("A qustion must have at least one correct options")) def get_answer(self): - options = self.get_all_children() + options = self.options answers = [item.name for item in options if item.is_correct == True] if len(answers) == 0: frappe.throw("No correct answer is set for {0}".format(self.name)) diff --git a/erpnext/education/doctype/quiz/quiz.py b/erpnext/education/doctype/quiz/quiz.py index 2c436925880..4bd7cad453b 100644 --- a/erpnext/education/doctype/quiz/quiz.py +++ b/erpnext/education/doctype/quiz/quiz.py @@ -40,7 +40,13 @@ class Quiz(Document): def get_questions(self): quiz_question = self.get_all_children() if quiz_question: - questions = [frappe.get_doc('Question', question.question_link) for question in quiz_question] + questions = [frappe.get_doc('Question', question.question_link).as_dict() for question in quiz_question] + for question in questions: + correct_options = [option.is_correct for option in question.options] + if sum(correct_options) > 1: + question['type'] = "MultipleChoice" + else: + question['type'] = "SingleChoice" return questions else: return None diff --git a/erpnext/public/js/education/lms/components/Quiz.vue b/erpnext/public/js/education/lms/components/Quiz.vue index 41f5f3a81ef..afb61860f5e 100644 --- a/erpnext/public/js/education/lms/components/Quiz.vue +++ b/erpnext/public/js/education/lms/components/Quiz.vue @@ -10,7 +10,7 @@
- +
@@ -40,6 +40,8 @@ diff --git a/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue b/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue new file mode 100644 index 00000000000..e216a678d59 --- /dev/null +++ b/erpnext/public/js/education/lms/components/Quiz/QuizMultipleChoice.vue @@ -0,0 +1,28 @@ + + + + + diff --git a/erpnext/public/js/education/lms/components/Quiz/QuizSingleChoice.vue b/erpnext/public/js/education/lms/components/Quiz/QuizSingleChoice.vue index f3ccf47f825..560f3f06795 100644 --- a/erpnext/public/js/education/lms/components/Quiz/QuizSingleChoice.vue +++ b/erpnext/public/js/education/lms/components/Quiz/QuizSingleChoice.vue @@ -18,7 +18,7 @@ export default { name: 'QuizSingleChoice', methods: { emitResponse(q, o) { - this.$emit('updateResponse', {'question':q , 'option': o}) + this.$emit('updateResponse', {'question':q , 'option': o, 'type': this.question.type}) } } }; diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py index 46c2cbcbf14..c7b31ee09d8 100644 --- a/erpnext/www/lms.py +++ b/erpnext/www/lms.py @@ -96,7 +96,7 @@ def get_quiz_with_answers(quiz_name): def get_quiz_without_answers(quiz_name): try: quiz = frappe.get_doc("Quiz", quiz_name).get_questions() - quiz_output = [{'name':question.name, 'question':question.question, 'options':[{'name': option.name, 'option':option.option} for option in question.options]} for question in quiz] + quiz_output = [{'name':question.name, 'question':question.question, 'type': question.type, 'options':[{'name': option.name, 'option':option.option} for option in question.options]} for question in quiz] return quiz_output except: frappe.throw("Quiz {0} does not exist".format(quiz_name))