Merge pull request #24684 from barredterra/label-in-link-to-form
This commit is contained in:
commit
b3b02c809f
2 changed files with 16 additions and 4 deletions
|
|
@ -63,6 +63,7 @@ from frappe.utils.data import (
|
|||
get_time,
|
||||
get_timedelta,
|
||||
get_timespan_date_range,
|
||||
get_url_to_form,
|
||||
get_year_ending,
|
||||
getdate,
|
||||
now_datetime,
|
||||
|
|
@ -1009,6 +1010,10 @@ class TestMiscUtils(FrappeTestCase):
|
|||
self.assertIn("frappe", installed_apps)
|
||||
self.assertGreaterEqual(len(info["users"]), 1)
|
||||
|
||||
def test_get_url_to_form(self):
|
||||
self.assertTrue(get_url_to_form("System Settings").endswith("/app/system-settings"))
|
||||
self.assertTrue(get_url_to_form("User", "Test User").endswith("/app/user/Test%20User"))
|
||||
|
||||
def test_safe_json_load(self):
|
||||
self.assertEqual(safe_json_loads("{}"), {})
|
||||
self.assertEqual(safe_json_loads("{ /}"), "{ /}")
|
||||
|
|
|
|||
|
|
@ -1808,14 +1808,16 @@ def get_host_name() -> str:
|
|||
return get_url().rsplit("//", 1)[-1]
|
||||
|
||||
|
||||
def get_link_to_form(doctype: str, name: str, label: str | None = None) -> str:
|
||||
def get_link_to_form(doctype: str, name: str | None = None, label: str | None = None) -> str:
|
||||
"""Return the HTML link to the given document's form view.
|
||||
|
||||
e.g. get_link_to_form("Sales Invoice", "INV-0001", "Link Label") returns:
|
||||
'<a href="https://frappe.io/app/sales-invoice/INV-0001">Link Label</a>'.
|
||||
"""
|
||||
from frappe import _
|
||||
|
||||
if not label:
|
||||
label = name
|
||||
label = name or _(doctype)
|
||||
|
||||
return f"""<a href="{get_url_to_form(doctype, name)}">{label}</a>"""
|
||||
|
||||
|
|
@ -1863,13 +1865,18 @@ def get_absolute_url(doctype: str, name: str) -> str:
|
|||
return f"/app/{quoted(slug(doctype))}/{quoted(name)}"
|
||||
|
||||
|
||||
def get_url_to_form(doctype: str, name: str) -> str:
|
||||
def get_url_to_form(doctype: str, name: str | None = None) -> str:
|
||||
"""Return the absolute URL for the form view of the given document in the desk.
|
||||
|
||||
e.g. when doctype="Sales Invoice" and your site URL is "https://frappe.io",
|
||||
returns 'https://frappe.io/app/sales-invoice/INV-00001'
|
||||
"""
|
||||
return get_url(uri=f"/app/{quoted(slug(doctype))}/{quoted(name)}")
|
||||
if not name:
|
||||
uri = f"/app/{quoted(slug(doctype))}"
|
||||
else:
|
||||
uri = f"/app/{quoted(slug(doctype))}/{quoted(name)}"
|
||||
|
||||
return get_url(uri=uri)
|
||||
|
||||
|
||||
def get_url_to_list(doctype: str) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue