Beispiel #1
0
def render(path=None, http_status_code=None):
    """render html page"""
    if not path:
        path = frappe.local.request.path

    try:
        path = path.strip('/ ')
        raise_if_disabled(path)
        resolve_redirect(path)
        path = resolve_path(path)
        data = None

        # if in list of already known 404s, send it
        if can_cache() and frappe.cache().hget('website_404',
                                               frappe.request.url):
            data = render_page('404')
            http_status_code = 404
        elif is_static_file(path):
            return get_static_file_response()
        elif is_web_form(path):
            data = render_web_form(path)
        else:
            try:
                data = render_page_by_language(path)
            except frappe.DoesNotExistError:
                doctype, name = get_doctype_from_path(path)
                if doctype and name:
                    path = "printview"
                    frappe.local.form_dict.doctype = doctype
                    frappe.local.form_dict.name = name
                elif doctype:
                    path = "list"
                    frappe.local.form_dict.doctype = doctype
                else:
                    # 404s are expensive, cache them!
                    frappe.cache().hset('website_404', frappe.request.url,
                                        True)
                    data = render_page('404')
                    http_status_code = 404

                if not data:
                    try:
                        data = render_page(path)
                    except frappe.PermissionError as e:
                        data, http_status_code = render_403(e, path)

            except frappe.PermissionError as e:
                data, http_status_code = render_403(e, path)

            except frappe.Redirect as e:
                raise e

            except Exception:
                path = "error"
                data = render_page(path)
                http_status_code = 500

        data = add_csrf_token(data)

    except frappe.Redirect:
        return build_response(
            path, "", 301, {
                "Location":
                frappe.flags.redirect_location or
                (frappe.local.response or {}).get('location'),
                "Cache-Control":
                "no-store, no-cache, must-revalidate"
            })

    return build_response(path, data, http_status_code or 200)
Beispiel #2
0
def render(path=None, http_status_code=None):
	"""render html page"""
	if not path:
		path = frappe.local.request.path

	try:
		path = path.strip('/ ')
		resolve_redirect(path)
		path = resolve_path(path)
		data = None

		# if in list of already known 404s, send it
		if can_cache() and frappe.cache().hget('website_404', frappe.request.url):
			data = render_page('404')
			http_status_code = 404
		elif is_static_file(path):
			return get_static_file_response()
		else:
			try:
				data = render_page_by_language(path)
			except frappe.DoesNotExistError:
				doctype, name = get_doctype_from_path(path)
				if doctype and name:
					path = "printview"
					frappe.local.form_dict.doctype = doctype
					frappe.local.form_dict.name = name
				elif doctype:
					path = "list"
					frappe.local.form_dict.doctype = doctype
				else:
					# 404s are expensive, cache them!
					frappe.cache().hset('website_404', frappe.request.url, True)
					data = render_page('404')
					http_status_code = 404

				if not data:
					try:
						data = render_page(path)
					except frappe.PermissionError as e:
						data, http_status_code = render_403(e, path)

			except frappe.PermissionError as e:
				data, http_status_code = render_403(e, path)

			except frappe.Redirect as e:
				raise e

			except Exception:
				path = "error"
				data = render_page(path)
				http_status_code = 500

		data = add_csrf_token(data)

	except frappe.Redirect:
		return build_response(path, "", 301, {
			"Location": frappe.flags.redirect_location or (frappe.local.response or {}).get('location'),
			"Cache-Control": "no-store, no-cache, must-revalidate"
		})

	return build_response(path, data, http_status_code or 200)