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 | 2b7e158 | 2019-03-29 12:45:08 +0530 | [diff] [blame] | 93 | enrollment = utils.get_course_enrollment(course_name).name |
| 94 | quiz_status = {} |
| 95 | quiz_status['is_complete'], quiz_status['score'], quiz_status['result'] = utils.check_quiz_completion(quiz, enrollment) |
| 96 | 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] |
| 97 | return { 'quizData': quiz_output, 'status': quiz_status} |
| 98 | |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 99 | @frappe.whitelist() |
scmmishra | ab8fc8c | 2019-02-28 16:42:25 +0530 | [diff] [blame] | 100 | def evaluate_quiz(course, quiz_response, quiz_name): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 101 | """LMS Function: Evaluates a simple multiple choice quiz. |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 102 | :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. |
| 103 | """ |
| 104 | import json |
| 105 | quiz_response = json.loads(quiz_response) |
| 106 | quiz = frappe.get_doc("Quiz", quiz_name) |
| 107 | answers, score, status = quiz.evaluate(quiz_response, quiz_name) |
| 108 | |
| 109 | result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()} |
| 110 | result_data = [] |
| 111 | for key in answers: |
| 112 | item = {} |
| 113 | item['question'] = key |
| 114 | item['quiz_result'] = result[key] |
| 115 | try: |
scmmishra | 3d39b88 | 2019-03-27 18:01:14 +0530 | [diff] [blame] | 116 | if isinstance(quiz_response[key], list): |
| 117 | item['selected_option'] = ', '.join(frappe.get_value('Options', res, 'option') for res in quiz_response[key]) |
| 118 | else: |
| 119 | item['selected_option'] = frappe.get_value('Options', quiz_response[key], 'option') |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 120 | except: |
| 121 | item['selected_option'] = "Unattempted" |
| 122 | result_data.append(item) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 123 | |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 124 | add_quiz_activity(course, quiz_name, result_data, score, status) |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 125 | return(score) |
| 126 | |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 127 | def add_quiz_activity(course, quiz_name, result_data, score, status): |
| 128 | if not utils.get_current_student(): |
| 129 | return None |
| 130 | enrollment = utils.get_course_enrollment(course).name |
scmmishra | babb68d | 2018-11-19 16:13:21 +0530 | [diff] [blame] | 131 | quiz_activity = frappe.get_doc({ |
| 132 | "doctype": "Quiz Activity", |
| 133 | "enrollment": enrollment, |
| 134 | "quiz": quiz_name, |
| 135 | "activity_date": frappe.utils.datetime.datetime.now(), |
| 136 | "result": result_data, |
| 137 | "score": score, |
| 138 | "status": status |
scmmishra | 3d39b88 | 2019-03-27 18:01:14 +0530 | [diff] [blame] | 139 | }).insert() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 140 | |
| 141 | @frappe.whitelist() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 142 | def enroll_in_program(program_name): |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 143 | student = utils.get_current_student() |
| 144 | if not student: |
scmmishra | bf9a10f | 2019-03-06 15:45:35 +0530 | [diff] [blame] | 145 | utils.create_student_from_current_user() |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 146 | program_enrollment = student.enroll_in_program(program_name) |
scmmishra | 0a4902f | 2018-11-15 11:16:53 +0530 | [diff] [blame] | 147 | return program_name |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 148 | |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 149 | # Academty Activity |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 150 | @frappe.whitelist() |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 151 | def add_activity(course, content_type, content): |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 152 | if not utils.get_current_student(): |
| 153 | return |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 154 | enrollment = utils.get_course_enrollment(course) |
| 155 | if(utils.check_activity_exists(enrollment.name, content_type, content)): |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 156 | pass |
| 157 | else: |
| 158 | activity = frappe.get_doc({ |
| 159 | "doctype": "Course Activity", |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 160 | "enrollment": enrollment.name, |
scmmishra | 35bf561 | 2018-11-13 16:36:22 +0530 | [diff] [blame] | 161 | "content_type": content_type, |
| 162 | "content": content, |
| 163 | "activity_date": frappe.utils.datetime.datetime.now() |
| 164 | }) |
| 165 | activity.save() |
| 166 | frappe.db.commit() |
| 167 | |
scmmishra | fdbabde | 2018-11-22 15:33:30 +0530 | [diff] [blame] | 168 | @frappe.whitelist() |
scmmishra | d5973fe | 2019-04-22 12:05:22 +0530 | [diff] [blame] | 169 | def get_student_course_details(course_name, program_name): |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 170 | """ |
| 171 | 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] | 172 | :param course_name: |
| 173 | :param program_name: |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 174 | """ |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 175 | student = utils.get_current_student() |
| 176 | if not student: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 177 | return {'flag':'Start Course' } |
scmmishra | fdbabde | 2018-11-22 15:33:30 +0530 | [diff] [blame] | 178 | course_enrollment = utils.get_course_enrollment(course_name) |
scmmishra | b3154ef | 2018-12-06 20:13:20 +0530 | [diff] [blame] | 179 | program_enrollment = utils.get_program_enrollment(program_name) |
| 180 | if not program_enrollment: |
| 181 | return None |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 182 | if not course_enrollment: |
scmmishra | 5c646e6 | 2019-03-18 18:37:26 +0530 | [diff] [blame] | 183 | course_enrollment = utils.enroll_in_course(course_name, program_name) |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 184 | progress = course_enrollment.get_progress(student) |
| 185 | count = sum([activity['is_complete'] for activity in progress]) |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 186 | if count == 0: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 187 | return {'flag':'Start Course'} |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 188 | elif count == len(progress): |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 189 | return {'flag':'Completed'} |
scmmishra | a592f70 | 2018-11-20 18:37:01 +0530 | [diff] [blame] | 190 | elif count < len(progress): |
| 191 | next_item = next(item for item in progress if item['is_complete']==False) |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 192 | return {'flag':'Continue'} |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 193 | |
scmmishra | affbfe7 | 2018-11-26 11:59:25 +0530 | [diff] [blame] | 194 | @frappe.whitelist() |
scmmishra | d78c326 | 2019-04-22 12:06:28 +0530 | [diff] [blame] | 195 | def get_student_topic_details(topic_name, course_name): |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 196 | """ |
| 197 | Return the porgress of a course in a program as well as the content to continue from. |
| 198 | :param topic_name: |
| 199 | :param course_name: |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 200 | """ |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 201 | topic = frappe.get_doc("Topic", topic_name) |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 202 | student = utils.get_current_student() |
| 203 | if not student: |
scmmishra | 000e706 | 2019-03-19 12:30:43 +0530 | [diff] [blame] | 204 | topic_content = topic.get_all_children() |
| 205 | if topic_content: |
| 206 | return {'flag':'Start Course', 'content_type': topic_content[0].content_type, 'content': topic_content[0].content} |
| 207 | else: |
| 208 | return None |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 209 | course_enrollment = utils.get_course_enrollment(course_name) |
scmmishra | de5f71a | 2019-02-28 15:40:49 +0530 | [diff] [blame] | 210 | progress = student.get_topic_progress(course_enrollment.name, topic) |
scmmishra | 3726f8a | 2019-02-28 16:33:53 +0530 | [diff] [blame] | 211 | if not progress: |
| 212 | return { 'flag':'Start Topic', 'content_type': None, 'content': None } |
scmmishra | 7e1678e | 2019-02-26 17:11:01 +0530 | [diff] [blame] | 213 | count = sum([activity['is_complete'] for activity in progress]) |
| 214 | if count == 0: |
scmmishra | de5f71a | 2019-02-28 15:40:49 +0530 | [diff] [blame] | 215 | 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] | 216 | elif count == len(progress): |
| 217 | return {'flag':'Completed', 'content_type': progress[0]['content_type'], 'content': progress[0]['content']} |
| 218 | elif count < len(progress): |
| 219 | next_item = next(item for item in progress if item['is_complete']==False) |
| 220 | return {'flag':'Continue', 'content_type': next_item['content_type'], 'content': next_item['content']} |
| 221 | |
| 222 | @frappe.whitelist() |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 223 | def get_program_progress(program_name): |
scmmishra | 2955851 | 2018-11-26 19:16:54 +0530 | [diff] [blame] | 224 | import math |
scmmishra | affbfe7 | 2018-11-26 11:59:25 +0530 | [diff] [blame] | 225 | program = frappe.get_doc("Program", program_name) |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 226 | program_enrollment = utils.get_program_enrollment(program_name) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 227 | program_progress = {} |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 228 | if not program_enrollment: |
| 229 | return None |
| 230 | else: |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 231 | progress = [] |
scmmishra | 97c994f | 2018-11-26 14:41:15 +0530 | [diff] [blame] | 232 | for course in program.get_all_children(): |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 233 | course_progress = get_student_course_details(course.course, program_name) |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 234 | is_complete = False |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 235 | if course_progress['flag'] == "Completed": |
scmmishra | 201fec3 | 2018-11-26 16:52:45 +0530 | [diff] [blame] | 236 | is_complete = True |
| 237 | 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] | 238 | |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 239 | program_progress['progress'] = progress |
| 240 | program_progress['name'] = program_name |
| 241 | program_progress['program'] = program.program_name |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 242 | |
| 243 | try: |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 244 | 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] | 245 | except ZeroDivisionError: |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 246 | program_progress['percentage'] = 0 |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 247 | |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 248 | return program_progress |
scmmishra | 2955851 | 2018-11-26 19:16:54 +0530 | [diff] [blame] | 249 | |
| 250 | @frappe.whitelist() |
| 251 | def get_joining_date(): |
scmmishra | 9b7ac3e | 2019-03-28 14:47:22 +0530 | [diff] [blame] | 252 | current_student = utils.get_current_student() |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 253 | if current_student: |
scmmishra | 9b7ac3e | 2019-03-28 14:47:22 +0530 | [diff] [blame] | 254 | return student.joining_date |
| 255 | else: |
| 256 | return None |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 257 | |
| 258 | @frappe.whitelist() |
| 259 | def get_quiz_progress(program_name): |
| 260 | program = frappe.get_doc("Program", program_name) |
scmmishra | da39da6 | 2018-12-13 11:51:31 +0530 | [diff] [blame] | 261 | program_enrollment = utils.get_program_enrollment(program_name) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 262 | quiz_progress = frappe._dict() |
scmmishra | 327334a | 2019-04-22 12:03:17 +0530 | [diff] [blame] | 263 | student = utils.get_current_student() |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 264 | if not program_enrollment: |
| 265 | return None |
| 266 | else: |
| 267 | progress_list = [] |
| 268 | for course in program.get_all_children(): |
| 269 | course_enrollment = utils.get_course_enrollment(course.course) |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 270 | course_progress = course_enrollment.get_progress(student) |
| 271 | for progress_item in course_progress: |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 272 | if progress_item['content_type'] == "Quiz": |
scmmishra | 87df23b | 2018-12-09 19:57:12 +0530 | [diff] [blame] | 273 | progress_item['course'] = course.course_name |
scmmishra | 4d10229 | 2018-12-07 17:41:40 +0530 | [diff] [blame] | 274 | progress_list.append(progress_item) |
scmmishra | 209250c | 2019-03-28 14:27:51 +0530 | [diff] [blame] | 275 | if not progress_list: |
| 276 | return None |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 277 | quiz_progress.quiz_attempt = progress_list |
| 278 | quiz_progress.name = program_name |
| 279 | quiz_progress.program = program.program_name |
| 280 | return quiz_progress |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 281 | |
| 282 | |
| 283 | @frappe.whitelist(allow_guest=True) |
| 284 | def get_course_details(course_name): |
| 285 | try: |
scmmishra | 9967d27 | 2019-04-22 12:08:41 +0530 | [diff] [blame] | 286 | course = sfrappe.get_doc('Course', course_name) |
scmmishra | 95bb3c0 | 2019-02-26 16:49:58 +0530 | [diff] [blame] | 287 | return course |
| 288 | except: |
| 289 | return None |
| 290 | |
| 291 | # Functions to get program & course details |
| 292 | @frappe.whitelist(allow_guest=True) |
| 293 | def get_topics(course_name): |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame^] | 294 | try: |
| 295 | course = frappe.get_doc('Course', course_name) |
| 296 | return course.get_topics() |
| 297 | except frappe.DoesNotExistError: |
| 298 | frappe.throw(_("Course {0} does not exist.".format(course_name))) |
scmmishra | 23880ae | 2019-02-27 12:09:57 +0530 | [diff] [blame] | 299 | |
| 300 | @frappe.whitelist() |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame^] | 301 | def get_content(content_type, content): |
scmmishra | 23880ae | 2019-02-27 12:09:57 +0530 | [diff] [blame] | 302 | try: |
scmmishra | 4add826 | 2019-04-22 12:28:13 +0530 | [diff] [blame^] | 303 | return frappe.get_doc(content_type, content) |
| 304 | except frappe.DoesNotExistError: |
| 305 | frappe.throw(_("{0} {1} does not exist.".format(content_type, content))) |