Install debug toolbar in debug mode

This commit is contained in:
Andrew Godwin 2022-12-20 15:26:39 +00:00
parent 12a838eb0e
commit f82b82502c
5 changed files with 17 additions and 7 deletions

View file

@ -40,11 +40,6 @@ class Individual(TemplateView):
ancestors, descendants = PostService(self.post_obj).context( ancestors, descendants = PostService(self.post_obj).context(
self.request.identity self.request.identity
) )
print(
self.post_obj.to_mastodon_json(),
self.post_obj.emojis.all(),
self.post_obj.emojis.usable(),
)
return { return {
"identity": self.identity, "identity": self.identity,
"post": self.post_obj, "post": self.post_obj,

View file

@ -1,5 +1,6 @@
from time import time from time import time
from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed from django.core.exceptions import MiddlewareNotUsed
from core import sentry from core import sentry
@ -65,3 +66,10 @@ class SentryTaggingMiddleware:
sentry.set_takahe_app("web") sentry.set_takahe_app("web")
response = self.get_response(request) response = self.get_response(request)
return response return response
def show_toolbar(request):
"""
Determines whether to show the debug toolbar on a given page.
"""
return settings.DEBUG and request.user.is_authenticated and request.user.admin

View file

@ -5,6 +5,7 @@ cryptography~=38.0
dj_database_url~=1.0.0 dj_database_url~=1.0.0
django-cache-url~=3.4.2 django-cache-url~=3.4.2
django-cors-headers~=3.13.0 django-cors-headers~=3.13.0
django-debug-toolbar~=3.8.1
django-htmx~=1.13.0 django-htmx~=1.13.0
django-ninja~=0.19.1 django-ninja~=0.19.1
django-oauth-toolkit~=2.2.0 django-oauth-toolkit~=2.2.0

View file

@ -175,8 +175,9 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"django_htmx",
"corsheaders", "corsheaders",
"debug_toolbar",
"django_htmx",
"core", "core",
"activities", "activities",
"api", "api",
@ -194,6 +195,7 @@ MIDDLEWARE = [
"django.middleware.common.CommonMiddleware", "django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware", "django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.contrib.messages.middleware.MessageMiddleware", "django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_htmx.middleware.HtmxMiddleware", "django_htmx.middleware.HtmxMiddleware",
@ -309,6 +311,8 @@ MEDIA_URL = SETUP.MEDIA_URL
MEDIA_ROOT = SETUP.MEDIA_ROOT MEDIA_ROOT = SETUP.MEDIA_ROOT
MAIN_DOMAIN = SETUP.MAIN_DOMAIN MAIN_DOMAIN = SETUP.MAIN_DOMAIN
if DEBUG:
DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": "core.middleware.show_toolbar"}
if SETUP.USE_PROXY_HEADERS: if SETUP.USE_PROXY_HEADERS:
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

View file

@ -1,6 +1,6 @@
from django.conf import settings as djsettings from django.conf import settings as djsettings
from django.contrib import admin as djadmin from django.contrib import admin as djadmin
from django.urls import path, re_path from django.urls import include, path, re_path
from activities.views import compose, debug, explore, follows, posts, search, timelines from activities.views import compose, debug, explore, follows, posts, search, timelines
from api.views import api_router, oauth from api.views import api_router, oauth
@ -246,6 +246,8 @@ urlpatterns = [
path(".stator/", stator.RequestRunner.as_view()), path(".stator/", stator.RequestRunner.as_view()),
# Django admin # Django admin
path("djadmin/", djadmin.site.urls), path("djadmin/", djadmin.site.urls),
# Debug toolbar
path("__debug__/", include("debug_toolbar.urls")),
# Media files # Media files
re_path( re_path(
r"^media/(?P<path>.*)$", r"^media/(?P<path>.*)$",