[Major][Breaking] Modified lms.py and utils
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index a13b718..01cd5f3 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -117,16 +117,31 @@
student = frappe.get_doc("Student", student_id)
student.enroll_in_course(course_name=course_name, program_enrollment=get_program_enrollment(program_name))
-def enroll_all_courses_in_program(program_enrollment, student):
- program = frappe.get_doc("Program", program_enrollment.program)
- course_list = [course.course for course in program.get_all_children()]
- for course_name in course_list:
- student.enroll_in_course(course_name=course_name, program_enrollment=program_enrollment.name)
-
def check_activity_exists(enrollment, content_type, content):
activity = frappe.get_all("Course Activity", filters={'enrollment': enrollment, 'content_type': content_type, 'content': content})
return bool(activity)
+def check_content_completion(content_name, content_type, enrollment_name):
+ activity = frappe.get_list("Course Activity", filters={'enrollment': enrollment_name, 'content_type': content_type, 'content': content_name})
+ if activity:
+ return True
+ else:
+ return False
+
+def check_quiz_completion(quiz, enrollment_name):
+ attempts = frappe.get_list("Quiz Activity", filters={'enrollment': enrollment_name, 'quiz': quiz.name}, fields=["name", "activity_date", "score", "status"])
+ status = bool(len(attempts) == quiz.max_attempts)
+ score = None
+ result = None
+ if attempts:
+ if quiz.grading_basis == 'Last Highest Score':
+ attempts = sorted(attempts, key = lambda i: int(i.score), reverse=True)
+ score = attempts[0]['score']
+ result = attempts[0]['status']
+ if result == 'Pass':
+ status = True
+ return status, score, result
+
# def get_home_page(user):
# print("----------------------------------------------------------------------")
# print("Let's do a lot of magic")
diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py
index c0cc6fa..2af6ca9 100644
--- a/erpnext/www/lms.py
+++ b/erpnext/www/lms.py
@@ -147,7 +147,6 @@
utils.create_student()
student = frappe.get_doc("Student", utils.get_current_student())
program_enrollment = student.enroll_in_program(program_name)
- utils.enroll_all_courses_in_program(program_enrollment, student)
return program_name
# Academty Activity
@@ -168,39 +167,15 @@
frappe.db.commit()
def get_course_progress(course_enrollment):
+ student_id = utils.get_current_student()
+ student = frappe.get_doc("Student", student_id)
course = frappe.get_doc('Course', course_enrollment.course)
- contents = course.get_contents()
+ topics = course.get_topics()
progress = []
- for content in contents:
- if content.doctype in ('Article', 'Video'):
- status = check_content_completion(content.name, content.doctype, course_enrollment.name)
- progress.append({'content': content.name, 'content_type': content.doctype, 'is_complete': status})
- elif content.doctype == 'Quiz':
- status, score, result = check_quiz_completion(content, course_enrollment.name)
- progress.append({'content': content.name, 'content_type': content.doctype, 'is_complete': status, 'score': score, 'result': result})
+ for topic in topics:
+ progress.append(student.get_topic_progress(course_enrollment.name, topic))
return progress
-def check_content_completion(content_name, content_type, enrollment_name):
- activity = frappe.get_list("Course Activity", filters={'enrollment': enrollment_name, 'content_type': content_type, 'content': content_name})
- if activity:
- return True
- else:
- return False
-
-def check_quiz_completion(quiz, enrollment_name):
- attempts = frappe.get_list("Quiz Activity", filters={'enrollment': enrollment_name, 'quiz': quiz.name}, fields=["name", "activity_date", "score", "status"])
- status = bool(len(attempts) == quiz.max_attempts)
- score = None
- result = None
- if attempts:
- if quiz.grading_basis == 'Last Highest Score':
- attempts = sorted(attempts, key = lambda i: int(i.score), reverse=True)
- score = attempts[0]['score']
- result = attempts[0]['status']
- if result == 'Pass':
- status = True
- return status, score, result
-
@frappe.whitelist()
def get_course_meta(course_name, program_name):
course_enrollment = utils.get_course_enrollment(course_name)