mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Allow Base URL to exist without TLD (#5615)
- Custom validator just for this setting
This commit is contained in:
parent
87a8755e1b
commit
67b2d02a7f
@ -74,8 +74,20 @@ class MetaMixin(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmptyURLValidator(URLValidator):
|
class BaseURLValidator(URLValidator):
|
||||||
"""Validator for filed with url - that can be empty."""
|
"""Validator for the InvenTree base URL:
|
||||||
|
|
||||||
|
- Allow empty value
|
||||||
|
- Allow value without specified TLD (top level domain)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, schemes=None, **kwargs):
|
||||||
|
"""Custom init routine"""
|
||||||
|
|
||||||
|
super().__init__(schemes, **kwargs)
|
||||||
|
|
||||||
|
# Override default host_re value - allow optional tld regex
|
||||||
|
self.host_re = '(' + self.hostname_re + self.domain_re + f'({self.tld_re})?' + '|localhost)'
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
"""Make sure empty values pass."""
|
"""Make sure empty values pass."""
|
||||||
@ -1018,7 +1030,7 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'INVENTREE_BASE_URL': {
|
'INVENTREE_BASE_URL': {
|
||||||
'name': _('Base URL'),
|
'name': _('Base URL'),
|
||||||
'description': _('Base URL for server instance'),
|
'description': _('Base URL for server instance'),
|
||||||
'validator': EmptyURLValidator(),
|
'validator': BaseURLValidator(),
|
||||||
'default': '',
|
'default': '',
|
||||||
'after_save': update_instance_url,
|
'after_save': update_instance_url,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user