|
8 | 8 | import django
|
9 | 9 | from django.core.exceptions import ImproperlyConfigured
|
10 | 10 | from django.template import Node
|
11 |
| -from django.utils.html import escape |
| 11 | +from django.template.loader import render_to_string |
12 | 12 | from django.utils.safestring import mark_safe
|
13 | 13 |
|
14 | 14 | from debug_toolbar import settings as dt_settings
|
@@ -59,28 +59,36 @@ def tidy_stacktrace(stack):
|
59 | 59 | if omit_path(os.path.realpath(path)):
|
60 | 60 | continue
|
61 | 61 | text = "".join(text).strip() if text else ""
|
62 |
| - trace.append((path, line_no, func_name, text)) |
| 62 | + frame_locals = ( |
| 63 | + frame.f_locals |
| 64 | + if dt_settings.get_config()["ENABLE_STACKTRACES_LOCALS"] |
| 65 | + else None |
| 66 | + ) |
| 67 | + trace.append((path, line_no, func_name, text, frame_locals)) |
63 | 68 | return trace
|
64 | 69 |
|
65 | 70 |
|
66 | 71 | def render_stacktrace(trace):
|
67 | 72 | stacktrace = []
|
68 | 73 | for frame in trace:
|
69 |
| - params = (escape(v) for v in chain(frame[0].rsplit(os.path.sep, 1), frame[1:])) |
| 74 | + params = (v for v in chain(frame[0].rsplit(os.path.sep, 1), frame[1:])) |
70 | 75 | params_dict = {str(idx): v for idx, v in enumerate(params)}
|
71 | 76 | try:
|
72 |
| - stacktrace.append( |
73 |
| - '<span class="djdt-path">%(0)s/</span>' |
74 |
| - '<span class="djdt-file">%(1)s</span>' |
75 |
| - ' in <span class="djdt-func">%(3)s</span>' |
76 |
| - '(<span class="djdt-lineno">%(2)s</span>)\n' |
77 |
| - ' <span class="djdt-code">%(4)s</span>' % params_dict |
78 |
| - ) |
| 77 | + stacktrace.append(params_dict) |
79 | 78 | except KeyError:
|
80 | 79 | # This frame doesn't have the expected format, so skip it and move
|
81 | 80 | # on to the next one
|
82 | 81 | continue
|
83 |
| - return mark_safe("\n".join(stacktrace)) |
| 82 | + |
| 83 | + return mark_safe( |
| 84 | + render_to_string( |
| 85 | + "debug_toolbar/panels/sql_stacktrace.html", |
| 86 | + { |
| 87 | + "stacktrace": stacktrace, |
| 88 | + "show_locals": dt_settings.get_config()["ENABLE_STACKTRACES_LOCALS"], |
| 89 | + }, |
| 90 | + ) |
| 91 | + ) |
84 | 92 |
|
85 | 93 |
|
86 | 94 | def get_template_info():
|
|
0 commit comments