Skip to content

Commit

Permalink
build(debug): add django-debug-toolbar to debug dependencies
Browse files Browse the repository at this point in the history
configure urls.py and settings.py to allow the toolbar to show
when DEBUG = True
  • Loading branch information
dchiller committed Sep 20, 2024
1 parent 7eb739a commit ddcc94d
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 153 deletions.
19 changes: 14 additions & 5 deletions app/public/cantusdata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Application definition

INSTALLED_APPS = (
INSTALLED_APPS = [
# Template apps
"django.contrib.admin",
"django.contrib.auth",
Expand All @@ -46,20 +46,23 @@
"rest_framework",
"rest_framework.authtoken",
"cantusdata.CantusdataConfig",
)
]

if DEBUG:
INSTALLED_APPS += ("django_extensions",)
INSTALLED_APPS.extend(["django_extensions", "debug_toolbar"])

MIDDLEWARE = (
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware", # Migration: + django 3.1
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
)
]

if DEBUG:
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")

ROOT_URLCONF = "cantusdata.urls"

Expand Down Expand Up @@ -179,3 +182,9 @@
CELERY_RESULT_EXTENDED = True
CELERY_APP = "cantusdata"
CELERY_TASK_TRACK_STARTED = True

DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": lambda request: (
False if request.headers.get("x-requested-with") == "XMLHttpRequest" else True
),
}
5 changes: 5 additions & 0 deletions app/public/cantusdata/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from cantusdata.views.browse import browse_view
Expand Down Expand Up @@ -110,5 +111,9 @@
# Disambiguates json/html/browsable-api urls
urlpatterns = format_suffix_patterns(urlpatterns)

if settings.DEBUG:
from debug_toolbar.toolbar import debug_toolbar_urls # type: ignore

urlpatterns += debug_toolbar_urls()

admin.site.site_header = "Cantus Ultimus Admin"
Loading

0 comments on commit ddcc94d

Please sign in to comment.