From d69892abfa9baeeef39db1ec9eb304c62efbcf2f Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 5 Jun 2019 19:42:30 +0530 Subject: [PATCH] feat: added topic page --- erpnext/education/doctype/course/course.json | 14 +- erpnext/education/doctype/topic/topic.json | 363 +++++-------------- erpnext/www/lms/course.html | 8 +- erpnext/www/lms/macros/hero.html | 2 +- erpnext/www/lms/program.html | 4 +- erpnext/www/lms/topic.html | 44 +++ erpnext/www/lms/topic.py | 34 ++ 7 files changed, 177 insertions(+), 292 deletions(-) create mode 100644 erpnext/www/lms/topic.html create mode 100644 erpnext/www/lms/topic.py diff --git a/erpnext/education/doctype/course/course.json b/erpnext/education/doctype/course/course.json index 234b29d421..7d8b07397e 100644 --- a/erpnext/education/doctype/course/course.json +++ b/erpnext/education/doctype/course/course.json @@ -14,7 +14,7 @@ "course_abbreviation", "section_break_6", "topics", - "course_intro", + "description", "hero_image", "assessment", "default_grading_scale", @@ -68,11 +68,6 @@ "label": "Topics", "options": "Course Topic" }, - { - "fieldname": "course_intro", - "fieldtype": "Small Text", - "label": "Course Intro" - }, { "fieldname": "hero_image", "fieldtype": "Attach Image", @@ -94,9 +89,14 @@ "fieldtype": "Table", "label": "Assessment Criteria", "options": "Course Assessment Criteria" + }, + { + "fieldname": "description", + "fieldtype": "Small Text", + "label": "Description" } ], - "modified": "2019-05-20 19:27:09.381482", + "modified": "2019-06-05 18:39:11.870605", "modified_by": "Administrator", "module": "Education", "name": "Course", diff --git a/erpnext/education/doctype/topic/topic.json b/erpnext/education/doctype/topic/topic.json index f47b10d780..6e748fddce 100644 --- a/erpnext/education/doctype/topic/topic.json +++ b/erpnext/education/doctype/topic/topic.json @@ -1,297 +1,104 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "field:topic_code", - "beta": 0, - "creation": "2018-12-12 11:37:39.917760", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "autoname": "field:topic_code", + "creation": "2018-12-12 11:37:39.917760", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "topic_name", + "column_break_2", + "topic_code", + "section_break_4", + "topic_content", + "description", + "hero_image" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "topic_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "topic_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Name", + "reqd": 1 + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "column_break_2", - "fieldtype": "Column Break", - "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, - "length": 0, - "no_copy": 0, - "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 - }, + "fieldname": "column_break_2", + "fieldtype": "Column Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "topic_code", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Code", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, + "fieldname": "topic_code", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Code", + "reqd": 1, "unique": 1 - }, + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "section_break_4", - "fieldtype": "Section Break", - "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, - "length": 0, - "no_copy": 0, - "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 - }, + "fieldname": "section_break_4", + "fieldtype": "Section Break" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "topic_content", - "fieldtype": "Table", - "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": "Topic Content", - "length": 0, - "no_copy": 0, - "options": "Topic Content", - "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 - }, + "fieldname": "topic_content", + "fieldtype": "Table", + "label": "Topic Content", + "options": "Topic Content" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, - "fieldname": "hero_image", - "fieldtype": "Attach Image", - "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": "Hero Image", - "length": 0, - "no_copy": 0, - "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 + "fieldname": "hero_image", + "fieldtype": "Attach Image", + "label": "Hero Image" + }, + { + "fieldname": "description", + "fieldtype": "Small Text", + "label": "Description" } - ], - "has_web_view": 0, - "hide_toolbar": 0, - "idx": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "menu_index": 0, - "modified": "2019-04-09 11:35:34.137040", - "modified_by": "Administrator", - "module": "Education", - "name": "Topic", - "name_case": "", - "owner": "Administrator", + ], + "modified": "2019-06-05 18:38:44.029711", + "modified_by": "Administrator", + "module": "Education", + "name": "Topic", + "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Administrator", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Administrator", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Instructor", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Instructor", + "share": 1, "write": 1 } - ], - "quick_entry": 1, - "read_only": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/www/lms/course.html b/erpnext/www/lms/course.html index 1182eb99da..d046ac8514 100644 --- a/erpnext/www/lms/course.html +++ b/erpnext/www/lms/course.html @@ -36,7 +36,7 @@
{% if has_access %} - + {% else %}
{% endif %} @@ -72,7 +72,7 @@ {% elif progress[topic.name].started %} In Progress {% else %} - Open + Start {% endif %}
@@ -85,11 +85,11 @@ {% block content %}
- {{ hero(course.course_name, course.course_intro, has_access, {'name': 'Program', 'url': '/lms/program?program=' + program }) }} + {{ hero(course.course_name, course.description, has_access, {'name': 'Program', 'url': '/lms/program?program=' + program }) }}
{% for topic in topics %} - {{ card(topic.as_dict(), loop.index, topics|length) }} + {{ card(topic, loop.index, topics|length) }} {% endfor %}
diff --git a/erpnext/www/lms/macros/hero.html b/erpnext/www/lms/macros/hero.html index d9c4059d01..85052e1171 100644 --- a/erpnext/www/lms/macros/hero.html +++ b/erpnext/www/lms/macros/hero.html @@ -2,7 +2,7 @@

