Skip to content

Commit

Permalink
Enable Django Debug Toolbar in deployed environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHolmes123 committed Sep 3, 2024
1 parent 3a95de7 commit bc6e2bd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
17 changes: 17 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,20 @@
"Apply for an export certificate": env.gtm_exporter_container_id,
"Apply for an import licence": env.gtm_importer_container_id,
}

# Djando debug toolbar config.
# Almost exclusively used locally but can be temporarily enabled in deployed environments
SHOW_DEBUG_TOOLBAR = env.show_debug_toolbar
if SHOW_DEBUG_TOOLBAR:
INSTALLED_APPS += [
"debug_toolbar",
]

MIDDLEWARE += [
"debug_toolbar.middleware.DebugToolbarMiddleware",
]

DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
"SHOW_TOOLBAR_CALLBACK": lambda x: SHOW_DEBUG_TOOLBAR,
}
29 changes: 0 additions & 29 deletions config/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,16 @@
AWS_STORAGE_BUCKET_NAME = "icms.local"
AWS_S3_ENDPOINT_URL = env.local_aws_s3_endpoint_url

# Debug toolbar config
INTERNAL_IPS = ("127.0.0.1", "localhost")
INSTALLED_APPS += [
"debug_toolbar",
"django_extensions",
]

MIDDLEWARE += [
"debug_toolbar.middleware.DebugToolbarMiddleware",
]

# When debugging queries in console
SHOW_DB_QUERIES = env.show_db_queries

if SHOW_DB_QUERIES:
MIDDLEWARE += ["web.middleware.common.DBQueriesMiddleware"]

DEBUG_TOOLBAR_PANELS = [
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
"debug_toolbar.panels.redirects.RedirectsPanel",
"debug_toolbar.panels.profiling.ProfilingPanel",
]

SHOW_DEBUG_TOOLBAR = env.show_debug_toolbar

DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
"SHOW_TOOLBAR_CALLBACK": lambda x: SHOW_DEBUG_TOOLBAR,
}

NPM_STATIC_FILES_LOCATION = "web/static/3rdparty"

NPM_FILE_PATTERNS = {
Expand Down
4 changes: 4 additions & 0 deletions config/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@
GOV_UK_ONE_LOGIN_AUTHENTICATION_LEVEL = one_login_types.AuthenticationLevel.MEDIUM_LEVEL

SAVE_GENERATED_PDFS = env.save_generated_pdfs

# Disable toolbar if enabled when running tests.
if SHOW_DEBUG_TOOLBAR:
DEBUG_TOOLBAR_CONFIG["SHOW_TOOLBAR_CALLBACK"] = lambda _: False
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
path("", include("web.urls")),
]

if settings.DEBUG:
if settings.SHOW_DEBUG_TOOLBAR:
import debug_toolbar

urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns
1 change: 1 addition & 0 deletions requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dj-database-url==2.1.0
django-celery-results==2.5.1
django-chunk-upload-handlers==0.0.14
django-compressor==4.4
django-debug-toolbar~=4.4
django-filter==23.4
django-guardian==2.4.0
django-htmlmin==0.11.0
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# add packages needed only for development

black==24.4.2
django-debug-toolbar==4.2
django-extensions==3.2.3
factory-boy==3.0.1
faker==4.1.2
Expand Down

0 comments on commit bc6e2bd

Please sign in to comment.