Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 1 | |
Shivam Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 2 | import frappe |
| 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | import erpnext.education.utils as utils |
| 5 | |
Shivam Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 6 | no_cache = 1 |
| 7 | |
| 8 | def get_context(context): |
Shivam Mishra | 147d5d9 | 2019-06-12 16:01:02 +0530 | [diff] [blame] | 9 | 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 Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 16 | |
| 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 | |
| 23 | def get_contents(topic, course, program): |
| 24 | student = utils.get_current_student() |
Shivam Mishra | 09cd46f | 2019-06-06 14:02:49 +0530 | [diff] [blame] | 25 | if student: |
| 26 | course_enrollment = utils.get_or_create_course_enrollment(course, program) |
Shivam Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 27 | contents = topic.get_contents() |
| 28 | progress = [] |
| 29 | if contents: |
| 30 | for content in contents: |
| 31 | if content.doctype in ('Article', 'Video'): |
Shivam Mishra | 09cd46f | 2019-06-06 14:02:49 +0530 | [diff] [blame] | 32 | if student: |
| 33 | status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name) |
| 34 | else: |
| 35 | status = True |
Shivam Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 36 | progress.append({'content': content, 'content_type': content.doctype, 'completed': status}) |
| 37 | elif content.doctype == 'Quiz': |
Shivam Mishra | 09cd46f | 2019-06-06 14:02:49 +0530 | [diff] [blame] | 38 | if student: |
Jannat Patel | dcdd3be | 2021-04-19 10:36:40 +0530 | [diff] [blame] | 39 | status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name) |
Shivam Mishra | 09cd46f | 2019-06-06 14:02:49 +0530 | [diff] [blame] | 40 | else: |
| 41 | status = False |
| 42 | score = None |
| 43 | result = None |
Shivam Mishra | d69892a | 2019-06-05 19:42:30 +0530 | [diff] [blame] | 44 | progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result}) |
| 45 | |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 46 | return progress |