diff --git a/src/rockstor/settings.py b/src/rockstor/settings.py index afee8c75a..232e503e1 100644 --- a/src/rockstor/settings.py +++ b/src/rockstor/settings.py @@ -18,6 +18,8 @@ # Django settings for Rockstor project. import os +import sys + import distro import keyring from huey import SqliteHuey @@ -162,7 +164,7 @@ ] MIDDLEWARE = ( - "debug_toolbar.middleware.DebugToolbarMiddleware", + # "debug_toolbar.middleware.DebugToolbarMiddleware", # New in 1.8, 1.11 newly sets Content-Length header. # 'django.middleware.common.CommonMiddleware', "django.contrib.sessions.middleware.SessionMiddleware", @@ -201,7 +203,7 @@ "smart_manager", "oauth2_provider", "huey.contrib.djhuey", - "debug_toolbar", + # "debug_toolbar", ) # https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-STORAGES @@ -473,15 +475,27 @@ # For live updates (running system) we call distro.version() directly in code. OS_DISTRO_VERSION = distro.version() # 3, 15.0 ,20181107 -# Django Debug Toolbar-related settings and confrguration -INTERNAL_IPS = [ - "127.0.0.1", # It seems requests always come from this when using DRF -] - -# https://django-debug-toolbar.readthedocs.io/en/stable/configuration.html -DEBUG_TOOLBAR_CONFIG = { - # Update to the latest AJAX request - # Without this, we can only catch the initial request - # which is not helpful in most of our cases - "UPDATE_ON_FETCH": True -} +# DJANGO DEBUG TOOLBAR settings and configuration +# recommended NOT to use the toolbar when running tests +# so enable it only when NOT running tests or NOT DEBUG +TESTING = "test" in sys.argv +if (not TESTING) and DEBUG: + INSTALLED_APPS = [ + *INSTALLED_APPS, + "debug_toolbar", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + *MIDDLEWARE, + ] + INTERNAL_IPS = [ + "127.0.0.1", # It seems requests always come from this when using DRF + ] + + # https://django-debug-toolbar.readthedocs.io/en/stable/configuration.html + DEBUG_TOOLBAR_CONFIG = { + # Update to the latest AJAX request + # Without this, we can only see the initial request in the toolbar panel + # Previous queries can still be seen and inspected in the "History" panel, though + "UPDATE_ON_FETCH": True + } diff --git a/src/rockstor/urls.py b/src/rockstor/urls.py index 0a8c03fb1..7542c35d4 100644 --- a/src/rockstor/urls.py +++ b/src/rockstor/urls.py @@ -18,7 +18,6 @@ from django.urls import include, re_path from django.views.static import serve from django.conf import settings -from debug_toolbar.toolbar import debug_toolbar_urls from smart_manager.views import ( BaseServiceView, @@ -150,4 +149,11 @@ re_path( r"^api/update-subscriptions/", include("storageadmin.urls.update_subscription") ), -] + debug_toolbar_urls() +] + +if (not settings.TESTING) and settings.DEBUG: + from debug_toolbar.toolbar import debug_toolbar_urls + + urlpatterns = [ + *urlpatterns, + ] + debug_toolbar_urls()