Skip to content

Commit 687c289

Browse files
authored
Single source 'djdt' app name (#1588)
Avoid needing to keep multiple constants in sync by defining an APP_NAME constant in debug_toolbar.__init__ and referencing where it is needed.
1 parent 571b240 commit 687c289

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

debug_toolbar/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
__all__ = ["VERSION"]
1+
__all__ = ["APP_NAME", "VERSION"]
2+
3+
APP_NAME = "djdt"
24

35
# Do not use pkg_resources to find the version but set it here directly!
46
# see issue #1446
57
VERSION = "3.2.4"
68

79
# Code that discovers files or modules in INSTALLED_APPS imports this module.
8-
urls = "debug_toolbar.urls", "djdt" # See debug_toolbar/urls.py
10+
urls = "debug_toolbar.urls", APP_NAME

debug_toolbar/toolbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from django.urls.exceptions import Resolver404
1515
from django.utils.module_loading import import_string
1616

17-
from debug_toolbar import settings as dt_settings
17+
from debug_toolbar import APP_NAME, settings as dt_settings
1818

1919

2020
class DebugToolbar:
@@ -144,8 +144,6 @@ def is_toolbar_request(cls, request):
144144
"""
145145
Determine if the request is for a DebugToolbar view.
146146
"""
147-
from debug_toolbar.urls import app_name
148-
149147
# The primary caller of this function is in the middleware which may
150148
# not have resolver_match set.
151149
try:
@@ -154,7 +152,7 @@ def is_toolbar_request(cls, request):
154152
)
155153
except Resolver404:
156154
return False
157-
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name
155+
return resolver_match.namespaces and resolver_match.namespaces[-1] == APP_NAME
158156

159157
@staticmethod
160158
@lru_cache(maxsize=128)

debug_toolbar/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
from debug_toolbar import APP_NAME
12
from debug_toolbar.toolbar import DebugToolbar
23

3-
app_name = "djdt" # See debug_toolbar/__init__.py
4+
app_name = APP_NAME
45
urlpatterns = DebugToolbar.get_urls()

0 commit comments

Comments
 (0)