Skip to content

Commit

Permalink
Initial setup and config of Django Debug Toolbar rockstor#2939
Browse files Browse the repository at this point in the history
Add django-debug-toolbar package to the optional `dev` dependency group
Add `--dev` flag to build.sh to run `poetry install` with that flag
Add DjDTB to settings.py
Add DjDTB urls
  • Loading branch information
FroggyFlox committed Dec 18, 2024
1 parent 812f1cf commit 3b9f8f2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
14 changes: 13 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# exit on error
set -o errexit

DEV_MODE=0
if [ "$1" = "--dev" ]; then
DEV_MODE=1
fi

# Install Poetry, a dependency management, packaging, and build system.
# Uninstall legacy/transitional Poetry version of 1.1.15
PATH="/root/.local/bin:$PATH" # ensure legacy path.
Expand Down Expand Up @@ -48,7 +53,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 [ $DEV_MODE -eq 1 ]; then
echo "Install djdt."
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
15 changes: 15 additions & 0 deletions src/rockstor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
]

MIDDLEWARE = (
"debug_toolbar.middleware.DebugToolbarMiddleware",
# New in 1.8, 1.11 newly sets Content-Length header.
# 'django.middleware.common.CommonMiddleware',
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down Expand Up @@ -200,6 +201,7 @@
"smart_manager",
"oauth2_provider",
"huey.contrib.djhuey",
"debug_toolbar",
)

# https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-STORAGES
Expand Down Expand Up @@ -470,3 +472,16 @@
# 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-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
}
3 changes: 2 additions & 1 deletion src/rockstor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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,
Expand Down Expand Up @@ -149,4 +150,4 @@
re_path(
r"^api/update-subscriptions/", include("storageadmin.urls.update_subscription")
),
]
] + debug_toolbar_urls()

0 comments on commit 3b9f8f2

Please sign in to comment.