blob: 17fc8f799258f6b70de44aa359ef3a7b503d789c [file] [log] [blame]
Shivam Mishrad69892a2019-06-05 19:42:30 +05301import frappe
2
Chillar Anand915b3432021-09-02 16:44:59 +05303import erpnext.education.utils as utils
4
Shivam Mishrad69892a2019-06-05 19:42:30 +05305no_cache = 1
6
7def get_context(context):
Shivam Mishra147d5d92019-06-12 16:01:02 +05308 try:
9 course = frappe.form_dict['course']
10 program = frappe.form_dict['program']
11 topic = frappe.form_dict['topic']
12 except KeyError:
13 frappe.local.flags.redirect_location = '/lms'
14 raise frappe.Redirect
Shivam Mishrad69892a2019-06-05 19:42:30 +053015
16 context.program = program
17 context.course = course
18 context.topic = frappe.get_doc("Topic", topic)
19 context.contents = get_contents(context.topic, course, program)
20 context.has_access = utils.allowed_program_access(program)
21
22def get_contents(topic, course, program):
23 student = utils.get_current_student()
Shivam Mishra09cd46f2019-06-06 14:02:49 +053024 if student:
25 course_enrollment = utils.get_or_create_course_enrollment(course, program)
Shivam Mishrad69892a2019-06-05 19:42:30 +053026 contents = topic.get_contents()
27 progress = []
28 if contents:
29 for content in contents:
30 if content.doctype in ('Article', 'Video'):
Shivam Mishra09cd46f2019-06-06 14:02:49 +053031 if student:
32 status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
33 else:
34 status = True
Shivam Mishrad69892a2019-06-05 19:42:30 +053035 progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
36 elif content.doctype == 'Quiz':
Shivam Mishra09cd46f2019-06-06 14:02:49 +053037 if student:
Jannat Pateldcdd3be2021-04-19 10:36:40 +053038 status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name)
Shivam Mishra09cd46f2019-06-06 14:02:49 +053039 else:
40 status = False
41 score = None
42 result = None
Shivam Mishrad69892a2019-06-05 19:42:30 +053043 progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
44
Ankush Menat4551d7d2021-08-19 13:41:10 +053045 return progress