From 590227b107b11b767c00a8001b71d9c250f25096 Mon Sep 17 00:00:00 2001 From: scmmishra Date: Thu, 18 Oct 2018 15:44:08 +0530 Subject: [PATCH] LMS: Fixed views for article and video --- erpnext/education/doctype/video/video.json | 4 +- erpnext/www/lms/course.html | 52 +++++++++---------- erpnext/www/lms/course.js | 2 +- erpnext/www/lms/course.py | 36 ++++++++----- erpnext/www/lms/program.html | 4 +- erpnext/www/lms/program.py | 7 ++- .../www/lms/templates/includes/article.html | 23 ++++---- .../www/lms/templates/includes/lms-nav.html | 6 +++ erpnext/www/lms/templates/includes/video.html | 19 +++---- 9 files changed, 80 insertions(+), 73 deletions(-) create mode 100644 erpnext/www/lms/templates/includes/lms-nav.html diff --git a/erpnext/education/doctype/video/video.json b/erpnext/education/doctype/video/video.json index d10f196872..d8c3368d93 100644 --- a/erpnext/education/doctype/video/video.json +++ b/erpnext/education/doctype/video/video.json @@ -54,7 +54,7 @@ "collapsible": 0, "columns": 0, "fieldname": "description", - "fieldtype": "Data", + "fieldtype": "Text Editor", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -185,7 +185,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-10-17 06:57:00.219252", + "modified": "2018-10-18 12:26:47.709081", "modified_by": "Administrator", "module": "Education", "name": "Video", diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html index 5e2e393ffa..9896b017aa 100644 --- a/erpnext/www/lms/course.html +++ b/erpnext/www/lms/course.html @@ -1,45 +1,41 @@ {% extends "frappe_theme/templates/base.html" %} {% block title %}ERPNext Academy{% endblock %} - {% from "templates/includes/media.html" import media %} - {% block head_include %} {% endblock %} - {% block content %} -
-{% with quiz = quiz, current_content = current_content, next_content = next_content, course_name = course_name, program=current_program%} -{% include "www/lms/templates/includes/" + current_content.content_type.lower() + ".html" %} -{% endwith %} +
+ {% with content = current_content, next_content = next_content, course_name = course_name, program_name = program_name %} + {% include "www/lms/templates/includes/" + content_type.lower() + ".html" %} + {% endwith %}
- {% endblock %} \ No newline at end of file diff --git a/erpnext/www/lms/course.js b/erpnext/www/lms/course.js index e8f1dd5d0f..a25d00e471 100644 --- a/erpnext/www/lms/course.js +++ b/erpnext/www/lms/course.js @@ -34,4 +34,4 @@ function addActivity() { "program": $('#content-holder').data('program'), } }) -} \ No newline at end of file +} diff --git a/erpnext/www/lms/course.py b/erpnext/www/lms/course.py index 19e495fab3..9e874273ee 100644 --- a/erpnext/www/lms/course.py +++ b/erpnext/www/lms/course.py @@ -1,23 +1,31 @@ from __future__ import unicode_literals import erpnext.education.utils as utils +from urlparse import urlparse, parse_qs import frappe def get_context(context): if frappe.form_dict['course']: - context.current_content = frappe.get_doc("Content", frappe.form_dict["content"]) - context.course_name = frappe.form_dict["course"] - context.current_course = utils.get_contents_in_course(context.course_name) - context.current_program = frappe.form_dict["program"] - context.next_content = get_next_content(context) - if context.current_content.content_type == "Quiz": - context.questions = utils.get_quiz_as_dict(context.current_content.name) + # Save form_dict variables + program_name = frappe.form_dict["program"] + course_name = frappe.form_dict["course"] + content_name = frappe.form_dict["content"] + content_type = frappe.form_dict["type"] + # Get the required doctypes + current_course = frappe.get_doc("Course", course_name) + current_content = frappe.get_doc(content_type, content_name) -def get_next_content(context): - if context.current_course: - course_data = [content.name for content in context.current_course] - try: - return course_data[course_data.index(context.current_content.name) + 1] - except IndexError: - return None \ No newline at end of file + # Saving context variables for Jinja + context.current_content = current_content + context.course_name = course_name + context.program_name = program_name + context.content_type = content_type + context.next_content_type, context.next_content = get_next_content(content_name, content_type, current_course.get_content_info()) + +def get_next_content(c_name, c_type, content_list): + try: + next = content_list[content_list.index([c_type, c_name]) + 1] + return next[0], next[1] + except IndexError: + return None, None \ No newline at end of file diff --git a/erpnext/www/lms/program.html b/erpnext/www/lms/program.html index 5c1f15994c..00e13cb0ca 100644 --- a/erpnext/www/lms/program.html +++ b/erpnext/www/lms/program.html @@ -11,7 +11,7 @@
-
{{ course.name }}
+
{{ course.course_name }}
Course Content
    @@ -22,7 +22,7 @@
diff --git a/erpnext/www/lms/program.py b/erpnext/www/lms/program.py index c5bf018878..10bdd6b187 100644 --- a/erpnext/www/lms/program.py +++ b/erpnext/www/lms/program.py @@ -4,5 +4,8 @@ import frappe def get_context(context): - context.program = frappe.get_doc("Program", frappe.form_dict["program"]) - context.course_list = utils.get_courses_in_program(frappe.form_dict["program"]) \ No newline at end of file + program = frappe.get_doc("Program", frappe.form_dict["program"]) + course_list = program.get_course_list() + + context.program = program + context.course_list = course_list \ No newline at end of file diff --git a/erpnext/www/lms/templates/includes/article.html b/erpnext/www/lms/templates/includes/article.html index 2ca93fa43b..15835b816f 100644 --- a/erpnext/www/lms/templates/includes/article.html +++ b/erpnext/www/lms/templates/includes/article.html @@ -2,19 +2,15 @@
-

{{ current_content.name }}

+

{{ content.title }}

- 49 Mins - — Published on 28th October 2018. + Published on {{ content.publish_date }}, by {{ content.author }}
- Previous - {% if next_content != None %} - Next - {% else %} - Finish Course - {% endif %} + {% with next_content = next_content, course_name = course_name, program_name = program_name %} + {% include "www/lms/templates/includes/lms-nav.html" %} + {% endwith %}

@@ -23,11 +19,12 @@
- {{ current_content.article_content }} + {{ content.content }}
-