From db0e3dd2a9efee15afd0f861edf50fd067eb2d68 Mon Sep 17 00:00:00 2001 From: Tom Webber Date: Thu, 18 Jul 2024 15:45:24 +0100 Subject: [PATCH 1/4] feat: add django-debug-toolbar --- core/settings.py | 13 +++++++++++-- core/urls.py | 7 +++++++ poetry.lock | 15 +++++++++++++++ pyproject.toml | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/core/settings.py b/core/settings.py index c016f2ee..c0c443b9 100644 --- a/core/settings.py +++ b/core/settings.py @@ -30,7 +30,7 @@ pass # Application definition -INSTALLED_APPS = [ +INSTALLED_APPS: list[str] = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", @@ -45,10 +45,14 @@ "waffle", ] +INTERNAL_IPS: list[str] = [ + "127.0.0.1", +] + if os.environ.get("AZURE_AUTH_ENABLED", "true") != "false": INSTALLED_APPS.append("azure_auth") -MIDDLEWARE = [ +MIDDLEWARE: list[str] = [ "django_prometheus.middleware.PrometheusBeforeMiddleware", "django.middleware.security.SecurityMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", @@ -226,6 +230,11 @@ environment=ENV or "local", ) +# add debug toolbar when not running tests +if not TESTING: + INSTALLED_APPS.insert(-1, "debug_toolbar") + MIDDLEWARE.insert(1, "debug_toolbar.middleware.DebugToolbarMiddleware") + # Enable / Disable Azure Auth if not os.environ.get("AZURE_AUTH_ENABLED", "true") == "false": # Adds the Azure Authentication middleware to the Django Authentication middleware diff --git a/core/urls.py b/core/urls.py index 593393dd..58c51c0a 100644 --- a/core/urls.py +++ b/core/urls.py @@ -15,6 +15,8 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from debug_toolbar.toolbar import debug_toolbar_urls +from django.conf import settings from django.contrib import admin from django.urls import include, path @@ -27,3 +29,8 @@ path("", include("home.urls", namespace="home")), path("", include("django_prometheus.urls")), ] + +if not settings.TESTING: + urlpatterns = [ + *urlpatterns, + ] + debug_toolbar_urls() diff --git a/poetry.lock b/poetry.lock index 94a6f38b..35078f79 100644 --- a/poetry.lock +++ b/poetry.lock @@ -809,6 +809,21 @@ files = [ Django = ">=3.2" msal = ">=1.18.0,<2.0.0" +[[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-prometheus" version = "2.3.1" diff --git a/pyproject.toml b/pyproject.toml index 13b1e4a8..c4c4a5db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ django-azure-auth = "^2.0.0" django-waffle = "^4.1.0" psycopg = "^3.2.1" psycopg-binary = "^3.2.1" +django-debug-toolbar = "^4.4.6" [tool.poetry.group.dev.dependencies] black = "^24.8.0" From 5f6cbd1bc5667ce3da33fe67c8840e81a1465ee3 Mon Sep 17 00:00:00 2001 From: Tom Webber Date: Fri, 19 Jul 2024 15:42:55 +0100 Subject: [PATCH 2/4] suggestion: only use debug toolbar if `DEBUG` is true --- core/settings.py | 2 +- core/urls.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/settings.py b/core/settings.py index c0c443b9..e6a9d9dc 100644 --- a/core/settings.py +++ b/core/settings.py @@ -231,7 +231,7 @@ ) # add debug toolbar when not running tests -if not TESTING: +if (not TESTING) or (not DEBUG): INSTALLED_APPS.insert(-1, "debug_toolbar") MIDDLEWARE.insert(1, "debug_toolbar.middleware.DebugToolbarMiddleware") diff --git a/core/urls.py b/core/urls.py index 58c51c0a..9b6a0fbc 100644 --- a/core/urls.py +++ b/core/urls.py @@ -30,7 +30,7 @@ path("", include("django_prometheus.urls")), ] -if not settings.TESTING: +if (not settings.TESTING) or (not settings.DEBUG): urlpatterns = [ *urlpatterns, ] + debug_toolbar_urls() From 2678a6e4c659c45003e8be9ca9281d244b13b40e Mon Sep 17 00:00:00 2001 From: Tom Webber Date: Fri, 23 Aug 2024 15:02:21 +0100 Subject: [PATCH 3/4] fix: debug and testing interactions --- core/settings.py | 2 +- core/urls.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/settings.py b/core/settings.py index e6a9d9dc..37990580 100644 --- a/core/settings.py +++ b/core/settings.py @@ -231,7 +231,7 @@ ) # add debug toolbar when not running tests -if (not TESTING) or (not DEBUG): +if DEBUG and not TESTING: INSTALLED_APPS.insert(-1, "debug_toolbar") MIDDLEWARE.insert(1, "debug_toolbar.middleware.DebugToolbarMiddleware") diff --git a/core/urls.py b/core/urls.py index 9b6a0fbc..51b37400 100644 --- a/core/urls.py +++ b/core/urls.py @@ -30,7 +30,7 @@ path("", include("django_prometheus.urls")), ] -if (not settings.TESTING) or (not settings.DEBUG): +if settings.DEBUG and not settings.TESTING: urlpatterns = [ *urlpatterns, ] + debug_toolbar_urls() From 32f6f2b02356ff8e22bfba5c18e3700f9b9e9509 Mon Sep 17 00:00:00 2001 From: Tom Webber Date: Mon, 9 Sep 2024 14:17:52 +0100 Subject: [PATCH 4/4] chore: update poetry lock --- poetry.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 6391ea84..59952e79 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "acryl-datahub" @@ -3134,4 +3134,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "c8463d9a43a531980200f1dfe575fdb652b0232c2717eb56a33915d802ff3b75" +content-hash = "988e6fc1908a22e27a042eb5d6c4f8294d6c70007bbc0c65db3f2948265460fe"