Skip to content

Move settings reset logic to settings module. #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from functools import lru_cache

from django.conf import settings
from django.dispatch import receiver
from django.test.signals import setting_changed

CONFIG_DEFAULTS = {
# Toolbar options
Expand Down Expand Up @@ -71,3 +73,18 @@ def get_panels():
except AttributeError:
PANELS = PANELS_DEFAULTS
return PANELS


@receiver(setting_changed)
def update_toolbar_config(*, setting, **kwargs):
"""
Refresh configuration when overriding settings.
"""
if setting == "DEBUG_TOOLBAR_CONFIG":
get_config.cache_clear()
elif setting == "DEBUG_TOOLBAR_PANELS":
from debug_toolbar.toolbar import DebugToolbar

get_panels.cache_clear()
DebugToolbar._panel_classes = None
# Not implemented: invalidate debug_toolbar.urls.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Next version
* Removed support for Django < 3.2.
* Updated check ``W006`` to look for
``django.template.loaders.app_directories.Loader``.
* Reset settings when overridden in tests. Packages or projects using
django-debug-toolbar can now use Django’s test settings tools, like
``@override_settings``, to reconfigure the toolbar during tests.

3.2.4 (2021-12-15)
------------------
Expand Down
21 changes: 0 additions & 21 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
# Refresh the debug toolbar's configuration when overriding settings.

from django.dispatch import receiver
from django.test.signals import setting_changed

from debug_toolbar import settings as dt_settings
from debug_toolbar.toolbar import DebugToolbar


@receiver(setting_changed)
def update_toolbar_config(**kwargs):
if kwargs["setting"] == "DEBUG_TOOLBAR_CONFIG":
dt_settings.get_config.cache_clear()


@receiver(setting_changed)
def update_toolbar_panels(**kwargs):
if kwargs["setting"] == "DEBUG_TOOLBAR_PANELS":
dt_settings.get_panels.cache_clear()
DebugToolbar._panel_classes = None
# Not implemented: invalidate debug_toolbar.urls.