浏览代码

Added inheritable context hook

version-14
Felipe Orellana 8 年前
父节点
当前提交
cde153d75b
共有 1 个文件被更改,包括 31 次插入16 次删除
  1. +31
    -16
      frappe/website/context.py

+ 31
- 16
frappe/website/context.py 查看文件

@@ -33,6 +33,25 @@ def get_context(path, args=None):

return context

def update_controller_context(context, controller):
module = frappe.get_module(controller)

if module:
# get config fields
for prop in ("base_template_path", "template", "no_cache", "no_sitemap",
"condition_field"):
if hasattr(module, prop):
context[prop] = getattr(module, prop)

if hasattr(module, "get_context"):
ret = module.get_context(context)
if ret:
context.update(ret)

if hasattr(module, "get_children"):
context.children = module.get_children(context)


def build_context(context):
"""get_context method of doc or module is supposed to render
content templates and push it into context"""
@@ -62,22 +81,18 @@ def build_context(context):
context[prop] = getattr(context.doc, prop, False)

elif context.controller:
module = frappe.get_module(context.controller)

if module:
# get config fields
for prop in ("base_template_path", "template", "no_cache", "no_sitemap",
"condition_field"):
if hasattr(module, prop):
context[prop] = getattr(module, prop)

if hasattr(module, "get_context"):
ret = module.get_context(context)
if ret:
context.update(ret)

if hasattr(module, "get_children"):
context.children = module.get_children(context)
# controller based context
update_controller_context(context, context.controller)
# controller context extensions
context_controller_hooks = frappe.get_hooks("extend_controller_context") or {}
for controller, extension in context_controller_hooks.items():
if isinstance(extension, list):
for ext in extension:
if controller == context.controller:
update_controller_context(context, ext)
else:
update_controller_context(context, extension)

add_metatags(context)



正在加载...
取消
保存