Skip to content

Commit a8513e5

Browse files
committed
Add a .ready() method to the panel API
This method will be called for all installed panels from the DebugToolbarConfig.ready() method during Django initialization to support initialization that needs to happen unconditionally for the panel regardless of whether it is enabled for a particular request.
1 parent 3803724 commit a8513e5

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

debug_toolbar/apps.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class DebugToolbarConfig(AppConfig):
1717
def ready(self):
1818
from debug_toolbar.toolbar import DebugToolbar
1919

20-
# Import the panels when the app is ready. This allows panels
21-
# like CachePanel to enable the instrumentation immediately.
22-
DebugToolbar.get_panel_classes()
20+
# Import the panels when the app is ready and call their ready() methods. This
21+
# allows panels like CachePanel to enable their instrumentation immediately.
22+
for cls in DebugToolbar.get_panel_classes():
23+
cls.ready()
2324

2425

2526
def check_template_config(config):

debug_toolbar/panels/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ def scripts(self):
114114
"""
115115
return []
116116

117+
# Panel early initialization
118+
119+
@classmethod
120+
def ready(cls):
121+
"""
122+
Perform early initialization for the panel.
123+
124+
This should only include initialization or instrumentation that needs to
125+
be done unconditionally for the panel regardless of whether it is
126+
enabled for a particular request. It should be idempotent.
127+
"""
128+
pass
129+
117130
# URLs for panel-specific views
118131

119132
@classmethod

docs/panels.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ unauthorized access. There is no public CSS API at this time.
352352

353353
.. autoattribute:: debug_toolbar.panels.Panel.scripts
354354

355+
.. automethod:: debug_toolbar.panels.Panel.ready
356+
355357
.. automethod:: debug_toolbar.panels.Panel.get_urls
356358

357359
.. automethod:: debug_toolbar.panels.Panel.enable_instrumentation

0 commit comments

Comments
 (0)