diff options
| author | bkonkle | 2011-09-15 10:36:11 -0500 |
|---|---|---|
| committer | bkonkle | 2011-09-15 10:36:11 -0500 |
| commit | 717dc6815a9d4ddcd30efc17db11ade0f8f38354 (patch) | |
| tree | 5f3a3fceefe9bead41019c3216991337cc12fe6f /debug_toolbar/panels/sql.py | |
| parent | ed9bca7c00f6f326842d79e843f678787fac8b15 (diff) | |
| download | django-debug-toolbar-717dc6815a9d4ddcd30efc17db11ade0f8f38354.tar.bz2 | |
Edited all of the panels to use the stats API and not override the content method
Diffstat (limited to 'debug_toolbar/panels/sql.py')
| -rw-r--r-- | debug_toolbar/panels/sql.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 9527410..188e1eb 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -2,7 +2,6 @@ import re import uuid from django.db.backends import BaseDatabaseWrapper -from django.template.loader import render_to_string from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _, ungettext_lazy as __ @@ -14,6 +13,7 @@ from debug_toolbar.utils import sqlparse from debug_toolbar.utils.tracking.db import CursorWrapper from debug_toolbar.utils.tracking import replace_call + # Inject our tracking cursor @replace_call(BaseDatabaseWrapper.cursor) def cursor(func, self): @@ -26,6 +26,7 @@ def cursor(func, self): return CursorWrapper(result, self, logger=logger) + def get_isolation_level_display(engine, level): if engine == 'psycopg2': import psycopg2.extensions @@ -41,6 +42,7 @@ def get_isolation_level_display(engine, level): return choices.get(level) + def get_transaction_status_display(engine, level): if engine == 'psycopg2': import psycopg2.extensions @@ -56,12 +58,14 @@ def get_transaction_status_display(engine, level): return choices.get(level) + class SQLDebugPanel(DebugPanel): """ Panel that displays information about the SQL queries run while processing the request. """ name = 'SQL' + template = 'debug_toolbar/panels/sql.html' has_content = True def __init__(self, *args, **kwargs): @@ -205,18 +209,12 @@ class SQLDebugPanel(DebugPanel): if trans_id: self._queries[i-1][1]['ends_trans'] = True - self.stats = { + self.record_stats({ 'databases': sorted(self._databases.items(), key=lambda x: -x[1]['time_spent']), 'queries': [q for a, q in self._queries], 'sql_time': self._sql_time, - } - toolbar = DebugToolbarMiddleware.get_current() - toolbar.stats['sql'] = self.stats - - def content(self): - context = self.context.copy() - context.update(self.stats) - return render_to_string('debug_toolbar/panels/sql.html', context) + }) + class BoldKeywordFilter(sqlparse.filters.Filter): """sqlparse filter to bold SQL keywords""" @@ -230,10 +228,12 @@ class BoldKeywordFilter(sqlparse.filters.Filter): if is_keyword: yield sqlparse.tokens.Text, '</strong>' + def swap_fields(sql): return re.sub('SELECT</strong> (.*) <strong>FROM', 'SELECT</strong> <a class="djDebugUncollapsed djDebugToggle" href="#">•••</a> ' + '<a class="djDebugCollapsed djDebugToggle" href="#">\g<1></a> <strong>FROM', sql) + def reformat_sql(sql): stack = sqlparse.engine.FilterStack() stack.preprocess.append(BoldKeywordFilter()) # add our custom filter |
