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