diff --git a/poetry.lock b/poetry.lock index 9da6e3d49..8d6d0c604 100644 --- a/poetry.lock +++ b/poetry.lock @@ -407,6 +407,21 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-debug-toolbar" +version = "4.4.6" +description = "A configurable set of panels that display various debug information about the current request/response." +optional = false +python-versions = ">=3.8" +files = [ + {file = "django_debug_toolbar-4.4.6-py3-none-any.whl", hash = "sha256:3beb671c9ec44ffb817fad2780667f172bd1c067dbcabad6268ce39a81335f45"}, + {file = "django_debug_toolbar-4.4.6.tar.gz", hash = "sha256:36e421cb908c2f0675e07f9f41e3d1d8618dc386392ec82d23bcfcd5d29c7044"}, +] + +[package.dependencies] +django = ">=4.2.9" +sqlparse = ">=0.2" + [[package]] name = "django-oauth-toolkit" version = "2.4.0" @@ -1416,4 +1431,4 @@ testing = ["coverage[toml]", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "0c21eddc7cfacd5630b92eedc3aaf632e9ff8636a034e3f671bdd7911321836c" +content-hash = "e682775a5baa4268794f4e33b473f849f4fd5fafa4c20ad3f8a1562049279a8a" diff --git a/pyproject.toml b/pyproject.toml index caaa5fb2e..700b54292 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,6 +88,7 @@ URLObject = "==2.1.1" keyring-pass = "*" # https://pypi.org/project/supervisor/ 4.1.0 onwards embeds unmaintained meld3 supervisor = "==4.2.4" +django-debug-toolbar = "^4.4.6" # used only when DEBUG = True # `poetry install --with dev` [tool.poetry.group.dev] diff --git a/src/rockstor/settings.py b/src/rockstor/settings.py index b6658904c..d38b2aa56 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 @@ -470,3 +472,28 @@ # Note that the following will capture the build os version. # For live updates (running system) we call distro.version() directly in code. OS_DISTRO_VERSION = distro.version() # 3, 15.0 ,20181107 + +# DJANGO DEBUG TOOLBAR settings and configuration +# recommended NOT to use the toolbar when running tests +# so enable it only when in DEBUG mode and NOT running tests +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 c103437bb..4f0b7270f 100644 --- a/src/rockstor/urls.py +++ b/src/rockstor/urls.py @@ -150,3 +150,13 @@ r"^api/update-subscriptions/", include("storageadmin.urls.update_subscription") ), ] + +# DJANGO DEBUG TOOLBAR +# recommended NOT to use the toolbar when running tests +# so enable it only when in DEBUG mode and NOT running tests +if (not settings.TESTING) and settings.DEBUG: + from debug_toolbar.toolbar import debug_toolbar_urls + + urlpatterns = [ + *urlpatterns, + ] + debug_toolbar_urls()