From 6cc0880b4a432629744727b797d1c32411e5e4d7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 16 Feb 2021 15:31:04 +1100 Subject: [PATCH] Add INVENTREE_BASE_URL setting - Also adds callable validator! --- InvenTree/common/models.py | 14 +++++++++++++- InvenTree/report/models.py | 1 + InvenTree/templates/InvenTree/settings/global.html | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 9e6c6e868d..d893206126 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -18,7 +18,7 @@ from djmoney.contrib.exchange.models import convert_money from djmoney.contrib.exchange.exceptions import MissingRate from django.utils.translation import ugettext as _ -from django.core.validators import MinValueValidator +from django.core.validators import MinValueValidator, URLValidator from django.core.exceptions import ValidationError import InvenTree.helpers @@ -64,6 +64,13 @@ class InvenTreeSetting(models.Model): 'default': 'My company name', }, + 'INVENTREE_BASE_URL': { + 'name': _('Base URL'), + 'description': _('Base URL for server instance'), + 'validator': URLValidator(), + 'default': '', + }, + 'INVENTREE_DEFAULT_CURRENCY': { 'name': _('Default Currency'), 'description': _('Default currency'), @@ -528,6 +535,11 @@ class InvenTreeSetting(models.Model): return + if callable(validator): + # We can accept function validators with a single argument + print("Running validator function") + validator(self.value) + # Boolean validator if validator == bool: # Value must "look like" a boolean value diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index f052c0321d..906b65be0b 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -209,6 +209,7 @@ class ReportTemplateBase(ReportBase): context = self.get_context_data(request) + context['base_url'] = common.models.InvenTreeSetting.get_setting('INVENTREE_BASE_URL') context['date'] = datetime.datetime.now().date() context['datetime'] = datetime.datetime.now() context['default_page_size'] = common.models.InvenTreeSetting.get_setting('REPORT_DEFAULT_PAGE_SIZE') diff --git a/InvenTree/templates/InvenTree/settings/global.html b/InvenTree/templates/InvenTree/settings/global.html index 6d2f14bfd9..d63593d866 100644 --- a/InvenTree/templates/InvenTree/settings/global.html +++ b/InvenTree/templates/InvenTree/settings/global.html @@ -16,6 +16,7 @@ {% include "InvenTree/settings/header.html" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE" icon="fa-info-circle" %} + {% include "InvenTree/settings/setting.html" with key="INVENTREE_BASE_URL" icon="fa-globe" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_COMPANY_NAME" icon="fa-building" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-dollar-sign" %}