From bfc15cf1a4db7cf19445746c2c9d06c2d9c80e6b Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Fri, 5 Mar 2021 17:18:09 +0000 Subject: [PATCH] Added preview and sections fields to LMS Topic - The preview is used to show the details of the topic in the course page - the sections are used to show the different part of the topic, each could be of a different type Issue #8 --- .../lms/doctype/lms_topic/lms_topic.json | 19 ++++++++++--- community/www/courses/course.html | 4 +-- community/www/courses/course.py | 2 +- community/www/courses/topic.html | 27 +++++++++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/community/lms/doctype/lms_topic/lms_topic.json b/community/lms/doctype/lms_topic/lms_topic.json index 3079aa11..52d00479 100644 --- a/community/lms/doctype/lms_topic/lms_topic.json +++ b/community/lms/doctype/lms_topic/lms_topic.json @@ -7,10 +7,12 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "course", + "preview", "title", "description", - "course", - "order" + "order", + "sections" ], "fields": [ { @@ -37,11 +39,22 @@ "fieldname": "order", "fieldtype": "Int", "label": "Order" + }, + { + "fieldname": "preview", + "fieldtype": "Markdown Editor", + "label": "Preview" + }, + { + "fieldname": "sections", + "fieldtype": "Table", + "label": "Sections", + "options": "LMS Section" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-03-05 12:59:22.817471", + "modified": "2021-03-05 17:08:55.580189", "modified_by": "Administrator", "module": "LMS", "name": "LMS Topic", diff --git a/community/www/courses/course.html b/community/www/courses/course.html index 644e2f41..682b9255 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -32,10 +32,10 @@ {% for topic in course.topics %}
{{topic.title}}
-
{{topic.description}}
+
{{topic.preview | markdown }}
{% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/community/www/courses/course.py b/community/www/courses/course.py index 0bc2dded..5a41858b 100644 --- a/community/www/courses/course.py +++ b/community/www/courses/course.py @@ -17,7 +17,7 @@ def get_course(name): filters={ 'course': name }, - fields=['name', 'title', 'description'], + fields=['name', 'title', 'preview'], order_by='creation' ) return course diff --git a/community/www/courses/topic.html b/community/www/courses/topic.html index 5771c006..d14388c5 100644 --- a/community/www/courses/topic.html +++ b/community/www/courses/topic.html @@ -19,7 +19,30 @@

{{ topic.title }}

-
{{ topic.description }}
+ {% for s in topic.sections %} +
+ {{ render_section(s) }} +
+ {% endfor %} + -{% endblock %} \ No newline at end of file +{% endblock %} + +{% macro render_section(s) %} + {% if s.type == "text" %} + {{ render_section_text(s) }} + {% elif s.type == "code" %} + {{ render_section_code(s) }} + {% else %} +
Unknown section type: {{s.type}}
+ {% endif %} +{% endmacro %} + +{% macro render_section_text(s) %} + {{ s.contents | markdown }} +{% endmacro %} + +{% macro render_section_code(s) %} +
{{s.code}}
+{% endmacro %}