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 5 commits into
base: testing
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}
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
# If using htmx, to retain toolbar handle
# through page renders add this
"ROOT_TAG_EXTRA_ATTRS": "hx-preserve"
}

If the project is contemplating to use htmx (#2735 and #2821) then this would also be required (among other things of course to enable htmx overall), according to:
https://django-debug-toolbar.readthedocs.io/en/stable/tips.html#working-with-htmx-and-turbo

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()