diff options
Diffstat (limited to 'debug_toolbar/utils')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 15 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/db.py | 3 |
2 files changed, 16 insertions, 2 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 01f817a..f7a3de0 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -6,6 +6,8 @@ import sys from django.conf import settings from django.views.debug import linebreak_iter +from django.utils.html import escape +from django.utils.safestring import mark_safe # Figure out some paths django_path = os.path.realpath(os.path.dirname(django.__file__)) @@ -48,6 +50,19 @@ def tidy_stacktrace(stack): return trace +def render_stacktrace(trace): + stacktrace = [] + for frame in trace: + params = map(escape, frame[0].rsplit(os.path.sep, 1) + list(frame[1:])) + try: + stacktrace.append(u'<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)) + except IndexError: + # This frame doesn't have the expected format, so skip it and move on to the next one + continue + return mark_safe('\n'.join(stacktrace)) + + + def get_template_info(source, context_lines=3): line = 0 upto = 0 diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index c0789eb..4d87090 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -91,8 +91,7 @@ class NormalCursorWrapper(object): stop = datetime.now() duration = ms_from_timedelta(stop - start) enable_stacktraces = getattr(settings, - 'DEBUG_TOOLBAR_CONFIG', {}) \ - .get('ENABLE_STACKTRACES', True) + 'DEBUG_TOOLBAR_CONFIG', {}).get('ENABLE_STACKTRACES', True) if enable_stacktraces: stacktrace = tidy_stacktrace(reversed(get_stack())) else: |
