aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-16 09:58:32 +0100
committerAymeric Augustin2013-11-16 10:10:09 +0100
commit3d639ab35c2ca038d738253b93b593a755756cff (patch)
treea7d5082b065c5ab11fcfacddfc71465d90f90993
parent71a2c1237de8ed759c3ba415c8bfd91b62adf193 (diff)
downloaddjango-debug-toolbar-3d639ab35c2ca038d738253b93b593a755756cff.tar.bz2
Avoid providing the same information through multiple paths.
-rw-r--r--debug_toolbar/panels/signals.py3
-rw-r--r--debug_toolbar/panels/template/panel.py3
-rw-r--r--debug_toolbar/templates/debug_toolbar/base.html12
-rw-r--r--debug_toolbar/toolbar.py26
4 files changed, 19 insertions, 25 deletions
diff --git a/debug_toolbar/panels/signals.py b/debug_toolbar/panels/signals.py
index 1d24b80..25e250b 100644
--- a/debug_toolbar/panels/signals.py
+++ b/debug_toolbar/panels/signals.py
@@ -16,7 +16,6 @@ except ImportError:
connection_created = None
from debug_toolbar.panels import DebugPanel
-from debug_toolbar.utils import settings as dt_settings
class SignalDebugPanel(DebugPanel):
@@ -63,7 +62,7 @@ class SignalDebugPanel(DebugPanel):
@property
def signals(self):
signals = self.SIGNALS.copy()
- for signal in dt_settings.CONFIG['EXTRA_SIGNALS']:
+ for signal in self.toolbar.config['EXTRA_SIGNALS']:
mod_path, signal_name = signal.rsplit('.', 1)
signals_mod = import_module(mod_path)
signals[signal_name] = getattr(signals_mod, signal_name)
diff --git a/debug_toolbar/panels/template/panel.py b/debug_toolbar/panels/template/panel.py
index 7c4b06a..b877a53 100644
--- a/debug_toolbar/panels/template/panel.py
+++ b/debug_toolbar/panels/template/panel.py
@@ -16,7 +16,6 @@ from django.utils.translation import ugettext_lazy as _
from debug_toolbar.panels import DebugPanel
from debug_toolbar.panels.sql.tracking import recording, SQLQueryTriggered
-from debug_toolbar.utils import settings as dt_settings
# Code taken and adapted from Simon Willison and Django Snippets:
# http://www.djangosnippets.org/snippets/766/
@@ -147,7 +146,7 @@ class TemplateDebugPanel(DebugPanel):
template.origin_name = 'No origin'
info['template'] = template
# Clean up context for better readability
- if dt_settings.CONFIG['SHOW_TEMPLATE_CONTEXT']:
+ if self.toolbar.config['SHOW_TEMPLATE_CONTEXT']:
context_list = template_data.get('context', [])
info['context'] = '\n'.join(context_list)
template_context.append(info)
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index 424dc57..b54a343 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -9,16 +9,16 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar
<script src="{{ STATIC_URL }}debug_toolbar/js/jquery.cookie.js"></script>
<script src="{{ STATIC_URL }}debug_toolbar/js/toolbar.js"></script>
<div id="djDebug" style="display:none;" dir="ltr"
- data-storage-id="{{ storage_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
- {{ TOOLBAR_ROOT_TAG_ATTRS|safe }}>
+ data-storage-id="{{ toolbar.storage_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
+ {{ toolbar.config.ROOT_TAG_ATTRS|safe }}>
<div style="display:none;" id="djDebugToolbar">
<ul id="djDebugPanelList">
- {% if panels %}
+ {% if toolbar.panels %}
<li><a id="djHideToolBarButton" href="#" title="{% trans "Hide Toolbar" %}">{% trans "Hide" %} &#187;</a></li>
{% else %}
<li id="djDebugButton">DEBUG</li>
{% endif %}
- {% for panel in panels %}
+ {% for panel in toolbar.panels %}
<li class="djDebugPanelButton">
<input type="checkbox" data-cookie="djdt{{ panel.panel_id }}" {% if panel.enabled %}checked="checked" title="{% trans "Disable for next and successive requests" %}"{% else %}title="{% trans "Enable for next and successive requests" %}"{% endif %} />
{% if panel.has_content and panel.enabled %}
@@ -44,7 +44,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar
<div style="display:none;" id="djDebugToolbarHandle">
<span title="{% trans "Show Toolbar" %}" id="djShowToolBarButton">&#171;</span>
</div>
- {% for panel in panels %}
+ {% for panel in toolbar.panels %}
{% if panel.has_content and panel.enabled %}
<div id="{{ panel.panel_id }}" class="panelContent">
<div class="djDebugPanelTitle">
@@ -53,7 +53,7 @@ if(!window.jQuery) document.write('<scr'+'ipt src="{{ STATIC_URL }}debug_toolbar
</div>
<div class="djDebugPanelContent">
<div class="scroll">
- {% if not storage_id %}{{ panel.content }}{% endif %}
+ {% if not toolbar.storage_id %}{{ panel.content }}{% endif %}
</div>
</div>
</div>
diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py
index 8b48a9f..7041610 100644
--- a/debug_toolbar/toolbar.py
+++ b/debug_toolbar/toolbar.py
@@ -20,19 +20,17 @@ class DebugToolbar(object):
def __init__(self, request):
self.request = request
- self._panels = SortedDict()
- base_url = self.request.META.get('SCRIPT_NAME', '')
- self.config = {}
- self.config.update(dt_settings.CONFIG)
+ self.config = dt_settings.CONFIG.copy()
self.template_context = {
- 'BASE_URL': base_url, # for backwards compatibility
'STATIC_URL': settings.STATIC_URL,
- 'TOOLBAR_ROOT_TAG_ATTRS': self.config['ROOT_TAG_ATTRS'],
+ 'toolbar': self,
}
- self.stats = {}
+ self._panels = SortedDict()
for panel_class in self.get_panel_classes():
panel_instance = panel_class(self, context=self.template_context)
self._panels[panel_instance.panel_id] = panel_instance
+ self.stats = {}
+ self.storage_id = None
# Manage panels
@@ -62,10 +60,9 @@ class DebugToolbar(object):
"""
Renders the overall Toolbar with panels inside.
"""
- context = self.template_context.copy()
- context['panels'] = self.panels
if not self.should_render_panels():
- context['storage_id'] = self.store()
+ self.store()
+ context = self.template_context.copy()
return render_to_string('debug_toolbar/base.html', context)
# Handle storing toolbars in memory and fetching them later on
@@ -73,20 +70,19 @@ class DebugToolbar(object):
_storage = SortedDict()
def should_render_panels(self):
- render_panels = dt_settings.CONFIG['RENDER_PANELS']
+ render_panels = self.config['RENDER_PANELS']
if render_panels is None:
render_panels = self.request.META['wsgi.multiprocess']
return render_panels
def store(self):
- storage_id = uuid.uuid4().hex
+ self.storage_id = uuid.uuid4().hex
cls = type(self)
- cls._storage[storage_id] = self
- for _ in range(len(cls._storage) - dt_settings.CONFIG['RESULTS_CACHE_SIZE']):
+ cls._storage[self.storage_id] = self
+ for _ in range(len(cls._storage) - self.config['RESULTS_CACHE_SIZE']):
# When we drop support for Python 2.6 and switch to
# collections.OrderedDict, use popitem(last=False).
del cls._storage[cls._storage.keyOrder[0]]
- return storage_id
@classmethod
def fetch(cls, storage_id):