From 1e1f1ad1860b4866b6f30e2a58b05f0e0ee1c8fc Mon Sep 17 00:00:00 2001 From: scmmishra Date: Wed, 24 Oct 2018 16:46:46 +0530 Subject: [PATCH] LMS: Course Completion Status Working --- .../course_enrollment/course_enrollment.json | 36 ++++++++++++++++++- erpnext/education/utils.py | 16 +++++++++ erpnext/www/lms/course.html | 5 --- erpnext/www/lms/course.js | 10 ++++++ erpnext/www/lms/index.html | 5 --- erpnext/www/lms/program.html | 9 +++-- erpnext/www/lms/program.py | 12 ++++++- .../www/lms/templates/includes/lms-nav.html | 2 +- 8 files changed, 77 insertions(+), 18 deletions(-) diff --git a/erpnext/education/doctype/course_enrollment/course_enrollment.json b/erpnext/education/doctype/course_enrollment/course_enrollment.json index 686f2c1c2b..47bb973d5d 100644 --- a/erpnext/education/doctype/course_enrollment/course_enrollment.json +++ b/erpnext/education/doctype/course_enrollment/course_enrollment.json @@ -144,6 +144,40 @@ "set_only_once": 0, "translatable": 0, "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "0", + "fieldname": "completed", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Completed", + "length": 0, + "no_copy": 0, + "options": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 } ], "has_web_view": 0, @@ -156,7 +190,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-10-19 17:46:46.595749", + "modified": "2018-10-24 16:05:02.961543", "modified_by": "Administrator", "module": "Education", "name": "Course Enrollment", diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py index c6ca6ef3c1..f298362fe3 100644 --- a/erpnext/education/utils.py +++ b/erpnext/education/utils.py @@ -99,6 +99,8 @@ def add_quiz_activity(enrollment, quiz, score, answers, quiz_response): @frappe.whitelist() def add_activity(content_type, content, course, program): + if content_type == "Quiz": + pass enrollment = get_course_enrollment(course, frappe.session.user) if check_activity_exists(enrollment['name'], content_type, content): pass @@ -167,4 +169,18 @@ def get_student_id(email=None): return frappe.get_all('Student', filters={'student_email_id': email}, fields=['name'])[0].name except IndexError: frappe.throw("Student with email {0} does not exist".format(email)) + return None + +@frappe.whitelist() +def mark_course_complete(course): + try: + enrollment_name = get_course_enrollment(course, frappe.session.user) + enrollment = frappe.get_doc("Course Enrollment", enrollment_name) + enrollment.completed = 1 + enrollment.save() + pass + except: + import traceback + traceback.print_exc() + frappe.throw("The user is not enrolled for the course {course}".format(course=course)) return None \ No newline at end of file diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html index 11b134dc2c..799480bd37 100644 --- a/erpnext/www/lms/course.html +++ b/erpnext/www/lms/course.html @@ -1,13 +1,8 @@ {% extends "frappe_theme/templates/base.html" %} {% block title %}ERPNext Academy{% endblock %} {% from "templates/includes/media.html" import media %} -{% block head_include %} - - -{% endblock %} {% block content %}
- {% include "www/lms/templates/includes/" + content_type.lower() + ".html" %}
diff --git a/erpnext/www/lms/course.js b/erpnext/www/lms/course.js index d24c0247be..b4eb8f7b73 100644 --- a/erpnext/www/lms/course.js +++ b/erpnext/www/lms/course.js @@ -35,3 +35,13 @@ function addActivity() { } }) } + +function addFinalActivity() { + addActivity() + frappe.call({ + method: "erpnext.education.utils.mark_course_complete", + args: { + "course": $('#content-holder').data('course'), + }, + }) +} diff --git a/erpnext/www/lms/index.html b/erpnext/www/lms/index.html index 444bbde093..c39ee6ea65 100644 --- a/erpnext/www/lms/index.html +++ b/erpnext/www/lms/index.html @@ -3,11 +3,6 @@ {% from "templates/includes/media.html" import media %} -{% block head_include %} - - -{% endblock %} - {% macro featured_card(program_name, description, hero_image, code) %}
diff --git a/erpnext/www/lms/program.html b/erpnext/www/lms/program.html index 00e13cb0ca..bee013672c 100644 --- a/erpnext/www/lms/program.html +++ b/erpnext/www/lms/program.html @@ -1,11 +1,6 @@ {% extends "frappe_theme/templates/base.html" %} {% block title %}ERPNext Academy{% endblock %} -{% block head_include %} - - -{% endblock %} - {% macro course_card(course) %}
@@ -22,7 +17,11 @@
+ {% if not check_complete(course.name) %} Start Course + {% else %} + Complete + {% endif %}
diff --git a/erpnext/www/lms/program.py b/erpnext/www/lms/program.py index 10bdd6b187..a8c9c0efe0 100644 --- a/erpnext/www/lms/program.py +++ b/erpnext/www/lms/program.py @@ -8,4 +8,14 @@ def get_context(context): course_list = program.get_course_list() context.program = program - context.course_list = course_list \ No newline at end of file + context.course_list = course_list + context.check_complete = check_complete + + +def check_complete(course_name): + try: + enrollment = utils.get_course_enrollment(course_name, frappe.session.user) + completed = frappe.get_value('Course Enrollment', enrollment['name'], "completed") + return bool(completed) + except: + return False \ No newline at end of file diff --git a/erpnext/www/lms/templates/includes/lms-nav.html b/erpnext/www/lms/templates/includes/lms-nav.html index 64932f65f7..efd1b8b4ff 100644 --- a/erpnext/www/lms/templates/includes/lms-nav.html +++ b/erpnext/www/lms/templates/includes/lms-nav.html @@ -2,5 +2,5 @@ {% if next_content != None %} Next {% else %} -Finish Course +Finish Course {% endif %} \ No newline at end of file