From a105a1d3b4d3574a93625ac4b5b88dbab936c721 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 30 Sep 2021 15:04:19 +0530 Subject: [PATCH] fix: removed chapter and lesson links --- community/lms/doctype/chapter/chapter.json | 2 +- .../doctype/course_chapter/course_chapter.js | 12 ++- .../course_chapter/course_chapter.json | 2 +- .../doctype/course_lesson/course_lesson.js | 55 ++++++++++- .../doctype/course_lesson/course_lesson.json | 2 +- .../doctype/course_lesson/course_lesson.py | 92 ++++++++++++++++++- community/lms/doctype/lesson/lesson.py | 4 +- .../lms/doctype/lms_course/lms_course.py | 2 +- .../lms_course_progress.json | 4 +- community/lms/doctype/lms_quiz/lms_quiz.json | 4 +- community/patches.txt | 2 - community/www/batch/learn.html | 2 +- community/www/batch/learn.py | 9 -- 13 files changed, 163 insertions(+), 29 deletions(-) diff --git a/community/lms/doctype/chapter/chapter.json b/community/lms/doctype/chapter/chapter.json index 9bc525ed..5e0559dd 100644 --- a/community/lms/doctype/chapter/chapter.json +++ b/community/lms/doctype/chapter/chapter.json @@ -83,4 +83,4 @@ "sort_order": "DESC", "title_field": "title", "track_changes": 1 -} \ No newline at end of file +} diff --git a/community/lms/doctype/course_chapter/course_chapter.js b/community/lms/doctype/course_chapter/course_chapter.js index f23a53a8..9e24b54d 100644 --- a/community/lms/doctype/course_chapter/course_chapter.js +++ b/community/lms/doctype/course_chapter/course_chapter.js @@ -2,7 +2,13 @@ // For license information, please see license.txt frappe.ui.form.on('Course Chapter', { - // refresh: function(frm) { - - // } + onload: function (frm) { + frm.set_query("lesson", "lessons", function () { + return { + filters: { + "chapter": frm.doc.name, + } + }; + }); + } }); diff --git a/community/lms/doctype/course_chapter/course_chapter.json b/community/lms/doctype/course_chapter/course_chapter.json index b33baa69..7ebf90b4 100644 --- a/community/lms/doctype/course_chapter/course_chapter.json +++ b/community/lms/doctype/course_chapter/course_chapter.json @@ -58,7 +58,7 @@ "link_fieldname": "chapter" } ], - "modified": "2021-09-29 15:33:44.611223", + "modified": "2021-09-29 15:33:44.611228", "modified_by": "Administrator", "module": "LMS", "name": "Course Chapter", diff --git a/community/lms/doctype/course_lesson/course_lesson.js b/community/lms/doctype/course_lesson/course_lesson.js index 66699dfa..0ff38a3c 100644 --- a/community/lms/doctype/course_lesson/course_lesson.js +++ b/community/lms/doctype/course_lesson/course_lesson.js @@ -2,7 +2,56 @@ // For license information, please see license.txt frappe.ui.form.on('Course Lesson', { - // refresh: function(frm) { + setup: function (frm) { + frm.trigger('setup_help'); + }, + setup_help(frm) { + frm.get_field('help').html(` +

You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.

