feat: Hook to add dynamic routes for other web view doctypes

This commit is contained in:
Suraj Shetty 2023-08-17 09:30:24 +05:30
parent 112836dcd7
commit 5d85341984
3 changed files with 12 additions and 5 deletions

View file

@ -286,6 +286,13 @@ def extract_script_and_style_tags(html):
@redis_cache(ttl=60 * 60)
def get_dynamic_web_pages() -> dict[str, str]:
return frappe.get_all(
"Web Page", fields=["name", "route", "modified"], filters=dict(published=1, dynamic_route=1)
pages = frappe.get_all(
"Web Page",
fields=["name", "route", "modified"],
filters=dict(published=1, dynamic_route=1),
update={"doctype": "Web Page"},
)
get_web_pages_with_dynamic_routes = frappe.get_hooks("get_web_pages_with_dynamic_routes") or []
for method in get_web_pages_with_dynamic_routes:
pages.extend(frappe.get_attr(method)())
return pages

View file

@ -30,7 +30,7 @@ class DocumentPage(BaseTemplatePage):
def search_web_page_dynamic_routes(self):
d = get_page_info_from_web_page_with_dynamic_routes(self.path)
if d:
self.doctype = "Web Page"
self.doctype = d.doctype
self.docname = d.name
return True
else:

View file

@ -21,8 +21,8 @@ def get_page_info_from_web_page_with_dynamic_routes(path):
rules, page_info = [], {}
for d in get_dynamic_web_pages():
rules.append(Rule("/" + d.route, endpoint=d.name))
d.doctype = "Web Page"
rules.append(Rule(f"/{d.route}", endpoint=d.name))
d.doctype = d.doctype or "Web Page"
page_info[d.name] = d
end_point = evaluate_dynamic_routes(rules, path)