old_contents: import frappe
  from frappe import _
  from frappe.model.document import get_controller
  from frappe.website.page_controllers.base_template_page import BaseTemplatePage
  from frappe.website.render import build_response
  from frappe.website.router import (get_doctypes_with_web_view,
  	get_page_info_from_web_page_with_dynamic_routes)
  
  
  class DocumentPage(BaseTemplatePage):
  	def validate(self):
  		'''
  		Find a document with matching `route` from all doctypes with `has_web_view`=1
  		'''
  		if self.search_in_doctypes_with_web_view():
  			return True
  
  		if self.search_web_page_dynamic_routes():
  			return True
  
  		return False
  
  	def search_in_doctypes_with_web_view(self):
  		for doctype in get_doctypes_with_web_view():
  			filters = dict(route=self.path)
  			meta = frappe.get_meta(doctype)
  			condition_field = self.get_condition_field(meta)
  
  			if condition_field:
  				filters[condition_field] = 1
  
  			try:
  				self.docname = frappe.db.get_value(doctype, filters, 'name')
  				if self.docname:
  					self.doctype = doctype
  					self.meta = meta
  					return True
  			except Exception as e:
  				if not frappe.db.is_missing_column(e): raise e
  
  	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.docname = d.name
  			self.meta = frappe.get_meta(self.doctype)
  			return True
  		else:
  			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 = frappe.get_template(self.context.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)
  
  	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())
  
  		if not self.context.template_path:
  			self.context.template_path = self.context.doc.meta.get_web_template()
  
  		if hasattr(self.doc, "get_context"):
  			ret = self.doc.get_context(self.context)
  
  			if ret:
  				self.context.update(ret)
  
  		for prop in ("no_cache", "sitemap"):
  			if not prop in self.context:
  				self.context[prop] = getattr(self.doc, prop, False)
  
  	def get_condition_field(self, meta):
  		condition_field = None
  		if meta.is_published_field:
  			condition_field = meta.is_published_field
  		elif not meta.custom:
  			controller = get_controller(meta.doctype)
  			condition_field = controller.website.condition_field
  
  		return condition_field
  
new_contents: import frappe
  from frappe import _
  from frappe.model.document import get_controller
  from frappe.website.page_controllers.base_template_page import BaseTemplatePage
  from frappe.website.render import build_response
  from frappe.website.router import (get_doctypes_with_web_view,
  	get_page_info_from_web_page_with_dynamic_routes)
  
  
  class DocumentPage(BaseTemplatePage):
  	def validate(self):
  		'''
  		Find a document with matching `route` from all doctypes with `has_web_view`=1
  		'''
  		if self.search_in_doctypes_with_web_view():
  			return True
  
  		if self.search_web_page_dynamic_routes():
  			return True
  
  		return False
  
  	def search_in_doctypes_with_web_view(self):
  		for doctype in get_doctypes_with_web_view():
  			filters = dict(route=self.path)
  			meta = frappe.get_meta(doctype)
  			condition_field = self.get_condition_field(meta)
  
  			if condition_field:
  				filters[condition_field] = 1
  
  			try:
  				self.docname = frappe.db.get_value(doctype, filters, 'name')
  				if self.docname:
  					self.doctype = doctype
  					self.meta = meta
  					return True
  			except Exception as e:
  				if not frappe.db.is_missing_column(e): raise e
  
  	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.docname = d.name
  			self.meta = frappe.get_meta(self.doctype)
  			return True
  		else:
  			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 = frappe.get_template(self.context.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)
  
  	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())
  
  		if not self.context.template_path:
  			self.context.template_path = self.context.doc.meta.get_web_template()
  
  		if hasattr(self.doc, "get_context"):
  			ret = self.doc.get_context(self.context)
  
  			if ret:
  				self.context.update(ret)
  
  		for prop in ("no_cache", "sitemap"):
  			if not prop in self.context:
  				self.context[prop] = getattr(self.doc, prop, False)
  
  	def get_condition_field(self, meta):
  		condition_field = None
  		if meta.is_published_field:
  			condition_field = meta.is_published_field
  		elif not meta.custom:
  			controller = get_controller(meta.name)
  			condition_field = controller.website.condition_field
  
  		return condition_field
  
subject: Document Page