Added quiz functions

This commit is contained in:
scmmishra 2018-11-01 19:50:47 +05:30 committed by Aditya Hase
parent 7a59f9501e
commit 374184414b

View File

@ -60,4 +60,23 @@ def get_next_content(content, content_type, course):
try: try:
return content_list[current_index + 1] return content_list[current_index + 1]
except IndexError: except IndexError:
return None
def get_quiz_with_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, 'is_correct':option.is_correct} for option in question.options]} for question in quiz]
return quiz_output
except:
frappe.throw("Quiz {0} does not exist".format(quiz_name))
return None
@frappe.whitelist()
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]
return quiz_output
except:
frappe.throw("Quiz {0} does not exist".format(quiz_name))
return None return None