aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/panels/sql.py
diff options
context:
space:
mode:
authorDavid Cramer2011-03-28 17:30:19 -0700
committerDavid Cramer2011-03-28 17:30:19 -0700
commit4c7c43300ed0bfee6243cb5b59887837f2becb13 (patch)
treea9597fa662e1b7f5be3cbdffdec2c503dbde6674 /debug_toolbar/panels/sql.py
parent5aff6ee75f8af3dd46254953b0b0de7c8e19c8e2 (diff)
downloaddjango-debug-toolbar-4c7c43300ed0bfee6243cb5b59887837f2becb13.tar.bz2
Fail gracefully when theres no queries on a page
Diffstat (limited to 'debug_toolbar/panels/sql.py')
-rw-r--r--debug_toolbar/panels/sql.py77
1 files changed, 39 insertions, 38 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 5efafbb..e9e2569 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -202,46 +202,47 @@ class SQLDebugPanel(DebugPanel):
return ''
def content(self):
- width_ratio_tally = 0
- colors = [
- (256, 0, 0), # red
- (0, 256, 0), # blue
- (0, 0, 256), # green
- ]
- factor = int(256.0/(len(self._databases)*2.5))
- for n, db in enumerate(self._databases.itervalues()):
- rgb = [0, 0, 0]
- color = n % 3
- rgb[color] = 256 - n/3*factor
- nn = color
- # XXX: pretty sure this is horrible after so many aliases
- while rgb[color] < factor:
- print rgb[color], factor
- nc = min(256 - rgb[color], 256)
- rgb[color] += nc
- nn += 1
- if nn > 2:
- nn = 0
- rgb[nn] = nc
- db['rgb_color'] = rgb
+ if self._queries:
+ width_ratio_tally = 0
+ colors = [
+ (256, 0, 0), # red
+ (0, 256, 0), # blue
+ (0, 0, 256), # green
+ ]
+ factor = int(256.0/(len(self._databases)*2.5))
+ for n, db in enumerate(self._databases.itervalues()):
+ rgb = [0, 0, 0]
+ color = n % 3
+ rgb[color] = 256 - n/3*factor
+ nn = color
+ # XXX: pretty sure this is horrible after so many aliases
+ while rgb[color] < factor:
+ print rgb[color], factor
+ nc = min(256 - rgb[color], 256)
+ rgb[color] += nc
+ nn += 1
+ if nn > 2:
+ nn = 0
+ rgb[nn] = nc
+ db['rgb_color'] = rgb
- for alias, query in self._queries:
- query['alias'] = alias
- query['sql'] = reformat_sql(query['sql'])
- query['rgb_color'] = self._databases[alias]['rgb_color']
- try:
- query['width_ratio'] = (query['duration'] / self._sql_time) * 100
- except ZeroDivisionError:
- query['width_ratio'] = 0
- query['start_offset'] = width_ratio_tally
- query['end_offset'] = query['width_ratio'] + query['start_offset']
- width_ratio_tally += query['width_ratio']
+ for alias, query in self._queries:
+ query['alias'] = alias
+ query['sql'] = reformat_sql(query['sql'])
+ query['rgb_color'] = self._databases[alias]['rgb_color']
+ try:
+ query['width_ratio'] = (query['duration'] / self._sql_time) * 100
+ except ZeroDivisionError:
+ query['width_ratio'] = 0
+ query['start_offset'] = width_ratio_tally
+ query['end_offset'] = query['width_ratio'] + query['start_offset']
+ width_ratio_tally += query['width_ratio']
- stacktrace = []
- for frame in query['stacktrace']:
- params = map(escape, frame[0].rsplit('/', 1) + list(frame[1:]))
- stacktrace.append('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)\n <span class="code">{4}</span>"'.format(*params))
- query['stacktrace'] = mark_safe('\n'.join(stacktrace))
+ stacktrace = []
+ for frame in query['stacktrace']:
+ params = map(escape, frame[0].rsplit('/', 1) + list(frame[1:]))
+ stacktrace.append('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)\n <span class="code">{4}</span>"'.format(*params))
+ query['stacktrace'] = mark_safe('\n'.join(stacktrace))
context = self.context.copy()
context.update({