diff options
| author | Jannis Leidel | 2013-04-24 02:51:17 -0700 |
|---|---|---|
| committer | Jannis Leidel | 2013-04-24 02:51:17 -0700 |
| commit | 1390c405f6718dc44169503176f610f194fe6d41 (patch) | |
| tree | 70466742c10a71b0164972112bf528a527ada90f /debug_toolbar/utils | |
| parent | 49c09c0b9afb588fa3cde047075331ea81d18a55 (diff) | |
| parent | f6b515f71aea595c303d287f121a34ec31c4784c (diff) | |
| download | django-debug-toolbar-1390c405f6718dc44169503176f610f194fe6d41.tar.bz2 | |
Merge pull request #347 from midiotthimble/sql-panel-refactor
Request Line is too large (400) sometimes
Diffstat (limited to 'debug_toolbar/utils')
| -rw-r--r-- | debug_toolbar/utils/functional.py | 14 | ||||
| -rw-r--r-- | debug_toolbar/utils/sql.py | 15 | ||||
| -rw-r--r-- | debug_toolbar/utils/sqlparse/filters.py | 14 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/db.py | 3 |
4 files changed, 43 insertions, 3 deletions
diff --git a/debug_toolbar/utils/functional.py b/debug_toolbar/utils/functional.py new file mode 100644 index 0000000..1dbb734 --- /dev/null +++ b/debug_toolbar/utils/functional.py @@ -0,0 +1,14 @@ +try: + from django.utils.functional import cached_property +except ImportError: # Django < 1.4 + class cached_property(object): + """ + Decorator that creates converts a method with a single + self argument into a property cached on the instance. + """ + def __init__(self, func): + self.func = func + + def __get__(self, instance, type): + res = instance.__dict__[self.func.__name__] = self.func(instance) + return res diff --git a/debug_toolbar/utils/sql.py b/debug_toolbar/utils/sql.py new file mode 100644 index 0000000..909edf7 --- /dev/null +++ b/debug_toolbar/utils/sql.py @@ -0,0 +1,15 @@ +import re +from debug_toolbar.utils import sqlparse +from debug_toolbar.utils.sqlparse.filters import BoldKeywordFilter + + +def reformat_sql(sql): + stack = sqlparse.engine.FilterStack() + stack.preprocess.append(BoldKeywordFilter()) # add our custom filter + stack.postprocess.append(sqlparse.filters.SerializerUnicode()) # tokens -> strings + return swap_fields(''.join(stack.run(sql))) + + +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) diff --git a/debug_toolbar/utils/sqlparse/filters.py b/debug_toolbar/utils/sqlparse/filters.py index 897cc90..6443a3c 100644 --- a/debug_toolbar/utils/sqlparse/filters.py +++ b/debug_toolbar/utils/sqlparse/filters.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import re +from django.utils.html import escape from debug_toolbar.utils.sqlparse import tokens as T from debug_toolbar.utils.sqlparse import sql @@ -423,3 +424,16 @@ class OutputPHPFilter(Filter): varname = self.varname stmt.tokens = tuple(self._process(stmt.tokens, varname)) return stmt + + +class BoldKeywordFilter(Filter): + """sqlparse filter to bold SQL keywords""" + def process(self, stack, stream): + """Process the token stream""" + for token_type, value in stream: + is_keyword = token_type in T.Keyword + if is_keyword: + yield T.Text, '<strong>' + yield token_type, escape(value) + if is_keyword: + yield T.Text, '</strong>' diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index 0ff3359..8a51c36 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -154,9 +154,6 @@ class NormalCursorWrapper(object): 'duration': duration, 'raw_sql': sql, 'params': _params, - 'hash': sha1(settings.SECRET_KEY \ - + smart_str(sql) \ - + _params).hexdigest(), 'stacktrace': stacktrace, 'start_time': start, 'stop_time': stop, |
