From e19c18e5a9840ed68c4c29ccf5ecb09df03af137 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Wed, 26 May 2021 11:03:33 +0530 Subject: [PATCH] refactor: Move context value setting code to a separate function --- frappe/website/page_renderers/template_page.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frappe/website/page_renderers/template_page.py b/frappe/website/page_renderers/template_page.py index 682c3cda39..2b326d7383 100644 --- a/frappe/website/page_renderers/template_page.py +++ b/frappe/website/page_renderers/template_page.py @@ -45,6 +45,8 @@ class TemplatePage(BaseTemplatePage): self.basename = os.path.splitext(file_path)[0] self.template_path = os.path.relpath(file_path, self.app_path) self.basepath = os.path.dirname(file_path) + self.filename = os.path.basename(file_path) + self.name = os.path.splitext(self.filename)[0] return def can_render(self): @@ -109,10 +111,6 @@ class TemplatePage(BaseTemplatePage): self.convert_from_markdown() def update_context(self): - self.context.base_template = self.context.base_template or get_base_template(self.path) - self.context.basepath = self.basepath - self.context.basename = self.basename - self.context.path = self.path self.set_page_properties() self.set_properties_from_source() self.load_colocated_files() @@ -138,8 +136,15 @@ class TemplatePage(BaseTemplatePage): self.context[prop] = getattr(self.pymodule, prop) def set_page_properties(self): + self.context.base_template = self.context.base_template \ + or get_base_template(self.path) \ + or 'templates/web.html' + self.context.basepath = self.basepath + self.context.basename = self.basename + self.context.name = self.name + self.context.path = self.path + self.context.route = self.path self.context.template = self.template_path - self.context.base_template = self.context.base_template or 'templates/web.html' def set_properties_from_source(self): if not self.source: