fix: Move context building to get_html

This commit is contained in:
Suraj Shetty 2021-06-24 15:19:48 +05:30
parent 9ad276767f
commit 9e8aadf2f9
2 changed files with 9 additions and 9 deletions

View file

@ -98,14 +98,14 @@ class TestBlogPost(unittest.TestCase):
clear_website_cache()
# first response no-cache
pages = frappe.get_all('Blog Post', fields=['name', 'route'],
filters={'published': 1, 'route': ('!=', '')}, limit =1)
filters={'published': 1, 'title': "_Test Blog Post"}, limit=1)
set_request(path=pages[0].route)
response = get_response()
route = pages[0].route
response = get_response(route)
self.assertIn(('X-From-Cache', 'False'), list(response.headers))
# first response returned from cache
response = get_response()
response = get_response(route)
self.assertIn(('X-From-Cache', 'True'), list(response.headers))
frappe.flags.force_website_cache = True

View file

@ -47,10 +47,6 @@ class DocumentPage(BaseTemplatePage):
return False
def render(self):
self.doc = frappe.get_doc(self.doctype, self.docname)
self.init_context()
self.update_context()
self.post_process_context()
html = self.get_html()
html = self.add_csrf_token(html)
@ -58,6 +54,10 @@ class DocumentPage(BaseTemplatePage):
@cache_html
def get_html(self):
self.doc = frappe.get_doc(self.doctype, self.docname)
self.init_context()
self.update_context()
self.post_process_context()
html = frappe.get_template(self.template_path).render(self.context)
return html