Skip to content

Add SQL_TOKEN_GROUPING setting to control token grouping in SQL panel #1404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Config setting to enable token grouping in SQL panel
  • Loading branch information
alkihis committed Nov 20, 2020
commit a2c8acafabc97c2b4e28bbfa180d3d91e2cbee9c
5 changes: 4 additions & 1 deletion debug_toolbar/panels/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.utils.html import escape
from sqlparse import tokens as T

from debug_toolbar import settings as dt_settings


class BoldKeywordFilter:
"""sqlparse filter to bold SQL keywords"""
Expand Down Expand Up @@ -31,7 +33,8 @@ def reformat_sql(sql, with_toggle=False):

def parse_sql(sql, aligned_indent=False):
stack = sqlparse.engine.FilterStack()
stack.enable_grouping()
if dt_settings.get_config()["SQL_STACK_GROUPING"]:
stack.enable_grouping()
if aligned_indent:
stack.stmtprocess.append(
sqlparse.filters.AlignedIndentFilter(char="&nbsp;", n="<br/>")
Expand Down
1 change: 1 addition & 0 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"SHOW_TEMPLATE_CONTEXT": True,
"SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
"SQL_WARNING_THRESHOLD": 500, # milliseconds
"SQL_STACK_GROUPING": True,
}


Expand Down