zhuangxujie 01bc837fd4
Some checks failed
Server (Postgres) / Build & reinstall (setup) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (1) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (2) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (3) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (4) (push) Has been cancelled
Server (Mariadb) / Build & reinstall (setup) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (1) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (2) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (3) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (4) (push) Has been cancelled
Server (Mariadb) / Coverage Wrap Up (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Has been cancelled
Regenerate POT file (translatable strings) / Regenerate POT file (version-16-hotfix) (push) Has been cancelled
Sync translations to hotfix branches / Trigger sync → version-16-hotfix (push) Has been cancelled
Create weekly release pull requests / Release (15) (push) Has been cancelled
Create weekly release pull requests / Release (16) (push) Has been cancelled
first commit
2026-07-23 16:31:28 +08:00

55 lines
1.3 KiB
Python

import json
import re
import frappe
import frappe.sessions
from frappe import _
from frappe.utils.jinja_globals import is_rtl
no_cache = 1
SCRIPT_TAG_PATTERN = re.compile(r"\<script[^<]*\</script\>", re.IGNORECASE)
CLOSING_SCRIPT_TAG_PATTERN = re.compile(r"</script\>", re.IGNORECASE)
def get_context(context):
csrf_token = frappe.sessions.get_csrf_token()
context = frappe._dict()
context.boot = get_boot()
context.csrf_token = csrf_token
context.build_version = frappe.utils.get_build_version()
context.app_name = (
frappe.get_website_settings("app_name") or frappe.get_system_settings("app_name") or "ERPNext"
)
context.layout_direction = "rtl" if is_rtl() else "ltr"
context.lang = frappe.local.lang
return context
@frappe.whitelist(methods=["POST"], allow_guest=True)
def get_context_for_dev():
if not frappe.conf.developer_mode:
frappe.throw(_("This method is only meant for developer mode"))
return {
"boot": json.loads(get_boot()),
"layout_direction": "rtl" if is_rtl() else "ltr",
}
def get_boot():
try:
boot = frappe.sessions.get()
except Exception as e:
raise frappe.SessionBootFailed from e
boot_json = frappe.as_json(boot, indent=None, separators=(",", ":"))
boot_json = SCRIPT_TAG_PATTERN.sub("", boot_json)
boot_json = CLOSING_SCRIPT_TAG_PATTERN.sub("", boot_json)
boot_json = json.dumps(boot_json)
return boot_json