From 38c1baf7195f0e62bd0293fc42f8b6966da23d3f Mon Sep 17 00:00:00 2001 From: scmmishra Date: Fri, 12 Oct 2018 15:22:16 +0530 Subject: [PATCH] Templates: modified routing logic, added data attributes in template Co-authored-by: Chinmay Pai --- erpnext/www/lms/course.html | 9 +- erpnext/www/lms/course.py | 17 ++- erpnext/www/lms/index.html | 2 +- erpnext/www/lms/program.html | 2 +- erpnext/www/lms/program.py | 4 +- .../www/lms/templates/includes/article.html | 8 +- erpnext/www/lms/templates/includes/quiz.html | 106 +++++++++--------- erpnext/www/lms/templates/includes/video.html | 6 +- 8 files changed, 93 insertions(+), 61 deletions(-) diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html index 3acc76e5d0..182efab7d6 100644 --- a/erpnext/www/lms/course.html +++ b/erpnext/www/lms/course.html @@ -8,11 +8,12 @@ {% endblock %} - {% block content %} -{% with current_content = current_content %} +
+{% with current_content = current_content, next_content = next_content, course_name = current_course.name, program=current_program%} {% include "www/lms/templates/includes/" + current_content.content_type.lower() + ".html" %} {% endwith %} +
{% endblock %} \ No newline at end of file diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py index ff7073dc9c..0276102462 100644 --- a/erpnext/www/lms/course.py +++ b/erpnext/www/lms/course.py @@ -3,6 +3,17 @@ import frappe def get_context(context): - context.current_course = frappe.get_doc("Course", frappe.form_dict["course"]) - context.current_content = frappe.get_doc("Content", frappe.form_dict["content"]) - next_content = get_next_content() \ No newline at end of file + if frappe.form_dict['course']: + context.current_course = frappe.get_doc("Course", frappe.form_dict["course"]) + context.current_content = frappe.get_doc("Content", frappe.form_dict["content"]) + context.current_program = frappe.form_dict["program"] + context.next_content = get_next_content(context) + + +def get_next_content(context): + if context.current_course: + course_data = [content_item.content for content_item in context.current_course.course_content] + try: + return course_data[course_data.index(context.current_content.name) + 1] + except IndexError: + return None \ No newline at end of file diff --git a/erpnext/www/lms/index.html b/erpnext/www/lms/index.html index 1974d4f569..444bbde093 100644 --- a/erpnext/www/lms/index.html +++ b/erpnext/www/lms/index.html @@ -13,7 +13,7 @@
- +
{{ program_name }}
{{ description }}
diff --git a/erpnext/www/lms/program.html b/erpnext/www/lms/program.html index 449c040c42..23f2e5c528 100644 --- a/erpnext/www/lms/program.html +++ b/erpnext/www/lms/program.html @@ -22,7 +22,7 @@
diff --git a/erpnext/www/lms/program.py b/erpnext/www/lms/program.py index b6ebcf44d2..c61aee53f6 100644 --- a/erpnext/www/lms/program.py +++ b/erpnext/www/lms/program.py @@ -1,9 +1,11 @@ from __future__ import unicode_literals +from erpnext.education.utils import get_student_name import frappe def get_context(context): - context.program = frappe.get_doc("Program", frappe.form_dict["code"]) + print(get_student_name(frappe.session.user)) + context.program = frappe.get_doc("Program", frappe.form_dict["program"]) context.course_list, context.course_data = get_courses(context) def get_courses(context): diff --git a/erpnext/www/lms/templates/includes/article.html b/erpnext/www/lms/templates/includes/article.html index f9fd6e0036..2ca93fa43b 100644 --- a/erpnext/www/lms/templates/includes/article.html +++ b/erpnext/www/lms/templates/includes/article.html @@ -10,7 +10,11 @@
Previous - Next + {% if next_content != None %} + Next + {% else %} + Finish Course + {% endif %}

@@ -23,7 +27,7 @@
Report a diff --git a/erpnext/www/lms/templates/includes/quiz.html b/erpnext/www/lms/templates/includes/quiz.html index 97a2e6828c..280a17baae 100644 --- a/erpnext/www/lms/templates/includes/quiz.html +++ b/erpnext/www/lms/templates/includes/quiz.html @@ -1,56 +1,62 @@ -{% macro quiz(question, opt1, opt2, opt3, opt4) %} -
-
{{ question }}
-
-
- - -
-
- - -
-
- - -
-
- - -
+{% macro quiz(loop_index, question_id, question, options) %} +
+
{{ loop_index }}{{ question }}
+
+ + {% for option in options %} +
+ + +
+ {% endfor %}
+
{% endmacro %} -
-
\ No newline at end of file diff --git a/erpnext/www/lms/templates/includes/video.html b/erpnext/www/lms/templates/includes/video.html index 77a4e6cc97..6727321dec 100644 --- a/erpnext/www/lms/templates/includes/video.html +++ b/erpnext/www/lms/templates/includes/video.html @@ -13,7 +13,11 @@
Previous - Next + {% if next_content != None %} + Next + {% else %} + Finish Course + {% endif %}