From 0dd3389518046476659e0b7464c83fb8b4de857b Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 18 Nov 2021 19:59:14 +1100 Subject: [PATCH 01/13] Read "DEMO_MODE" into settings.py --- InvenTree/InvenTree/settings.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index c5a90ac7f3..c9d6e72086 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -92,6 +92,12 @@ DEBUG = _is_true(get_setting( CONFIG.get('debug', True) )) +# Determine if we are running in "demo mode" +DEMO_MODE = _is_true(get_setting( + 'INVENTREE_DEMO', + CONFIG.get('demo', False) +)) + DOCKER = _is_true(get_setting( 'INVENTREE_DOCKER', False From 4aeac79ba5cd2eee0dd6b339d6f70dfde762c823 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 18 Nov 2021 20:08:24 +1100 Subject: [PATCH 02/13] Remove very old unused file --- InvenTree/InvenTree/utils.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 InvenTree/InvenTree/utils.py diff --git a/InvenTree/InvenTree/utils.py b/InvenTree/InvenTree/utils.py deleted file mode 100644 index dc28da81a0..0000000000 --- a/InvenTree/InvenTree/utils.py +++ /dev/null @@ -1,13 +0,0 @@ -from rest_framework.views import exception_handler - - -def api_exception_handler(exc, context): - response = exception_handler(exc, context) - - # Now add the HTTP status code to the response. - if response is not None: - - data = {'error': response.data} - response.data = data - - return response From 1f5e4a1e6bf8aa25029d783d3d24280c3d5deb68 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 18 Nov 2021 20:17:27 +1100 Subject: [PATCH 03/13] Adds a template tag for testing if the server is running in demo mode --- .../part/templatetags/inventree_extras.py | 6 ++++++ InvenTree/templates/base.html | 19 +++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 42c66cf78e..fa739d9bd2 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -89,6 +89,12 @@ def inventree_in_debug_mode(*args, **kwargs): return djangosettings.DEBUG +@register.simple_tag() +def inventree_demo_mode(*args, **kwargs): + """ Return True if the server is running in DEMO mode """ + + return djangosettings.DEMO_MODE + @register.simple_tag() def inventree_docker_mode(*args, **kwargs): diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index 6dc0d7d78a..262a749bfa 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -86,25 +86,20 @@
- - {% if server_restart_required %} -
+ + {% block alerts %} +
+ + {% if server_restart_required %} -
- {% endif %} - - {% block alerts %} -
- + {% endif %}
{% endblock %} From 2a5b882a252e9df9a748373a7e650872374df2dd Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 18 Nov 2021 20:34:50 +1100 Subject: [PATCH 04/13] Navbar updates - Display "demo mode" with link to docs - Remove "admin" menu action --- InvenTree/InvenTree/settings.py | 5 ++++- InvenTree/templates/navbar.html | 6 +++++- InvenTree/templates/navbar_demo.html | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 InvenTree/templates/navbar_demo.html diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index c9d6e72086..cda30b0a27 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -240,7 +240,10 @@ STATIC_COLOR_THEMES_DIR = os.path.join(STATIC_ROOT, 'css', 'color-themes') MEDIA_URL = '/media/' if DEBUG: - logger.info("InvenTree running in DEBUG mode") + logger.info("InvenTree running with DEBUG enabled") + +if DEMO_MODE: + logger.warning("InvenTree running in DEMO mode") logger.debug(f"MEDIA_ROOT: '{MEDIA_ROOT}'") logger.debug(f"STATIC_ROOT: '{STATIC_ROOT}'") diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index eeb049d320..c339d7b4e1 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -4,6 +4,7 @@ {% settings_value 'BARCODE_ENABLE' as barcodes %} {% settings_value 'STICKY_HEADER' user=request.user as sticky %} +{% inventree_demo_mode as demo %}