From d5d89c67b1da9258e17848c3c3e62d0bd4f1bb65 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 20:42:19 +1000 Subject: [PATCH] Error out if the static or media directories are not properly defined --- InvenTree/InvenTree/settings.py | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 96b7da140d..6297dca41d 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -169,6 +169,30 @@ else: logger.exception(f"Couldn't load keyfile {key_file}") sys.exit(-1) +# The filesystem location for served static files +STATIC_ROOT = os.path.abspath( + get_setting( + 'INVENTREE_STATIC_ROOT', + CONFIG.get('static_root', None) + ) +) + +if STATIC_ROOT is None: + print("ERROR: INVENTREE_STATIC_ROOT directory not defined") + sys.exit(1) + +# The filesystem location for served static files +MEDIA_ROOT = os.path.abspath( + get_setting( + 'INVENTREE_MEDIA_ROOT', + CONFIG.get('media_root', None) + ) +) + +if MEDIA_ROOT is None: + print("ERROR: INVENTREE_MEDIA_ROOT directory is not defined") + sys.exit(1) + # List of allowed hosts (default = allow all) ALLOWED_HOSTS = CONFIG.get('allowed_hosts', ['*']) @@ -189,14 +213,6 @@ if cors_opt: # Web URL endpoint for served static files STATIC_URL = '/static/' -# The filesystem location for served static files -STATIC_ROOT = os.path.abspath( - get_setting( - 'INVENTREE_STATIC_ROOT', - CONFIG.get('static_root', '/home/inventree/data/static') - ) -) - STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'InvenTree', 'static'), ] @@ -218,14 +234,6 @@ STATIC_COLOR_THEMES_DIR = os.path.join(STATIC_ROOT, 'css', 'color-themes') # Web URL endpoint for served media files MEDIA_URL = '/media/' -# The filesystem location for served static files -MEDIA_ROOT = os.path.abspath( - get_setting( - 'INVENTREE_MEDIA_ROOT', - CONFIG.get('media_root', '/home/inventree/data/media') - ) -) - if DEBUG: logger.info("InvenTree running in DEBUG mode")