Allow for custom url schemes to be specified in the config file

This commit is contained in:
Oliver Walters 2019-09-14 00:03:13 +10:00
parent 0846daf1f6
commit ee17d5d3c3
4 changed files with 38 additions and 0 deletions

2
.gitignore vendored
View File

@ -36,6 +36,8 @@ InvenTree/media
InvenTree/static
media
static
inventree_media
inventree_static
# Local config file
config.yaml

View File

@ -213,6 +213,14 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Extra (optional) URL validators
# See https://docs.djangoproject.com/en/2.2/ref/validators/#django.core.validators.URLValidator
EXTRA_URL_SCHEMES = CONFIG.get('extra_url_schemes', [])
if not type(EXTRA_URL_SCHEMES) in [list]:
eprint("Warning: extra_url_schemes not correctly formatted")
EXTRA_URL_SCHEMES = []
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

View File

@ -2,10 +2,29 @@
Custom field validators for InvenTree
"""
from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
def allowable_url_schemes():
""" Return the list of allowable URL schemes.
In addition to the default schemes allowed by Django,
the install configuration file (config.yaml) can specify
extra schemas """
# Default schemes
schemes = ['http', 'https', 'ftp', 'ftps']
extra = settings.EXTRA_URL_SCHEMES
for e in extra:
if e.lower() not in schemes:
schemes.append(e.lower())
return schemes
def validate_part_name(value):
""" Prevent some illegal characters in part names.
"""

View File

@ -47,7 +47,16 @@ media_root: '../inventree_media'
# By default it is stored in a directory named 'static' local to the InvenTree directory
static_root: '../inventree_static'
# Optional URL schemes to allow in URL fields
# By default, only the following schemes are allowed: ['http', 'https', 'ftp', 'ftps']
# Uncomment the lines below to allow extra schemes
#extra_url_schemes:
# - mailto
# - git
# - ssh
# Logging options
# If debug mode is enabled, set log_queries to True to show aggregate database queries in the debug console
log_queries: False
# Backup options