feat: added topic progress api
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index 96fb4ee..3abb840 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -239,6 +239,25 @@
status, score, result = check_quiz_completion(quiz, course_enrollment)
return {'questions': questions, 'activity': {'is_complete': status, 'score': score, 'result': result}}
+def get_student_topic_details(topic, course_name, program):
+ """
+ Return the porgress of a course in a program as well as the content to continue from.
+ :param topic_name:
+ :param course_name:
+ """
+ student = get_current_student()
+ course_enrollment = get_or_create_course_enrollment(course_name, program)
+ progress = student.get_topic_progress(course_enrollment.name, topic)
+ if not progress:
+ return {'label':'Open', 'indicator': 'blue'}
+ count = sum([activity['is_complete'] for activity in progress])
+ if count == 0:
+ return {'label':'Open', 'indicator': 'blue'}
+ elif count == len(progress):
+ return {'label':'Completed', 'indicator': 'green'}
+ elif count < len(progress):
+ return {'label':'In Progress', 'indicator': 'orange'}
+
def create_student_from_current_user():
user = frappe.get_doc("User", frappe.session.user)
diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html
index ee3b975..199fc16 100644
--- a/erpnext/www/lms/course.html
+++ b/erpnext/www/lms/course.html
@@ -67,9 +67,7 @@
</div>
{% if has_access %}
<div class='card-footer'>
- {% if index==1 %} <span class="indicator green"> Completed </span>
- {% else %} <span class="indicator orange"> Completed </span>
- {% endif %}
+ <span class="indicator {{ progress[topic.name].indicator }}"> {{ progress[topic.name].label }} </span>
</div>
</a>
{% else %}
diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py
index b9aff5c..f59c28c 100644
--- a/erpnext/www/lms/course.py
+++ b/erpnext/www/lms/course.py
@@ -9,5 +9,11 @@
course = frappe.get_doc('Course', frappe.form_dict['name'])
context.program = frappe.form_dict['program']
context.course = course
+
context.topics = course.get_topics()
- context.has_access = utils.allowed_program_access(context.program)
\ No newline at end of file
+ context.has_access = utils.allowed_program_access(context.program)
+ context.progress = get_topic_progress(context.topics, course, context.program)
+
+def get_topic_progress(topics, course, program):
+ progress = {topic.name: utils.get_student_topic_details(topic, course.name, program) for topic in topics}
+ return progress