fix: Website template path

This commit is contained in:
Suraj Shetty 2021-05-24 19:52:31 +05:30
parent 1a0a095b34
commit 15f5b697d3
3 changed files with 13 additions and 7 deletions

View file

@ -5,6 +5,10 @@ from frappe.website.website_components.metatags import MetaTags
class BaseTemplatePage(WebPage):
def __init__(self, path, http_status_code):
super().__init__(path=path, http_status_code=http_status_code)
self.template_path = ''
def init_context(self):
self.context = frappe._dict()
self.context.update(get_website_settings())
@ -35,8 +39,7 @@ class BaseTemplatePage(WebPage):
self.context.canonical = frappe.utils.get_url(frappe.utils.escape_html(self.path))
# context sends us a new template path
if self.context.template:
self.template_path = self.context.template
self.template_path = self.context.template or ''
def set_base_template_if_missing(self):
if not self.context.base_template_path:

View file

@ -53,8 +53,7 @@ class DocumentPage(BaseTemplatePage):
self.init_context()
self.update_context()
self.post_process_context()
template_path = self.context.template_path or self.context.template or ''
html = frappe.get_template(template_path).render(self.context)
html = frappe.get_template(self.template_path).render(self.context)
html = self.add_csrf_token(html)
return build_response(self.path, html, self.http_status_code or 200, self.headers)
@ -62,10 +61,12 @@ class DocumentPage(BaseTemplatePage):
def update_context(self):
self.context.doc = self.doc
self.context.update(self.context.doc.as_dict())
self.context.update(self.context.doc.get_website_properties())
self.context.update(self.context.doc.get_page_info())
if not self.context.template_path:
self.context.template_path = self.context.doc.meta.get_web_template()
self.template_path = self.context.template or self.template_path
if not self.template_path:
self.template_path = self.context.doc.meta.get_web_template()
if hasattr(self.doc, "get_context"):
ret = self.doc.get_context(self.context)

View file

@ -129,6 +129,8 @@ class WebsiteGenerator(Document):
if not route.page_title:
route.page_title = self.get(self.get_title_field())
route.title = route.page_title
return route
def send_indexing_request(self, operation_type='URL_UPDATED'):