blob: 684437cbf222f24921a28d871d45824b7ae3253c [file] [log] [blame]
Chillar Anand915b3432021-09-02 16:44:59 +05301
Shivam Mishrad69892a2019-06-05 19:42:30 +05302import frappe
3
Chillar Anand915b3432021-09-02 16:44:59 +05304import erpnext.education.utils as utils
5
Shivam Mishrad69892a2019-06-05 19:42:30 +05306no_cache = 1
7
8def get_context(context):
Shivam Mishra147d5d92019-06-12 16:01:02 +05309 try:
10 course = frappe.form_dict['course']
11 program = frappe.form_dict['program']
12 topic = frappe.form_dict['topic']
13 except KeyError:
14 frappe.local.flags.redirect_location = '/lms'
15 raise frappe.Redirect
Shivam Mishrad69892a2019-06-05 19:42:30 +053016
17 context.program = program
18 context.course = course
19 context.topic = frappe.get_doc("Topic", topic)
20 context.contents = get_contents(context.topic, course, program)
21 context.has_access = utils.allowed_program_access(program)
22
23def get_contents(topic, course, program):
24 student = utils.get_current_student()
Shivam Mishra09cd46f2019-06-06 14:02:49 +053025 if student:
26 course_enrollment = utils.get_or_create_course_enrollment(course, program)
Shivam Mishrad69892a2019-06-05 19:42:30 +053027 contents = topic.get_contents()
28 progress = []
29 if contents:
30 for content in contents:
31 if content.doctype in ('Article', 'Video'):
Shivam Mishra09cd46f2019-06-06 14:02:49 +053032 if student:
33 status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
34 else:
35 status = True
Shivam Mishrad69892a2019-06-05 19:42:30 +053036 progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
37 elif content.doctype == 'Quiz':
Shivam Mishra09cd46f2019-06-06 14:02:49 +053038 if student:
Jannat Pateldcdd3be2021-04-19 10:36:40 +053039 status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name)
Shivam Mishra09cd46f2019-06-06 14:02:49 +053040 else:
41 status = False
42 score = None
43 result = None
Shivam Mishrad69892a2019-06-05 19:42:30 +053044 progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
45
Ankush Menat4551d7d2021-08-19 13:41:10 +053046 return progress