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(
self.request.identity
)
print(
self.post_obj.to_mastodon_json(),
self.post_obj.emojis.all(),
self.post_obj.emojis.usable(),
)
return {
"identity": self.identity,
"post": self.post_obj,

View File

@ -1,5 +1,6 @@
from time import time
from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed
from core import sentry
@ -65,3 +66,10 @@ class SentryTaggingMiddleware:
sentry.set_takahe_app("web")
response = self.get_response(request)
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
django-cache-url~=3.4.2
django-cors-headers~=3.13.0
django-debug-toolbar~=3.8.1
django-htmx~=1.13.0
django-ninja~=0.19.1
django-oauth-toolkit~=2.2.0

View File

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

View File

@ -1,6 +1,6 @@
from django.conf import settings as djsettings
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 api.views import api_router, oauth
@ -246,6 +246,8 @@ urlpatterns = [
path(".stator/", stator.RequestRunner.as_view()),
# Django admin
path("djadmin/", djadmin.site.urls),
# Debug toolbar
path("__debug__/", include("debug_toolbar.urls")),
# Media files
re_path(
r"^media/(?P<path>.*)$",