blob: 0af077831222717e2f587d5409a03f4b50510a6f [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()
Shivam Mishra09cd46f2019-06-06 14:02:49 +053020 if student:
21 course_enrollment = utils.get_or_create_course_enrollment(course, program)
Shivam Mishrad69892a2019-06-05 19:42:30 +053022 contents = topic.get_contents()
23 progress = []
24 if contents:
25 for content in contents:
26 if content.doctype in ('Article', 'Video'):
Shivam Mishra09cd46f2019-06-06 14:02:49 +053027 if student:
28 status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
29 else:
30 status = True
Shivam Mishrad69892a2019-06-05 19:42:30 +053031 progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
32 elif content.doctype == 'Quiz':
Shivam Mishra09cd46f2019-06-06 14:02:49 +053033 if student:
34 status, score, result = utils.check_quiz_completion(content, course_enrollment.name)
35 else:
36 status = False
37 score = None
38 result = None
Shivam Mishrad69892a2019-06-05 19:42:30 +053039 progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
40
41 return progress