diff options
| author | Rob Hudson | 2009-08-28 09:22:28 -0700 | 
|---|---|---|
| committer | Rob Hudson | 2009-08-28 09:22:28 -0700 | 
| commit | 2c909f7d32128c29ff03da7713c3c7edfd91d785 (patch) | |
| tree | 1df4133c13e366b68df89ff03c20e82268048a14 | |
| parent | f97ff555a4d8f22dae83bcfd0c2dcf6e846962c9 (diff) | |
| download | django-debug-toolbar-2c909f7d32128c29ff03da7713c3c7edfd91d785.tar.bz2 | |
Refactored `reformat_sql` to produce a more compact output for a tighter view of the SQL.
| -rw-r--r-- | debug_toolbar/panels/sql.py | 31 | 
1 files changed, 14 insertions, 17 deletions
| diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 62c0e58..a53a8d4 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -20,6 +20,17 @@ socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__))  # get a copy of the toolbar object with access to its config dictionary  SQL_WARNING_THRESHOLD = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SQL_WARNING_THRESHOLD', 500) +SQL_KEYWORDS = ( +    'SELECT', +    'FROM', +    'WHERE', +    'INNER JOIN', +    'LEFT OUTER JOIN', +    'ORDER BY', +    'HAVING', +    'GROUP BY', +) +  def tidy_stacktrace(strace):      """      Clean up stacktrace and remove all entries that: @@ -125,21 +136,7 @@ def ms_from_timedelta(td):      return (td.seconds * 1000) + (td.microseconds / 1000.0)  def reformat_sql(sql): -    sql = sql.replace(',', ', ') -    sql = sql.replace('SELECT ', 'SELECT\n\t') -    sql = sql.replace(' FROM ', '\nFROM\n\t') -    sql = sql.replace(' WHERE ', '\nWHERE\n\t') -    sql = sql.replace(' INNER JOIN', '\n\tINNER JOIN') -    sql = sql.replace(' LEFT OUTER JOIN' , '\n\tLEFT OUTER JOIN') -    sql = sql.replace(' ORDER BY ', '\nORDER BY\n\t') -    sql = sql.replace(' HAVING ', '\nHAVING\n\t') -    sql = sql.replace(' GROUP BY ', '\nGROUP BY\n\t') -    # Use Pygments to highlight SQL if it's available -    try: -        from pygments import highlight -        from pygments.lexers import SqlLexer -        from pygments.formatters import HtmlFormatter -        sql = highlight(sql, SqlLexer(), HtmlFormatter()) -    except ImportError: -        pass +    for kwd in SQL_KEYWORDS: +        sql = sql.replace(kwd, '<strong>%s</strong>' % (kwd,))      return sql + | 
