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

Base URL configuration options (#4749)

* Improve construct_absolute_url method

- Look for hard-coded site URL if provided
- Otherwise look for specified site URL
- Otherwise look at the provided request object

* Refactor existing code which used base URL setting

* Update docs

* Validate that a provided base URL is valid
This commit is contained in:
Oliver
2023-05-02 22:14:57 +10:00
committed by GitHub
parent 10c3d101e8
commit 61d613ff34
9 changed files with 75 additions and 33 deletions

View File

@ -3,7 +3,6 @@
from django.contrib.auth import authenticate, login
from django.db import transaction
from django.db.models import F, Q
from django.db.utils import ProgrammingError
from django.http.response import JsonResponse
from django.urls import include, path, re_path
from django.utils.translation import gettext_lazy as _
@ -20,7 +19,8 @@ from company.models import SupplierPart
from InvenTree.api import (APIDownloadMixin, AttachmentMixin,
ListCreateDestroyAPIView, MetadataView, StatusView)
from InvenTree.filters import SEARCH_ORDER_FILTER, SEARCH_ORDER_FILTER_ALIAS
from InvenTree.helpers import DownloadFile, str2bool
from InvenTree.helpers import (DownloadFile, construct_absolute_url,
get_base_url, str2bool)
from InvenTree.mixins import (CreateAPI, ListAPI, ListCreateAPI,
RetrieveUpdateDestroyAPI)
from InvenTree.status_codes import (PurchaseOrderStatus, ReturnOrderLineStatus,
@ -1371,11 +1371,8 @@ class OrderCalendarExport(ICalFeed):
whether or not to show completed orders. Defaults to false
"""
try:
instance_url = InvenTreeSetting.get_setting('INVENTREE_BASE_URL', create=False, cache=False)
except ProgrammingError: # pragma: no cover
# database is not initialized yet
instance_url = ''
instance_url = get_base_url()
instance_url = instance_url.replace("http://", "").replace("https://", "")
timezone = settings.TIME_ZONE
file_name = "calendar.ics"
@ -1507,9 +1504,7 @@ class OrderCalendarExport(ICalFeed):
def item_link(self, item):
"""Set the item link."""
# Do not use instance_url as here, as the protocol needs to be included
site_url = InvenTreeSetting.get_setting("INVENTREE_BASE_URL")
return f'{site_url}{item.get_absolute_url()}'
return construct_absolute_url(item.get_absolute_url())
order_api_urls = [