From ffd9d56896be90348175c45d628e4ccd9603cb94 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 23:29:56 +0530 Subject: [PATCH] feat: embed pdf --- .../doctype/course_lesson/course_lesson.json | 6 ++-- lms/lms/utils.py | 3 +- lms/plugins.py | 29 ++++++++++++------- lms/www/batch/edit.js | 10 +++++++ lms/www/batch/learn.html | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lms/lms/doctype/course_lesson/course_lesson.json b/lms/lms/doctype/course_lesson/course_lesson.json index dc224a69..3fd75f37 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.json +++ b/lms/lms/doctype/course_lesson/course_lesson.json @@ -23,8 +23,8 @@ "column_break_15", "file_type", "section_break_11", - "instructor_notes", "body", + "instructor_notes", "help_section", "help" ], @@ -135,13 +135,13 @@ }, { "fieldname": "instructor_notes", - "fieldtype": "Text Editor", + "fieldtype": "Text", "label": "Instructor Notes" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-31 11:11:22.034553", + "modified": "2023-08-31 21:47:06.314995", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/lms/lms/utils.py b/lms/lms/utils.py index f101e9f0..5347c2e0 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -147,6 +147,8 @@ def get_lesson_details(chapter): ) lesson_details.number = flt(f"{chapter.idx}.{row.idx}") lesson_details.icon = get_lesson_icon(lesson_details.body) + if lesson_details.instructor_notes: + lesson_details.instructor_notes = markdown_to_html(lesson_details.instructor_notes) lessons.append(lesson_details) return lessons @@ -311,7 +313,6 @@ def render_html(lesson): if lesson.question: assignment = "{{ Assignment('" + lesson.question + "-" + lesson.file_type + "') }}" text = text + assignment - return markdown_to_html(text) diff --git a/lms/plugins.py b/lms/plugins.py index a171e05e..bc763238 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -156,9 +156,17 @@ def youtube_video_renderer(video_id): def embed_renderer(details): + type = details.split("|||")[0] src = details.split("|||")[1] + width = "100%" + height = "400" + + if type == "pdf": + width = "75%" + height = "600" + return f""" - ", }, + pdf: { + regex: /(https?:\/\/.*\.pdf)/, + embedUrl: "<%= remote_id %>", + html: "", + }, }, }, }, @@ -165,6 +170,11 @@ const parse_lesson_to_string = (data) => { } else if (block.type == "paragraph") { lesson_content += `${block.data.text}\n`; } else if (block.type == "embed") { + if (block.data.service == "pdf") { + if (!block.data.embed.startsWith(window.location.origin)) { + frappe.throw(__("Invalid PDF URL")); + } + } lesson_content += `{{ Embed("${ block.data.service }|||${block.data.embed.replace(/&/g, "&")}") }}\n`; diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index 8f44c010..743a01fc 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -157,7 +157,7 @@ {% if lesson.instructor_notes and (is_moderator or instructor or is_evaluator) %}
-
+
{{ _("Instructor Notes") }}