refactor: Rename validate function to can_render
This commit is contained in:
parent
cbd00179cb
commit
70a8bd5945
12 changed files with 13 additions and 14 deletions
|
|
@ -7,7 +7,7 @@ from frappe.website.router import (get_doctypes_with_web_view,
|
|||
|
||||
|
||||
class DocumentPage(BaseTemplatePage):
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
'''
|
||||
Find a document with matching `route` from all doctypes with `has_web_view`=1
|
||||
'''
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ class ErrorPage(TemplatePage):
|
|||
super().__init__(path=path, http_status_code=http_status_code)
|
||||
self.http_status_code = getattr(exception, 'http_status_code', None) or http_status_code or 500
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import frappe
|
|||
from frappe.website.page_controllers.template_page import TemplatePage
|
||||
|
||||
class ListPage(TemplatePage):
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return frappe.db.exists('DocType', self.path, True)
|
||||
|
||||
def render(self):
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class NotFoundPage(TemplatePage):
|
|||
http_status_code = 404
|
||||
super().__init__(path=path, http_status_code=http_status_code)
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return True
|
||||
|
||||
def render(self):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class NotPermittedPage(TemplatePage):
|
|||
super().__init__(path=path, http_status_code=http_status_code)
|
||||
self.http_status_code = 403
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return True
|
||||
|
||||
def render(self):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class PrintPage(TemplatePage):
|
|||
default path returns a printable object (based on permission)
|
||||
/Quotation/Q-0001
|
||||
'''
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
parts = self.path.split('/', 1)
|
||||
if len(parts)==2:
|
||||
if (frappe.db.exists('DocType', parts[0], True)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class RedirectPage(object):
|
|||
self.path = path
|
||||
self.http_status_code = http_status_code
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return True
|
||||
|
||||
def render(self):
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class StaticPage(WebPage):
|
|||
if os.path.isfile(file_path):
|
||||
self.file_path = file_path
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return self.is_valid_file_path() and self.file_path
|
||||
|
||||
def is_valid_file_path(self):
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class TemplatePage(BaseTemplatePage):
|
|||
self.basepath = os.path.dirname(file_path)
|
||||
return
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return hasattr(self, 'template_path') and bool(self.template_path)
|
||||
|
||||
def get_index_path_options(self, search_path):
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ from frappe.website.page_controllers.web_page import WebPage
|
|||
import frappe
|
||||
|
||||
class WebFormPage(WebPage):
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
return bool(frappe.get_all("Web Form", filters={'route': self.path}))
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class WebPage(object):
|
|||
if self.validate():
|
||||
return self.render()
|
||||
|
||||
def validate(self):
|
||||
def can_render(self):
|
||||
pass
|
||||
|
||||
def render(self):
|
||||
|
|
|
|||
|
|
@ -32,15 +32,14 @@ class PathResolver():
|
|||
try:
|
||||
resolve_redirect(self.path, request.query_string)
|
||||
except frappe.Redirect:
|
||||
return self.path, RedirectPage(self.path)
|
||||
return frappe.flags.redirect_location, RedirectPage(self.path)
|
||||
|
||||
endpoint = resolve_path(self.path)
|
||||
renderers = (StaticPage, WebFormPage, TemplatePage, ListPage, DocumentPage, PrintPage, NotFoundPage)
|
||||
|
||||
for renderer in renderers:
|
||||
renderer_instance = renderer(endpoint, 200)
|
||||
can_render = renderer_instance.validate()
|
||||
if can_render:
|
||||
if renderer_instance.can_render():
|
||||
return endpoint, renderer_instance
|
||||
|
||||
return endpoint, NotFoundPage(endpoint)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue