From 34e993cf86bcca523cce8d5b1a37488ab362c6d9 Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Thu, 20 May 2021 13:27:30 +0530 Subject: [PATCH] refactor: added lesson to exercise usualy to know which lesson an exercise is part of by looking at the exercise. --- community/lms/doctype/exercise/exercise.json | 15 +++++++++++---- community/lms/doctype/lesson/lesson.py | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/community/lms/doctype/exercise/exercise.json b/community/lms/doctype/exercise/exercise.json index a54f84af..33c7151e 100644 --- a/community/lms/doctype/exercise/exercise.json +++ b/community/lms/doctype/exercise/exercise.json @@ -14,7 +14,8 @@ "course", "hints", "tests", - "image" + "image", + "lesson" ], "fields": [ { @@ -32,7 +33,7 @@ { "columns": 4, "fieldname": "description", - "fieldtype": "Markdown Editor", + "fieldtype": "Small Text", "in_list_view": 1, "label": "Description" }, @@ -54,7 +55,7 @@ { "columns": 4, "fieldname": "hints", - "fieldtype": "Markdown Editor", + "fieldtype": "Small Text", "label": "Hints" }, { @@ -68,11 +69,17 @@ "fieldtype": "Code", "label": "Image", "read_only": 1 + }, + { + "fieldname": "lesson", + "fieldtype": "Link", + "label": "Lesson", + "options": "Lesson" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-05-19 18:27:40.475515", + "modified": "2021-05-20 13:23:12.340928", "modified_by": "Administrator", "module": "LMS", "name": "Exercise", diff --git a/community/lms/doctype/lesson/lesson.py b/community/lms/doctype/lesson/lesson.py index 87960951..c544f774 100644 --- a/community/lms/doctype/lesson/lesson.py +++ b/community/lms/doctype/lesson/lesson.py @@ -11,6 +11,11 @@ class Lesson(Document): def before_save(self): sections = SectionParser().parse(self.body or "") self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)] + for s in self.sections: + if s.type == "exercise": + e = s.get_exercise() + e.lesson = self.name + e.save() def get_sections(self): return sorted(self.get('sections'), key=lambda s: s.index)