+
+
+ Content Type +
+
+ Syntax +
+
- // } -}); +
+
+ Video +
+
+ {{ Video("url_of_source") }} +
+
+ +
+
+ YouTube Video +
+
+ {{ YouTubeVideo("unique_embed_id") }} +
+
+ +
+
+ Exercise +
+
+ {{ Exercise("exercise_name") }} +
+
+ +
+
+ Quiz +
+
+ {{ Quiz("lms_quiz_name") }} +
+
+ `); + } + }); diff --git a/community/lms/doctype/course_lesson/course_lesson.json b/community/lms/doctype/course_lesson/course_lesson.json index 77d54405..c154c620 100644 --- a/community/lms/doctype/course_lesson/course_lesson.json +++ b/community/lms/doctype/course_lesson/course_lesson.json @@ -71,7 +71,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-29 15:28:51.418013", + "modified": "2021-09-29 15:28:51.418015", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/community/lms/doctype/course_lesson/course_lesson.py b/community/lms/doctype/course_lesson/course_lesson.py index c6be9e00..25427c87 100644 --- a/community/lms/doctype/course_lesson/course_lesson.py +++ b/community/lms/doctype/course_lesson/course_lesson.py @@ -1,8 +1,96 @@ +# -*- coding: utf-8 -*- # Copyright (c) 2021, FOSS United and contributors # For license information, please see license.txt -# import frappe +from __future__ import unicode_literals +import frappe from frappe.model.document import Document +from ...md import markdown_to_html, find_macros class CourseLesson(Document): - pass + def on_update(self): + dynamic_documents = ["Exercise", "Quiz"] + for section in dynamic_documents: + self.update_lesson_name_in_document(section) + + def update_lesson_name_in_document(self, section): + doctype_map= { + "Exercise": "Exercise", + "Quiz": "LMS Quiz" + } + macros = find_macros(self.body) + documents = [value for name, value in macros if name == section] + index = 1 + for name in documents: + e = frappe.get_doc(doctype_map[section], name) + e.lesson = self.name + e.index_ = index + e.save() + index += 1 + self.update_orphan_documents(doctype_map[section], documents) + + def update_orphan_documents(self, doctype, documents): + """Updates the documents that were previously part of this lesson, + but not any more. + """ + linked_documents = {row['name'] for row in frappe.get_all(doctype, {"lesson": self.name})} + active_documents = set(documents) + orphan_documents = linked_documents - active_documents + for name in orphan_documents: + ex = frappe.get_doc(doctype, name) + ex.lesson = None + ex.index_ = 0 + ex.index_label = "" + ex.save() + + def render_html(self): + print(self.body) + return markdown_to_html(self.body) + + def get_exercises(self): + if not self.body: + return [] + + macros = find_macros(self.body) + exercises = [value for name, value in macros if name == "Exercise"] + return [frappe.get_doc("Exercise", name) for name in exercises] + + def get_progress(self): + return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status") + + def get_slugified_class(self): + if self.get_progress(): + return ("").join([ s for s in self.get_progress().lower().split() ]) + return + +@frappe.whitelist() +def save_progress(lesson, course, status): + if not frappe.db.exists("LMS Batch Membership", + { + "member": frappe.session.user, + "course": course + }): + return + + if frappe.db.exists("LMS Course Progress", + { + "lesson": lesson, + "owner": frappe.session.user, + "course": course + }): + doc = frappe.get_doc("LMS Course Progress", + { + "lesson": lesson, + "owner": frappe.session.user, + "course": course + }) + doc.status = status + doc.save(ignore_permissions=True) + else: + frappe.get_doc({ + "doctype": "LMS Course Progress", + "lesson": lesson, + "status": status, + }).save(ignore_permissions=True) + course_details = frappe.get_doc("LMS Course", course) + return course_details.get_course_progress() diff --git a/community/lms/doctype/lesson/lesson.py b/community/lms/doctype/lesson/lesson.py index 9fe2de50..cc315a91 100644 --- a/community/lms/doctype/lesson/lesson.py +++ b/community/lms/doctype/lesson/lesson.py @@ -44,6 +44,7 @@ class Lesson(Document): ex.save() def render_html(self): + print(self.body) return markdown_to_html(self.body) def get_exercises(self): @@ -55,7 +56,8 @@ class Lesson(Document): return [frappe.get_doc("Exercise", name) for name in exercises] def get_progress(self): - return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status") + return frappe.db.get_value("LMS Course Progress", + {"lesson": self.name, "owner": frappe.session.user}, "status") def get_slugified_class(self): if self.get_progress(): diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index 97c8ad10..5a60f38c 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -179,7 +179,7 @@ class LMSCourse(Document): lesson_list = frappe.get_all("Lesson Reference", {"parent": chapter.name}, ["lesson", "idx"], order_by="idx") for row in lesson_list: - lesson_details = frappe.get_doc("Lesson", row.lesson) + lesson_details = frappe.get_doc("Course Lesson", row.lesson) lesson_details.number = flt("{}.{}".format(chapter.idx, row.idx)) lessons.append(lesson_details) return lessons diff --git a/community/lms/doctype/lms_course_progress/lms_course_progress.json b/community/lms/doctype/lms_course_progress/lms_course_progress.json index db1772ab..78452c69 100644 --- a/community/lms/doctype/lms_course_progress/lms_course_progress.json +++ b/community/lms/doctype/lms_course_progress/lms_course_progress.json @@ -36,7 +36,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Lesson", - "options": "Lesson" + "options": "Course Lesson" }, { "fieldname": "status", @@ -53,7 +53,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-29 15:26:43.911664", + "modified": "2021-09-30 13:07:54.246863", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course Progress", diff --git a/community/lms/doctype/lms_quiz/lms_quiz.json b/community/lms/doctype/lms_quiz/lms_quiz.json index a1af03f2..837e8ead 100644 --- a/community/lms/doctype/lms_quiz/lms_quiz.json +++ b/community/lms/doctype/lms_quiz/lms_quiz.json @@ -28,13 +28,13 @@ "fieldname": "lesson", "fieldtype": "Link", "label": "Lesson", - "options": "Lesson", + "options": "Course Lesson", "read_only": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-20 10:44:15.930892", + "modified": "2021-09-30 13:10:06.929357", "modified_by": "Administrator", "module": "LMS", "name": "LMS Quiz", diff --git a/community/patches.txt b/community/patches.txt index e6d2fcb5..8f7cf33c 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -6,10 +6,8 @@ community.patches.replace_member_with_user_in_batch_membership community.patches.replace_member_with_user_in_course_mentor_mapping community.patches.replace_member_with_user_in_lms_message community.patches.replace_member_with_user_in_mentor_request -community.patches.v0_0.chapter_lesson_index_table execute:frappe.delete_doc("DocType", "LMS Message") community.patches.v0_0.course_instructor_update execute:frappe.delete_doc("DocType", "Discussion Message") execute:frappe.delete_doc("DocType", "Discussion Thread") -community.patches.v0_0.rename_chapters_and_lessons_doctype community.patches.v0_0.rename_chapter_and_lesson_doctype #29-09-2021 diff --git a/community/www/batch/learn.html b/community/www/batch/learn.html index 4ff7a10e..b4c40e0c 100644 --- a/community/www/batch/learn.html +++ b/community/www/batch/learn.html @@ -112,7 +112,7 @@ {% set is_instructor = frappe.session.user == course.instructor %} {% set title = lesson.title + " - " + course.title %} {% set condition = is_instructor if is_instructor else membership %} -{{ widgets.DiscussionMessage(doctype="Lesson", docname=lesson.name, +{{ widgets.DiscussionMessage(doctype="Course Lesson", docname=lesson.name, condition=condition, button_name="Start Learning", redirect_to="/courses/" + course.name) }} {% endmacro %} diff --git a/community/www/batch/learn.py b/community/www/batch/learn.py index 52fdddaf..fd48f30c 100644 --- a/community/www/batch/learn.py +++ b/community/www/batch/learn.py @@ -48,15 +48,6 @@ def get_current_lesson_details(lesson_number, context): def get_learn_url(lesson_number, course): return course.get_learn_url(lesson_number) and course.get_learn_url(lesson_number) + course.query_parameter -def get_chapter_title(course_name, lesson_number): - if not lesson_number: - return - lesson_split = cstr(lesson_number).split(".") - chapter_index = lesson_split[0] - lesson_index = lesson_split[1] - chapter_name = frappe.db.get_value("Chapter", {"course": course_name, "index_": chapter_index}, "name") - return frappe.db.get_value("Lesson", {"chapter": chapter_name, "index_": lesson_index}, "title") - def get_lesson_index(course, batch, user): lesson = batch.get_current_lesson(user) return lesson and course.get_lesson_index(lesson)