2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 11:10:54 +00:00

Adds a function to construct an "absolute" URL

Useful for providing an external link (e.g. in an email)
This commit is contained in:
Oliver
2021-11-01 23:40:21 +11:00
parent 9cbc2b82b5
commit dabaa9aea5
2 changed files with 31 additions and 10 deletions

View File

@ -14,6 +14,8 @@ from stock.models import StockItem
from common.models import InvenTreeSetting
import InvenTree.helpers
register = template.Library()
@ -119,18 +121,10 @@ def internal_link(link, text):
text = str(text)
base_url = InvenTreeSetting.get_setting('INVENTREE_BASE_URL')
url = InvenTree.helpers.construct_absolute_url(link)
# If the base URL is not set, just return the text
if not base_url:
if not url:
return text
if not base_url.endswith('/'):
base_url += '/'
if base_url.endswith('/') and link.startswith('/'):
link = link[1:]
url = f"{base_url}{link}"
return mark_safe(f'<a href="{url}">{text}</a>')