From dc877a9c09d4af5fae224cbab7c2b9107002b82e Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 29 Sep 2021 16:42:07 +0530 Subject: [PATCH 1/6] fix: renamed chapter and lesson doctype --- .../lms/doctype/course_chapter/__init__.py | 0 .../doctype/course_chapter/course_chapter.js | 8 ++ .../course_chapter/course_chapter.json | 86 ++++++++++++++++ .../doctype/course_chapter/course_chapter.py | 8 ++ .../course_chapter/test_course_chapter.py | 8 ++ .../lms/doctype/course_lesson/__init__.py | 0 .../doctype/course_lesson/course_lesson.js | 8 ++ .../doctype/course_lesson/course_lesson.json | 97 +++++++++++++++++++ .../doctype/course_lesson/course_lesson.py | 8 ++ .../course_lesson/test_course_lesson.py | 8 ++ community/lms/doctype/exercise/exercise.json | 4 +- .../exercise_submission.json | 4 +- .../lms_batch_membership.json | 4 +- .../lms_course_progress.json | 4 +- community/patches.txt | 1 + .../v0_0/rename_chapter_and_lesson_doctype.py | 30 ++++++ 16 files changed, 270 insertions(+), 8 deletions(-) create mode 100644 community/lms/doctype/course_chapter/__init__.py create mode 100644 community/lms/doctype/course_chapter/course_chapter.js create mode 100644 community/lms/doctype/course_chapter/course_chapter.json create mode 100644 community/lms/doctype/course_chapter/course_chapter.py create mode 100644 community/lms/doctype/course_chapter/test_course_chapter.py create mode 100644 community/lms/doctype/course_lesson/__init__.py create mode 100644 community/lms/doctype/course_lesson/course_lesson.js create mode 100644 community/lms/doctype/course_lesson/course_lesson.json create mode 100644 community/lms/doctype/course_lesson/course_lesson.py create mode 100644 community/lms/doctype/course_lesson/test_course_lesson.py create mode 100644 community/patches/v0_0/rename_chapter_and_lesson_doctype.py diff --git a/community/lms/doctype/course_chapter/__init__.py b/community/lms/doctype/course_chapter/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/community/lms/doctype/course_chapter/course_chapter.js b/community/lms/doctype/course_chapter/course_chapter.js new file mode 100644 index 00000000..f23a53a8 --- /dev/null +++ b/community/lms/doctype/course_chapter/course_chapter.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, FOSS United and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Course Chapter', { + // refresh: function(frm) { + + // } +}); diff --git a/community/lms/doctype/course_chapter/course_chapter.json b/community/lms/doctype/course_chapter/course_chapter.json new file mode 100644 index 00000000..2956fbe9 --- /dev/null +++ b/community/lms/doctype/course_chapter/course_chapter.json @@ -0,0 +1,86 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "CHP.", + "creation": "2021-05-03 05:49:08.383057", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "course", + "title", + "column_break_3", + "description", + "section_break_5", + "lessons" + ], + "fields": [ + { + "fieldname": "course", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Course", + "options": "LMS Course", + "reqd": 1 + }, + { + "fieldname": "title", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Title", + "reqd": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "description", + "fieldtype": "Small Text", + "label": "Description" + }, + { + "fieldname": "section_break_5", + "fieldtype": "Section Break" + }, + { + "fieldname": "lessons", + "fieldtype": "Table", + "label": "Lessons", + "options": "Lesson Reference" + } + ], + "index_web_pages_for_search": 1, + "links": [ + { + "group": "Lessons", + "link_doctype": "Course Lesson", + "link_fieldname": "chapter" + } + ], + "modified": "2021-09-29 15:33:44.611221", + "modified_by": "Administrator", + "module": "LMS", + "name": "Course Chapter", + "naming_rule": "Expression", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "search_fields": "title", + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "title", + "track_changes": 1 +} diff --git a/community/lms/doctype/course_chapter/course_chapter.py b/community/lms/doctype/course_chapter/course_chapter.py new file mode 100644 index 00000000..9556f2ae --- /dev/null +++ b/community/lms/doctype/course_chapter/course_chapter.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CourseChapter(Document): + pass diff --git a/community/lms/doctype/course_chapter/test_course_chapter.py b/community/lms/doctype/course_chapter/test_course_chapter.py new file mode 100644 index 00000000..d14cd9fd --- /dev/null +++ b/community/lms/doctype/course_chapter/test_course_chapter.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and Contributors +# See license.txt + +# import frappe +import unittest + +class TestCourseChapter(unittest.TestCase): + pass diff --git a/community/lms/doctype/course_lesson/__init__.py b/community/lms/doctype/course_lesson/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/community/lms/doctype/course_lesson/course_lesson.js b/community/lms/doctype/course_lesson/course_lesson.js new file mode 100644 index 00000000..66699dfa --- /dev/null +++ b/community/lms/doctype/course_lesson/course_lesson.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, FOSS United and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Course Lesson', { + // refresh: function(frm) { + + // } +}); diff --git a/community/lms/doctype/course_lesson/course_lesson.json b/community/lms/doctype/course_lesson/course_lesson.json new file mode 100644 index 00000000..03606e82 --- /dev/null +++ b/community/lms/doctype/course_lesson/course_lesson.json @@ -0,0 +1,97 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "LES.", + "creation": "2021-05-03 06:21:12.995987", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "chapter", + "include_in_preview", + "column_break_4", + "title", + "index_label", + "section_break_6", + "body", + "help_section", + "help" + ], + "fields": [ + { + "fieldname": "chapter", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Chapter", + "options": "Course Chapter", + "reqd": 1 + }, + { + "default": "0", + "fieldname": "include_in_preview", + "fieldtype": "Check", + "label": "Include In Preview" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "title", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Title", + "reqd": 1 + }, + { + "fieldname": "index_label", + "fieldtype": "Data", + "label": "Index Label", + "read_only": 1 + }, + { + "fieldname": "section_break_6", + "fieldtype": "Section Break" + }, + { + "fieldname": "body", + "fieldtype": "Markdown Editor", + "label": "Body", + "reqd": 1 + }, + { + "fieldname": "help_section", + "fieldtype": "Section Break", + "label": "Help" + }, + { + "fieldname": "help", + "fieldtype": "HTML" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-09-29 15:28:51.418015", + "modified_by": "Administrator", + "module": "LMS", + "name": "Course Lesson", + "naming_rule": "Expression", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} diff --git a/community/lms/doctype/course_lesson/course_lesson.py b/community/lms/doctype/course_lesson/course_lesson.py new file mode 100644 index 00000000..c6be9e00 --- /dev/null +++ b/community/lms/doctype/course_lesson/course_lesson.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CourseLesson(Document): + pass diff --git a/community/lms/doctype/course_lesson/test_course_lesson.py b/community/lms/doctype/course_lesson/test_course_lesson.py new file mode 100644 index 00000000..c5c40a94 --- /dev/null +++ b/community/lms/doctype/course_lesson/test_course_lesson.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and Contributors +# See license.txt + +# import frappe +import unittest + +class TestCourseLesson(unittest.TestCase): + pass diff --git a/community/lms/doctype/exercise/exercise.json b/community/lms/doctype/exercise/exercise.json index e7f0ea7c..67530594 100644 --- a/community/lms/doctype/exercise/exercise.json +++ b/community/lms/doctype/exercise/exercise.json @@ -78,7 +78,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Lesson", - "options": "Lesson" + "options": "Course Lesson" }, { "fieldname": "index_", @@ -96,7 +96,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-06-01 05:22:15.656013", + "modified": "2021-09-29 15:27:55.585874", "modified_by": "Administrator", "module": "LMS", "name": "Exercise", diff --git a/community/lms/doctype/exercise_submission/exercise_submission.json b/community/lms/doctype/exercise_submission/exercise_submission.json index 125af148..229e9de6 100644 --- a/community/lms/doctype/exercise_submission/exercise_submission.json +++ b/community/lms/doctype/exercise_submission/exercise_submission.json @@ -53,7 +53,7 @@ "fieldname": "lesson", "fieldtype": "Link", "label": "Lesson", - "options": "Lesson" + "options": "Course Lesson" }, { "fieldname": "image", @@ -94,7 +94,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-06-24 16:22:50.570845", + "modified": "2021-09-29 15:27:57.273879", "modified_by": "Administrator", "module": "LMS", "name": "Exercise Submission", diff --git a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json index 3a0bfa0c..7a6a8497 100644 --- a/community/lms/doctype/lms_batch_membership/lms_batch_membership.json +++ b/community/lms/doctype/lms_batch_membership/lms_batch_membership.json @@ -72,7 +72,7 @@ "fieldname": "current_lesson", "fieldtype": "Link", "label": "Current Lesson", - "options": "Lesson" + "options": "Course Lesson" }, { "fetch_from": "member.username", @@ -84,7 +84,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-08-04 17:10:42.708479", + "modified": "2021-09-29 15:27:58.765399", "modified_by": "Administrator", "module": "LMS", "name": "LMS Batch Membership", 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 33d785f6..db1772ab 100644 --- a/community/lms/doctype/lms_course_progress/lms_course_progress.json +++ b/community/lms/doctype/lms_course_progress/lms_course_progress.json @@ -28,7 +28,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Chapter", - "options": "Chapter", + "options": "Course Chapter", "read_only": 1 }, { @@ -53,7 +53,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-06-02 13:05:31.114939", + "modified": "2021-09-29 15:26:43.911664", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course Progress", diff --git a/community/patches.txt b/community/patches.txt index 0ab8479a..9d729b93 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -12,3 +12,4 @@ 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 #25-09-2021 diff --git a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py new file mode 100644 index 00000000..b0b544a6 --- /dev/null +++ b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py @@ -0,0 +1,30 @@ +import frappe + +def execute(): + frappe.reload_doc("lms", "doctype", "course_chapter") + frappe.reload_doc("lms", "doctype", "course_lesson") + + if not frappe.db.count("Course Chapter"): + move_chapters() + + if not frappe.db.count("Course Lesson"): + move_lessons() + + frappe.delete_doc("DocType", "Chapter") + frappe.delete_doc("DocType", "Lesson") + +def move_chapters(): + docs = frappe.get_all("Chapter", fields=["*"]) + for doc in docs: + keys = doc + keys.update({"doctype": "Course Chapter"}) + del keys["name"] + frappe.get_doc(keys).save() + +def move_lessons(): + docs = frappe.get_all("Lesson", fields=["*"]) + for doc in docs: + keys = doc + keys.update({"doctype": "Course Lesson"}) + del keys["name"] + frappe.get_doc(keys).save() From ddffc8372b879bbee19da2e4c5f79ea38088944a Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 29 Sep 2021 17:55:08 +0530 Subject: [PATCH 2/6] fix: condition to check course and chapter --- community/patches.txt | 2 +- .../v0_0/rename_chapter_and_lesson_doctype.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/community/patches.txt b/community/patches.txt index 9d729b93..e386940b 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -12,4 +12,4 @@ 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 #25-09-2021 +community.patches.v0_0.rename_chapter_and_lesson_doctype #26-09-2021 diff --git a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py index b0b544a6..b6863b6f 100644 --- a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py +++ b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py @@ -16,15 +16,17 @@ def execute(): def move_chapters(): docs = frappe.get_all("Chapter", fields=["*"]) for doc in docs: - keys = doc - keys.update({"doctype": "Course Chapter"}) - del keys["name"] - frappe.get_doc(keys).save() + if frappe.db.exists("LMS Course", doc.course): + keys = doc + keys.update({"doctype": "Course Chapter"}) + del keys["name"] + frappe.get_doc(keys).save() def move_lessons(): docs = frappe.get_all("Lesson", fields=["*"]) for doc in docs: - keys = doc - keys.update({"doctype": "Course Lesson"}) - del keys["name"] - frappe.get_doc(keys).save() + if frappe.db.exists("Chapter", doc.chapter): + keys = doc + keys.update({"doctype": "Course Lesson"}) + del keys["name"] + frappe.get_doc(keys).save() From b3840e056f9c011b120163b657a5a74ee333494f Mon Sep 17 00:00:00 2001 From: pateljannat Date: Wed, 29 Sep 2021 19:37:37 +0530 Subject: [PATCH 3/6] fix: naming series --- community/lms/doctype/course_chapter/course_chapter.json | 4 ++-- community/lms/doctype/course_lesson/course_lesson.json | 6 +++--- community/patches.txt | 2 +- community/patches/v0_0/rename_chapter_and_lesson_doctype.py | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/community/lms/doctype/course_chapter/course_chapter.json b/community/lms/doctype/course_chapter/course_chapter.json index 2956fbe9..63ce8e87 100644 --- a/community/lms/doctype/course_chapter/course_chapter.json +++ b/community/lms/doctype/course_chapter/course_chapter.json @@ -1,8 +1,8 @@ { "actions": [], "allow_rename": 1, - "autoname": "CHP.", - "creation": "2021-05-03 05:49:08.383057", + "autoname": "format:{####} {title}", + "creation": "2021-05-03 05:49:08.383050", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", diff --git a/community/lms/doctype/course_lesson/course_lesson.json b/community/lms/doctype/course_lesson/course_lesson.json index 03606e82..bacf3f47 100644 --- a/community/lms/doctype/course_lesson/course_lesson.json +++ b/community/lms/doctype/course_lesson/course_lesson.json @@ -1,8 +1,8 @@ { "actions": [], "allow_rename": 1, - "autoname": "LES.", - "creation": "2021-05-03 06:21:12.995987", + "autoname": "format:{####} {title}", + "creation": "2021-05-03 06:21:12.995981", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -22,7 +22,7 @@ "fieldname": "chapter", "fieldtype": "Link", "in_list_view": 1, - "label": "Chapter", + "label": "Course Chapter", "options": "Course Chapter", "reqd": 1 }, diff --git a/community/patches.txt b/community/patches.txt index e386940b..7651b808 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -12,4 +12,4 @@ 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 #26-09-2021 +community.patches.v0_0.rename_chapter_and_lesson_doctype #27-09-2021 diff --git a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py index b6863b6f..f86d5f2b 100644 --- a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py +++ b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py @@ -25,8 +25,10 @@ def move_chapters(): def move_lessons(): docs = frappe.get_all("Lesson", fields=["*"]) for doc in docs: + print(frappe.db.exists("Chapter", doc.chapter)) if frappe.db.exists("Chapter", doc.chapter): keys = doc + print(doc) keys.update({"doctype": "Course Lesson"}) del keys["name"] frappe.get_doc(keys).save() From 5488947922babcb824d91f3ad868e2cf714377bb Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 30 Sep 2021 11:27:27 +0530 Subject: [PATCH 4/6] fix: rename parenttype for lesson reference --- .../chapter_reference/chapter_reference.json | 4 +-- .../course_chapter/course_chapter.json | 4 +-- .../doctype/course_lesson/course_lesson.json | 4 +-- .../lesson_reference/lesson_reference.json | 4 +-- .../lms/doctype/lms_course/lms_course.json | 4 +-- .../lms/doctype/lms_course/lms_course.py | 4 +-- community/lms/workspace/lms/lms.json | 4 +-- community/patches.txt | 2 +- .../v0_0/rename_chapter_and_lesson_doctype.py | 30 +++++++++++-------- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/community/lms/doctype/chapter_reference/chapter_reference.json b/community/lms/doctype/chapter_reference/chapter_reference.json index 7c63fbcf..a251b1a4 100644 --- a/community/lms/doctype/chapter_reference/chapter_reference.json +++ b/community/lms/doctype/chapter_reference/chapter_reference.json @@ -13,14 +13,14 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Chapter", - "options": "Chapter", + "options": "Course Chapter", "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-07-27 16:25:02.903245", + "modified": "2021-09-30 10:35:30.014950", "modified_by": "Administrator", "module": "LMS", "name": "Chapter Reference", diff --git a/community/lms/doctype/course_chapter/course_chapter.json b/community/lms/doctype/course_chapter/course_chapter.json index 63ce8e87..b33baa69 100644 --- a/community/lms/doctype/course_chapter/course_chapter.json +++ b/community/lms/doctype/course_chapter/course_chapter.json @@ -2,7 +2,7 @@ "actions": [], "allow_rename": 1, "autoname": "format:{####} {title}", - "creation": "2021-05-03 05:49:08.383050", + "creation": "2021-05-03 05:49:08.383058", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -58,7 +58,7 @@ "link_fieldname": "chapter" } ], - "modified": "2021-09-29 15:33:44.611221", + "modified": "2021-09-29 15:33:44.611223", "modified_by": "Administrator", "module": "LMS", "name": "Course Chapter", diff --git a/community/lms/doctype/course_lesson/course_lesson.json b/community/lms/doctype/course_lesson/course_lesson.json index bacf3f47..77d54405 100644 --- a/community/lms/doctype/course_lesson/course_lesson.json +++ b/community/lms/doctype/course_lesson/course_lesson.json @@ -2,7 +2,7 @@ "actions": [], "allow_rename": 1, "autoname": "format:{####} {title}", - "creation": "2021-05-03 06:21:12.995981", + "creation": "2021-05-03 06:21:12.995984", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -71,7 +71,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-29 15:28:51.418015", + "modified": "2021-09-29 15:28:51.418013", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/community/lms/doctype/lesson_reference/lesson_reference.json b/community/lms/doctype/lesson_reference/lesson_reference.json index d7a0dc3a..a3e77ebb 100644 --- a/community/lms/doctype/lesson_reference/lesson_reference.json +++ b/community/lms/doctype/lesson_reference/lesson_reference.json @@ -13,14 +13,14 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Lesson", - "options": "Lesson", + "options": "Course Lesson", "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-08-31 10:44:42.048232", + "modified": "2021-09-30 10:35:47.832547", "modified_by": "Administrator", "module": "LMS", "name": "Lesson Reference", diff --git a/community/lms/doctype/lms_course/lms_course.json b/community/lms/doctype/lms_course/lms_course.json index 30a8475b..d2718857 100644 --- a/community/lms/doctype/lms_course/lms_course.json +++ b/community/lms/doctype/lms_course/lms_course.json @@ -148,7 +148,7 @@ "links": [ { "group": "Chapters", - "link_doctype": "Chapter", + "link_doctype": "Course Chapter", "link_fieldname": "course" }, { @@ -167,7 +167,7 @@ "link_fieldname": "course" } ], - "modified": "2021-09-20 12:00:18.325579", + "modified": "2021-09-30 10:36:48.759994", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index d2805505..97c8ad10 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -153,7 +153,7 @@ class LMSCourse(Document): """ chapters = [] for row in self.chapters: - chapter_details = frappe.db.get_value("Chapter", row.chapter, + chapter_details = frappe.db.get_value("Course Chapter", row.chapter, ["name", "title", "description"], as_dict=True) chapter_details.idx = row.idx @@ -217,7 +217,7 @@ class LMSCourse(Document): if not lesson: return None - chapter = frappe.db.get_value("Chapters", {"chapter": lesson.parent}, ["idx"], as_dict=True) + chapter = frappe.db.get_value("Chapter Reference", {"chapter": lesson.parent}, ["idx"], as_dict=True) if not chapter: return None diff --git a/community/lms/workspace/lms/lms.json b/community/lms/workspace/lms/lms.json index 3bbe5663..4f3bf870 100644 --- a/community/lms/workspace/lms/lms.json +++ b/community/lms/workspace/lms/lms.json @@ -79,7 +79,7 @@ "hidden": 0, "is_query_report": 0, "label": "Chapter", - "link_to": "Chapter", + "link_to": "Course Chapter", "link_type": "DocType", "onboard": 0, "type": "Link" @@ -166,4 +166,4 @@ "type": "DocType" } ] -} \ No newline at end of file +} diff --git a/community/patches.txt b/community/patches.txt index 7651b808..e6d2fcb5 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -12,4 +12,4 @@ 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 #27-09-2021 +community.patches.v0_0.rename_chapter_and_lesson_doctype #29-09-2021 diff --git a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py index f86d5f2b..4dd3bdca 100644 --- a/community/patches/v0_0/rename_chapter_and_lesson_doctype.py +++ b/community/patches/v0_0/rename_chapter_and_lesson_doctype.py @@ -10,25 +10,31 @@ def execute(): if not frappe.db.count("Course Lesson"): move_lessons() - frappe.delete_doc("DocType", "Chapter") - frappe.delete_doc("DocType", "Lesson") + change_parent_for_lesson_reference() def move_chapters(): docs = frappe.get_all("Chapter", fields=["*"]) for doc in docs: if frappe.db.exists("LMS Course", doc.course): - keys = doc - keys.update({"doctype": "Course Chapter"}) - del keys["name"] - frappe.get_doc(keys).save() + name = doc.name + doc.update({"doctype": "Course Chapter"}) + del doc["name"] + new_doc = frappe.get_doc(doc) + new_doc.save() + frappe.rename_doc("Course Chapter", new_doc.name, name) def move_lessons(): docs = frappe.get_all("Lesson", fields=["*"]) for doc in docs: - print(frappe.db.exists("Chapter", doc.chapter)) if frappe.db.exists("Chapter", doc.chapter): - keys = doc - print(doc) - keys.update({"doctype": "Course Lesson"}) - del keys["name"] - frappe.get_doc(keys).save() + name = doc.name + doc.update({"doctype": "Course Lesson"}) + del doc["name"] + new_doc = frappe.get_doc(doc) + new_doc.save() + frappe.rename_doc("Course Lesson", new_doc.name, name) + +def change_parent_for_lesson_reference(): + lesson_reference = frappe.get_all("Lesson Reference", fields=["name", "parent"]) + for reference in lesson_reference: + frappe.db.set_value("Lesson Reference", reference.name, "parenttype", "Course Chapter") From a105a1d3b4d3574a93625ac4b5b88dbab936c721 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 30 Sep 2021 15:04:19 +0530 Subject: [PATCH 5/6] 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) From 836672164333733ccd14b515c9ee9968e40449bd Mon Sep 17 00:00:00 2001 From: pateljannat Date: Thu, 30 Sep 2021 17:09:35 +0530 Subject: [PATCH 6/6] fix: indentation --- .../doctype/course_lesson/course_lesson.js | 90 +++++++++---------- community/lms/doctype/lesson/lesson.py | 1 - community/patches.txt | 2 + 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/community/lms/doctype/course_lesson/course_lesson.js b/community/lms/doctype/course_lesson/course_lesson.js index 0ff38a3c..bb4fa5a6 100644 --- a/community/lms/doctype/course_lesson/course_lesson.js +++ b/community/lms/doctype/course_lesson/course_lesson.js @@ -1,57 +1,57 @@ // Copyright (c) 2021, FOSS United and contributors // For license information, please see license.txt -frappe.ui.form.on('Course Lesson', { - 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 -
+frappe.ui.form.on('Lesson', { + 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") }} -
+
+
+ Video
+
+ {{ Video("url_of_source") }} +
+
-
-
- YouTube Video -
-
- {{ YouTubeVideo("unique_embed_id") }} -
+
+
+ YouTube Video
+
+ {{ YouTubeVideo("unique_embed_id") }} +
+
-
-
- Exercise -
-
- {{ Exercise("exercise_name") }} -
+
+
+ Exercise
+
+ {{ Exercise("exercise_name") }} +
+
-
-
- Quiz -
-
- {{ Quiz("lms_quiz_name") }} -
+
+
+ Quiz
- `); - } - }); +
+ {{ Quiz("lms_quiz_name") }} +
+
+`); + } +}); diff --git a/community/lms/doctype/lesson/lesson.py b/community/lms/doctype/lesson/lesson.py index cc315a91..75f00576 100644 --- a/community/lms/doctype/lesson/lesson.py +++ b/community/lms/doctype/lesson/lesson.py @@ -44,7 +44,6 @@ class Lesson(Document): ex.save() def render_html(self): - print(self.body) return markdown_to_html(self.body) def get_exercises(self): diff --git a/community/patches.txt b/community/patches.txt index 8f7cf33c..e6d2fcb5 100644 --- a/community/patches.txt +++ b/community/patches.txt @@ -6,8 +6,10 @@ 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