scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
scmmishra | babb68d | 2018-11-19 16:13:21 +0530 | [diff] [blame] | 2 | import erpnext.education.utils as utils |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 3 | import frappe |
| 4 | |
scmmishra | 1192529 | 2018-11-20 17:38:01 +0530 | [diff] [blame] | 5 | # LMS Utils to Update State for Vue Store |
| 6 | @frappe.whitelist() |
| 7 | def get_program_enrollments(): |
scmmishra | b3154ef | 2018-12-06 20:13:20 +0530 | [diff] [blame] | 8 | student = utils.get_current_student() |
| 9 | if student == None: |
| 10 | return None |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 11 | return student.get_program_enrollments() |
scmmishra | 1192529 | 2018-11-20 17:38:01 +0530 | [diff] [blame] | 12 | |
| 13 | @frappe.whitelist() |
| 14 | def get_all_course_enrollments(): |
| 15 | student = utils.get_current_student() |
| 16 | if student == None: |
| 17 | return None |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 18 | return student.get_all_course_enrollments() |
scmmishra | 1192529 | 2018-11-20 17:38:01 +0530 | [diff] [blame] | 19 | |
| 20 | # Vue Client Functions |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 21 | @frappe.whitelist(allow_guest=True) |
| 22 | def get_portal_details(): |
scmmishra | babb68d | 2018-11-19 16:13:21 +0530 | [diff] [blame] | 23 | """ |
| 24 | Returns portal details from Education Settings Doctype. This contains the Title and Description for LMS amoung other things. |
| 25 | """ |
scmmishra | c22eef2 | 2019-03-18 15:36:49 +0530 | [diff] [blame] | 26 | from erpnext import get_default_company |
| 27 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 28 | settings = frappe.get_doc("Education Settings") |
scmmishra | c22eef2 | 2019-03-18 15:36:49 +0530 | [diff] [blame] | 29 | title = settings.portal_title or get_default_company() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 30 | description = settings.description |
| 31 | return dict(title=title, description=description) |
| 32 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 33 | @frappe.whitelist(allow_guest=True) |
| 34 | def get_featured_programs(): |
| 35 | featured_program_names = frappe.get_all("Program", filters={"is_published": True, "is_featured": True}) |
| 36 | if featured_program_names: |
scmmishra | da2c90c | 2019-04-22 12:19:39 +0530 | [diff] [blame] | 37 | featured_list = [utils.get_program_and_enrollment_status(program['name']) for program in featured_program_names] |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 38 | return featured_list |
| 39 | else: |
scmmishra | 621cad8 | 2019-03-18 15:40:47 +0530 | [diff] [blame] | 40 | return get_all_programs()[:2] |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 41 | |
scmmishra | 85c2fee | 2018-11-14 14:23:06 +0530 | [diff] [blame] | 42 | @frappe.whitelist(allow_guest=True) |
| 43 | def get_all_programs(): |
| 44 | program_names = frappe.get_all("Program", filters={"is_published": True}) |
| 45 | if program_names: |
scmmishra | da2c90c | 2019-04-22 12:19:39 +0530 | [diff] [blame] | 46 | program_list = [utils.get_program_and_enrollment_status(program['name']) for program in program_names] |
scmmishra | 621cad8 | 2019-03-18 15:40:47 +0530 | [diff] [blame] | 47 | return program_list |
scmmishra | 85c2fee | 2018-11-14 14:23:06 +0530 | [diff] [blame] | 48 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 49 | @frappe.whitelist(allow_guest=True) |
scmmishra | da2c90c | 2019-04-22 12:19:39 +0530 | [diff] [blame] | 50 | def get_program(program_name): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 51 | try: |
scmmishra | da2c90c | 2019-04-22 12:19:39 +0530 | [diff] [blame] | 52 | return frappe.get_doc('Program', program_name) |
| 53 | except frappe.DoesNotExistError: |
| 54 | frappe.throw(_("Program {0} does not exist.".format(program_name))) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 55 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 56 | # Functions to get program & course details |
| 57 | @frappe.whitelist(allow_guest=True) |
| 58 | def get_courses(program_name): |
| 59 | program = frappe.get_doc('Program', program_name) |
| 60 | courses = program.get_course_list() |
scmmishra | fdbabde | 2018-11-22 15:33:30 +0530 | [diff] [blame] | 61 | return courses |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 62 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 63 | @frappe.whitelist() |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 64 | def get_next_content(current_content, current_content_type, topic): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 65 | if frappe.session.user == "Guest": |
| 66 | return None |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 67 | topic = frappe.get_doc("Topic", topic) |
| 68 | content_list = [{'content_type':item.doctype, 'content':item.name} for item in topic.get_contents()] |
| 69 | current_index = content_list.index({'content': current_content, 'content_type': current_content_type}) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 70 | try: |
| 71 | return content_list[current_index + 1] |
| 72 | except IndexError: |
| 73 | return None |
| 74 | |
| 75 | def get_quiz_with_answers(quiz_name): |
| 76 | try: |
| 77 | quiz = frappe.get_doc("Quiz", quiz_name).get_questions() |
| 78 | quiz_output = [{'name':question.name, 'question':question.question, 'options':[{'name': option.name, 'option':option.option, 'is_correct':option.is_correct} for option in question.options]} for question in quiz] |
| 79 | return quiz_output |
| 80 | except: |
| 81 | frappe.throw("Quiz {0} does not exist".format(quiz_name)) |
| 82 | return None |
| 83 | |
| 84 | @frappe.whitelist() |
scmmishra | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 85 | def get_quiz_without_answers(quiz_name, course_name): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 86 | try: |
scmmishra | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 87 | quiz = frappe.get_doc("Quiz", quiz_name) |
| 88 | questions = quiz.get_questions() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 89 | except: |
| 90 | frappe.throw("Quiz {0} does not exist".format(quiz_name)) |
| 91 | return None |
| 92 | |
scmmishra | 3673b25 | 2019-04-22 18:10:19 +0530 | [diff] [blame^] | 93 | if utils.check_super_access(): |
| 94 | quiz_output = [{'name':question.name, 'question':question.question, 'type': question.type, 'options':[{'name': option.name, 'option':option.option} for option in question.options]} for question in questions] |
| 95 | return { 'quizData': quiz_output, 'status': None} |
| 96 | |
scmmishra | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 97 | enrollment = utils.get_course_enrollment(course_name).name |
scmmishra | 66d2392 | 2019-04-22 12:54:43 +0530 | [diff] [blame] | 98 | quiz_progress = {} |
| 99 | quiz_progress['is_complete'], quiz_progress['score'], quiz_progress['result'] = utils.check_quiz_completion(quiz, enrollment) |
scmmishra | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 100 | quiz_output = [{'name':question.name, 'question':question.question, 'type': question.type, 'options':[{'name': option.name, 'option':option.option} for option in question.options]} for question in questions] |
scmmishra | 66d2392 | 2019-04-22 12:54:43 +0530 | [diff] [blame] | 101 | return { 'quizData': quiz_output, 'status': quiz_progress} |
scmmishra | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 102 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 103 | @frappe.whitelist() |
scmmishra | ab8fc8c | 2019-02-28 16:42:25 +0530 | [diff] [blame] | 104 | def evaluate_quiz(course, quiz_response, quiz_name): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 105 | """LMS Function: Evaluates a simple multiple choice quiz. |
scmmishra | 66d2392 | 2019-04-22 12:54:43 +0530 | [diff] [blame] | 106 | :param course: name of the course |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 107 | :param quiz_response: contains user selected choices for a quiz in the form of a string formatted as a dictionary. The function uses `json.loads()` to convert it to a python dictionary. |
scmmishra | 66d2392 | 2019-04-22 12:54:43 +0530 | [diff] [blame] | 108 | :param quiz_name: Name of the quiz attempted |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 109 | """ |
| 110 | import json |
| 111 | quiz_response = json.loads(quiz_response) |
| 112 | quiz = frappe.get_doc("Quiz", quiz_name) |
| 113 | answers, score, status = quiz.evaluate(quiz_response, quiz_name) |
scmmishra | ac8d347 | 2019-04-22 14:30:55 +0530 | [diff] [blame] | 114 | print(answers) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 115 | |
scmmishra | ac8d347 | 2019-04-22 14:30:55 +0530 | [diff] [blame] | 116 | course_enrollment = utils.get_course_enrollment(course) |
| 117 | if course_enrollment: |
| 118 | course_enrollment.add_quiz_activity(quiz_name, quiz_response, answers, score, status) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 119 | |
scmmishra | ac8d347 | 2019-04-22 14:30:55 +0530 | [diff] [blame] | 120 | return score |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 121 | |
| 122 | @frappe.whitelist() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 123 | def enroll_in_program(program_name): |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 124 | student = utils.get_current_student() |
| 125 | if not student: |
scmmishra | 5079e6c | 2019-04-22 14:46:26 +0530 | [diff] [blame] | 126 | student = utils.create_student_from_current_user() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 127 | program_enrollment = student.enroll_in_program(program_name) |
scmmishra | 0a4902f | 2018-11-15 11:16:53 +0530 | [diff] [blame] | 128 | return program_name |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 129 | |
scmmishra | ac8d347 | 2019-04-22 14:30:55 +0530 | [diff] [blame] | 130 | # Academdy Activity |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 131 | @frappe.whitelist() |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 132 | def add_activity(course, content_type, content): |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 133 | if not utils.get_current_student(): |
| 134 | return |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 135 | enrollment = utils.get_course_enrollment(course) |
scmmishra | ac8d347 | 2019-04-22 14:30:55 +0530 | [diff] [blame] | 136 | enrollment.add_activity(content_type, content) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 137 | |
scmmishra | fdbabde | 2018-11-22 15:33:30 +0530 | [diff] [blame] | 138 | @frappe.whitelist() |
scmmishra | d5973fe | 2019-04-22 12:05:22 +0530 | [diff] [blame] | 139 | def get_student_course_details(course_name, program_name): |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 140 | """ |
| 141 | Return the porgress of a course in a program as well as the content to continue from. |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 142 | :param course_name: |
| 143 | :param program_name: |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 144 | """ |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 145 | student = utils.get_current_student() |
| 146 | if not student: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 147 | return {'flag':'Start Course' } |
scmmishra | 3673b25 | 2019-04-22 18:10:19 +0530 | [diff] [blame^] | 148 | |
scmmishra | fdbabde | 2018-11-22 15:33:30 +0530 | [diff] [blame] | 149 | course_enrollment = utils.get_course_enrollment(course_name) |
scmmishra | b3154ef | 2018-12-06 20:13:20 +0530 | [diff] [blame] | 150 | program_enrollment = utils.get_program_enrollment(program_name) |
scmmishra | 3673b25 | 2019-04-22 18:10:19 +0530 | [diff] [blame^] | 151 | |
scmmishra | b3154ef | 2018-12-06 20:13:20 +0530 | [diff] [blame] | 152 | if not program_enrollment: |
| 153 | return None |
scmmishra | 3673b25 | 2019-04-22 18:10:19 +0530 | [diff] [blame^] | 154 | |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 155 | if not course_enrollment: |
scmmishra | 5c646e6 | 2019-03-18 18:37:26 +0530 | [diff] [blame] | 156 | course_enrollment = utils.enroll_in_course(course_name, program_name) |
scmmishra | 3673b25 | 2019-04-22 18:10:19 +0530 | [diff] [blame^] | 157 | |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 158 | progress = course_enrollment.get_progress(student) |
| 159 | count = sum([activity['is_complete'] for activity in progress]) |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 160 | if count == 0: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 161 | return {'flag':'Start Course'} |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 162 | elif count == len(progress): |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 163 | return {'flag':'Completed'} |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 164 | elif count < len(progress): |
| 165 | next_item = next(item for item in progress if item['is_complete']==False) |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 166 | return {'flag':'Continue'} |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 167 | |
scmmishra | affbfe7 | 2018-11-26 11:59:25 +0530 | [diff] [blame] | 168 | @frappe.whitelist() |
scmmishra | d78c326 | 2019-04-22 12:06:28 +0530 | [diff] [blame] | 169 | def get_student_topic_details(topic_name, course_name): |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 170 | """ |
| 171 | Return the porgress of a course in a program as well as the content to continue from. |
| 172 | :param topic_name: |
| 173 | :param course_name: |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 174 | """ |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 175 | topic = frappe.get_doc("Topic", topic_name) |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 176 | student = utils.get_current_student() |
| 177 | if not student: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 178 | topic_content = topic.get_all_children() |
| 179 | if topic_content: |
| 180 | return {'flag':'Start Course', 'content_type': topic_content[0].content_type, 'content': topic_content[0].content} |
| 181 | else: |
| 182 | return None |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 183 | course_enrollment = utils.get_course_enrollment(course_name) |
scmmishra | de5f71a | 2019-02-28 15:40:49 +0530 | [diff] [blame] | 184 | progress = student.get_topic_progress(course_enrollment.name, topic) |
scmmishra | 3726f8a | 2019-02-28 16:33:53 +0530 | [diff] [blame] | 185 | if not progress: |
| 186 | return { 'flag':'Start Topic', 'content_type': None, 'content': None } |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 187 | count = sum([activity['is_complete'] for activity in progress]) |
| 188 | if count == 0: |
scmmishra | de5f71a | 2019-02-28 15:40:49 +0530 | [diff] [blame] | 189 | return {'flag':'Start Topic', 'content_type': progress[0]['content_type'], 'content': progress[0]['content']} |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 190 | elif count == len(progress): |
| 191 | return {'flag':'Completed', 'content_type': progress[0]['content_type'], 'content': progress[0]['content']} |
| 192 | elif count < len(progress): |
| 193 | next_item = next(item for item in progress if item['is_complete']==False) |
| 194 | return {'flag':'Continue', 'content_type': next_item['content_type'], 'content': next_item['content']} |
| 195 | |
| 196 | @frappe.whitelist() |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 197 | def get_program_progress(program_name): |
scmmishra | 2955851 | 2018-11-26 19:16:54 +0530 | [diff] [blame] | 198 | import math |
scmmishra | affbfe7 | 2018-11-26 11:59:25 +0530 | [diff] [blame] | 199 | program = frappe.get_doc("Program", program_name) |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 200 | program_enrollment = utils.get_program_enrollment(program_name) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 201 | program_progress = {} |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 202 | if not program_enrollment: |
| 203 | return None |
| 204 | else: |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 205 | progress = [] |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 206 | for course in program.get_all_children(): |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 207 | course_progress = get_student_course_details(course.course, program_name) |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 208 | is_complete = False |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 209 | if course_progress['flag'] == "Completed": |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 210 | is_complete = True |
| 211 | progress.append({'course_name': course.course_name, 'name': course.course, 'is_complete': is_complete}) |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 212 | |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 213 | program_progress['progress'] = progress |
| 214 | program_progress['name'] = program_name |
| 215 | program_progress['program'] = program.program_name |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 216 | |
| 217 | try: |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 218 | program_progress['percentage'] = math.ceil((sum([item['is_complete'] for item in progress] * 100)/len(progress))) |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 219 | except ZeroDivisionError: |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 220 | program_progress['percentage'] = 0 |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 221 | |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 222 | return program_progress |
scmmishra | 2955851 | 2018-11-26 19:16:54 +0530 | [diff] [blame] | 223 | |
| 224 | @frappe.whitelist() |
| 225 | def get_joining_date(): |
scmmishra | 5079e6c | 2019-04-22 14:46:26 +0530 | [diff] [blame] | 226 | student = utils.get_current_student() |
| 227 | if student: |
scmmishra | 9b7ac3e | 2019-03-28 14:47:22 +0530 | [diff] [blame] | 228 | return student.joining_date |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 229 | |
| 230 | @frappe.whitelist() |
| 231 | def get_quiz_progress(program_name): |
| 232 | program = frappe.get_doc("Program", program_name) |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 233 | program_enrollment = utils.get_program_enrollment(program_name) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 234 | quiz_progress = frappe._dict() |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 235 | student = utils.get_current_student() |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 236 | if not program_enrollment: |
| 237 | return None |
| 238 | else: |
| 239 | progress_list = [] |
| 240 | for course in program.get_all_children(): |
| 241 | course_enrollment = utils.get_course_enrollment(course.course) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 242 | course_progress = course_enrollment.get_progress(student) |
| 243 | for progress_item in course_progress: |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 244 | if progress_item['content_type'] == "Quiz": |
scmmishra | 87df23b | 2018-12-09 19:57:12 +0530 | [diff] [blame] | 245 | progress_item['course'] = course.course_name |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 246 | progress_list.append(progress_item) |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 247 | if not progress_list: |
| 248 | return None |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 249 | quiz_progress.quiz_attempt = progress_list |
| 250 | quiz_progress.name = program_name |
| 251 | quiz_progress.program = program.program_name |
| 252 | return quiz_progress |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 253 | |
| 254 | |
| 255 | @frappe.whitelist(allow_guest=True) |
| 256 | def get_course_details(course_name): |
| 257 | try: |
scmmishra | 64d2fe0 | 2019-04-22 12:30:08 +0530 | [diff] [blame] | 258 | course = frappe.get_doc('Course', course_name) |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 259 | return course |
| 260 | except: |
| 261 | return None |
| 262 | |
| 263 | # Functions to get program & course details |
| 264 | @frappe.whitelist(allow_guest=True) |
| 265 | def get_topics(course_name): |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame] | 266 | try: |
| 267 | course = frappe.get_doc('Course', course_name) |
| 268 | return course.get_topics() |
| 269 | except frappe.DoesNotExistError: |
| 270 | frappe.throw(_("Course {0} does not exist.".format(course_name))) |
scmmishra | 23880ae | 2019-02-27 12:09:57 +0530 | [diff] [blame] | 271 | |
| 272 | @frappe.whitelist() |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame] | 273 | def get_content(content_type, content): |
scmmishra | 23880ae | 2019-02-27 12:09:57 +0530 | [diff] [blame] | 274 | try: |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame] | 275 | return frappe.get_doc(content_type, content) |
| 276 | except frappe.DoesNotExistError: |
| 277 | frappe.throw(_("{0} {1} does not exist.".format(content_type, content))) |