feat: pass context to page extensions

Pass the context to page extensions to allow them to make decisions
based on the context. For example, an extension to load the course
specific scripts. This is currently not possible because the course
details are not availale to the page extensions. Made this possible by
passing the context to page extensions.
This commit is contained in:
Anand Chitipothu
2022-01-25 07:12:17 +05:30
parent ec879b12b3
commit 6d4e64059a
2 changed files with 9 additions and 2 deletions

View File

@@ -31,7 +31,7 @@ def get_context(context):
"description": meta_info
}
context.page_extensions = get_page_extensions()
context.page_extensions = get_page_extensions(context)
context.page_context = {
"course": context.course.name,
"batch": context.get("batch") and context.batch.name,
@@ -52,8 +52,10 @@ def get_lesson_index(course, batch, user):
lesson = batch.get_current_lesson(user)
return lesson and course.get_lesson_index(lesson)
def get_page_extensions():
def get_page_extensions(context):
default_value = ["school.plugins.PageExtension"]
classnames = frappe.get_hooks("school_lesson_page_extensions") or default_value
extensions = [frappe.get_attr(name)() for name in classnames]
for e in extensions:
e.set_context(context)
return extensions