Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP_Add Django Debug Toolbar #2940

Draft
wants to merge 4 commits into
base: testing
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ PASSWORD_STORE_DIR=/root/.password-store

# Django
DJANGO_SETTINGS_MODULE=settings
#DJANGO_DEBUG=True
9 changes: 8 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ env > poetry-install.txt
poetry --version >> poetry-install.txt
poetry self show plugins >> poetry-install.txt
# /usr/local/bin/poetry -> /opt/pipx/venvs/poetry
poetry install -vvv --no-interaction --no-ansi >> poetry-install.txt 2>&1

if [ "$DJANGO_DEBUG" = "True" ]; then
echo "Install Django Debug Toolbar."
poetry install -vvv --no-interaction --no-ansi --with dev >> poetry-install-dev.txt 2>&1
else
echo "Normal install."
poetry install -vvv --no-interaction --no-ansi >> poetry-install.txt 2>&1
fi
echo

# Source package version from pyproject.toml's (version = "5.0.14") via `poetry version` output:
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ optional = true

[tool.poetry.group.dev.dependencies]
black = "*"
django-debug-toolbar = "^4.4.6"

[tool.poetry.scripts]
# https://python-poetry.org/docs/pyproject#scripts
Expand Down
27 changes: 27 additions & 0 deletions src/rockstor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

# Django settings for Rockstor project.
import os
import sys

import distro
import keyring
from huey import SqliteHuey
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions src/rockstor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()