refactor: added lesson to exercise

usualy to know which lesson an exercise is part of by looking at the
exercise.
This commit is contained in:
Anand Chitipothu
2021-05-20 13:27:30 +05:30
parent 8c889ffb92
commit 34e993cf86
2 changed files with 16 additions and 4 deletions

View File

@@ -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",

View File

@@ -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)