blob: d2c6da387ddf889b3518fec856551afff97a17ff [file] [log] [blame]
Shivam Mishrad69892a2019-06-05 19:42:30 +05301from __future__ import unicode_literals
2import erpnext.education.utils as utils
3import frappe
4
5no_cache = 1
6
7def get_context(context):
8 course = frappe.form_dict['course']
9 program = frappe.form_dict['program']
10 topic = frappe.form_dict['topic']
11
12 context.program = program
13 context.course = course
14 context.topic = frappe.get_doc("Topic", topic)
15 context.contents = get_contents(context.topic, course, program)
16 context.has_access = utils.allowed_program_access(program)
17
18def get_contents(topic, course, program):
19 student = utils.get_current_student()
20 if not student:
21 return None
22 course_enrollment = utils.get_or_create_course_enrollment(course, program)
23 contents = topic.get_contents()
24 progress = []
25 if contents:
26 for content in contents:
27 if content.doctype in ('Article', 'Video'):
28 status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
29 progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
30 elif content.doctype == 'Quiz':
31 status, score, result = utils.check_quiz_completion(content, course_enrollment.name)
32 progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
33
34 return progress