feat: added learn page

- added sections to the lesson to handle multiple sesions like examples and exercises
- added livecode integration to lesson pages
- autosave and submiting the answers is not done yet
This commit is contained in:
Anand Chitipothu
2021-05-14 12:11:45 +05:30
parent 1cf57c4823
commit 49b41749e8
12 changed files with 205 additions and 33 deletions

View File

@@ -9,7 +9,8 @@
"course",
"title",
"description",
"locked"
"locked",
"index_"
],
"fields": [
{
@@ -35,6 +36,12 @@
"in_list_view": 1,
"label": "Course",
"options": "LMS Course"
},
{
"default": "1",
"fieldname": "index_",
"fieldtype": "Int",
"label": "Index"
}
],
"index_web_pages_for_search": 1,
@@ -45,7 +52,7 @@
"link_fieldname": "chapter"
}
],
"modified": "2021-05-03 06:52:10.894328",
"modified": "2021-05-13 21:05:20.531890",
"modified_by": "Administrator",
"module": "LMS",
"name": "Chapter",

View File

@@ -9,7 +9,9 @@
"chapter",
"lesson_type",
"title",
"index_"
"index_",
"body",
"sections"
],
"fields": [
{
@@ -38,11 +40,22 @@
"fieldname": "index_",
"fieldtype": "Int",
"label": "Index"
},
{
"fieldname": "body",
"fieldtype": "Markdown Editor",
"label": "Body"
},
{
"fieldname": "sections",
"fieldtype": "Table",
"label": "Sections",
"options": "LMS Section"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-05-08 13:25:13.965162",
"modified": "2021-05-13 20:03:51.510605",
"modified_by": "Administrator",
"module": "LMS",
"name": "Lesson",

View File

@@ -3,8 +3,22 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe.model.document import Document
from ..lms_topic.section_parser import SectionParser
class Lesson(Document):
pass
def before_save(self):
sections = SectionParser().parse(self.body or "")
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
def get_sections(self):
return sorted(self.get('sections'), key=lambda s: s.index)
def make_lms_section(self, index, section):
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
s.type = section.type
s.label = section.label
s.contents = section.contents
s.index = index
return s

View File

@@ -177,3 +177,16 @@ class LMSCourse(Document):
visibility="Public")
return batches
def get_chapter(self, index):
return find("Chapter", course=self.name, index_=index)
def get_lesson(self, chapter_index, lesson_index):
chapter_name = frappe.get_value(
"Chapter",
{"course": self.name, "index_": chapter_index},
"name")
lesson_name = chapter_name and frappe.get_value(
"Lesson",
{"chapter": chapter_name, "index_": lesson_index},
"name")
return lesson_name and frappe.get_doc("Lesson", lesson_name)

View File

@@ -1,4 +1,9 @@
"""Utility to split the text in the topic into multiple sections.
{{ section(type="example", id="foo") }}
circle(100, 100, 50)
{{ end }}
"""
from __future__ import annotations
from dataclasses import dataclass