Added function to retrieve quiz data as JSON
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index d55bd1d..809fa9e 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -91,7 +91,7 @@
activity_does_not_exists, activity = check_entry_exists(kwargs.get('program'))
if activity_does_not_exists:
current_activity = frappe.get_doc({
- "doctype": "Student Course Activity",
+ "doctype": "Course Activity",
"student_id": get_student_id(frappe.session.user),
"program_name": kwargs.get('program'),
"lms_activity": [{
@@ -131,13 +131,13 @@
def check_entry_exists(program):
try:
- activity_name = frappe.get_all("Student Course Activity", filters={"student_id": get_student_id(frappe.session.user), "program_name": program})[0]
+ activity_name = frappe.get_all("Course Activity", filters={"student_id": get_student_id(frappe.session.user), "program_name": program})[0]
except IndexError:
print("------ Got No Doc ------")
return True, None
else:
print("------ Got A Doc ------")
- return None, frappe.get_doc("Student Course Activity", activity_name)
+ return None, frappe.get_doc("Course Activity", activity_name)
def get_student_id(email):
"""Returns Student ID, example EDU-STU-2018-00001 from email address
@@ -147,4 +147,25 @@
student = frappe.get_list('Student', filters={'student_email_id': email})[0].name
return student
except IndexError:
- frappe.throw("Student Account with email:{0} does not exist".format(email))
\ No newline at end of file
+ frappe.throw("Student Account with email:{0} does not exist".format(email))
+
+def get_quiz(content):
+ """Helper Function to get questions for a quiz
+
+ :params content: name of a Content doctype with content_type quiz"""
+ try:
+ quiz_doc = frappe.get_doc("Content", content)
+ if quiz_doc.content_type == "Quiz":
+ import json
+ quiz = [frappe.get_doc("Question", item.question_link) for item in quiz_doc.questions]
+ data = []
+ for question in quiz:
+ d = {}
+ d['Options'] = [{'option':item.option,'is_correct':item.is_correct} for item in quiz[0].options]
+ d['Question'] = question.question
+ data.append(d)
+ return json.dumps(data)
+ else:
+ frappe.throw("<b>{0}</b> is not a Quiz".format(content))
+ except frappe.DoesNotExistError:
+ return None
\ No newline at end of file