{{ title }}

diff --git a/erpnext/www/lms/program.html b/erpnext/www/lms/program.html index 07536daf61..615abd50de 100644 --- a/erpnext/www/lms/program.html +++ b/erpnext/www/lms/program.html @@ -45,7 +45,7 @@ {% endif %}
{{ course.course_name }}
-
{{ course.course_intro or '' }}
+
{{ course.description or '' }}
{% if has_access and progress[course.name] %} {% endif %} diff --git a/erpnext/www/lms/topic.html b/erpnext/www/lms/topic.html new file mode 100644 index 0000000000..bb960075f7 --- /dev/null +++ b/erpnext/www/lms/topic.html @@ -0,0 +1,44 @@ +{% extends "templates/base.html" %} +{% block title %}Topic Title{% endblock %} +{% from "www/lms/macros/hero.html" import hero %} + + +{% macro card(content, index, length) %} + +{% endmacro %} + +{% block content %} +
+ {{ hero(topic.topic_name, topic.description, has_access, {'name': 'Course', 'url': '/lms/course?name=' + course +'&program=' + program}) }} +
+
+ {% for content in contents %} + {{ card(content, loop.index, topic.contents|length) }} + {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/erpnext/www/lms/topic.py b/erpnext/www/lms/topic.py new file mode 100644 index 0000000000..d2c6da387d --- /dev/null +++ b/erpnext/www/lms/topic.py @@ -0,0 +1,34 @@ +from __future__ import unicode_literals +import erpnext.education.utils as utils +import frappe + +no_cache = 1 + +def get_context(context): + course = frappe.form_dict['course'] + program = frappe.form_dict['program'] + topic = frappe.form_dict['topic'] + + context.program = program + context.course = course + context.topic = frappe.get_doc("Topic", topic) + context.contents = get_contents(context.topic, course, program) + context.has_access = utils.allowed_program_access(program) + +def get_contents(topic, course, program): + student = utils.get_current_student() + if not student: + return None + course_enrollment = utils.get_or_create_course_enrollment(course, program) + contents = topic.get_contents() + progress = [] + if contents: + for content in contents: + if content.doctype in ('Article', 'Video'): + status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name) + progress.append({'content': content, 'content_type': content.doctype, 'completed': status}) + elif content.doctype == 'Quiz': + status, score, result = utils.check_quiz_completion(content, course_enrollment.name) + progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result}) + + return progress \ No newline at end of file