blob: ebedaf5edafd712af01d35bc4256a403647c938f [file] [log] [blame]
Shivam Mishrad69892a2019-06-05 19:42:30 +05301from __future__ import unicode_literals
Chillar Anand915b3432021-09-02 16:44:59 +05302
Shivam Mishrad69892a2019-06-05 19:42:30 +05303import frappe
4
Chillar Anand915b3432021-09-02 16:44:59 +05305import erpnext.education.utils as utils
6
Shivam Mishrad69892a2019-06-05 19:42:30 +05307no_cache = 1
8
9def get_context(context):
Shivam Mishra147d5d92019-06-12 16:01:02 +053010 try:
11 course = frappe.form_dict['course']
12 program = frappe.form_dict['program']
13 topic = frappe.form_dict['topic']
14 except KeyError:
15 frappe.local.flags.redirect_location = '/lms'
16 raise frappe.Redirect
Shivam Mishrad69892a2019-06-05 19:42:30 +053017
18 context.program = program
19 context.course = course
20 context.topic = frappe.get_doc("Topic", topic)
21 context.contents = get_contents(context.topic, course, program)
22 context.has_access = utils.allowed_program_access(program)
23
24def get_contents(topic, course, program):
25 student = utils.get_current_student()
Shivam Mishra09cd46f2019-06-06 14:02:49 +053026 if student:
27 course_enrollment = utils.get_or_create_course_enrollment(course, program)
Shivam Mishrad69892a2019-06-05 19:42:30 +053028 contents = topic.get_contents()
29 progress = []
30 if contents:
31 for content in contents:
32 if content.doctype in ('Article', 'Video'):
Shivam Mishra09cd46f2019-06-06 14:02:49 +053033 if student:
34 status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
35 else:
36 status = True
Shivam Mishrad69892a2019-06-05 19:42:30 +053037 progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
38 elif content.doctype == 'Quiz':
Shivam Mishra09cd46f2019-06-06 14:02:49 +053039 if student:
Jannat Pateldcdd3be2021-04-19 10:36:40 +053040 status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name)
Shivam Mishra09cd46f2019-06-06 14:02:49 +053041 else:
42 status = False
43 score = None
44 result = None
Shivam Mishrad69892a2019-06-05 19:42:30 +053045 progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
46
Ankush Menat4551d7d2021-08-19 13:41:10 +053047 return progress