#NEWLINE# def debug_sql_queries_response_processor( verbose = False , file = sys . stderr ) : #NEWLINE# #INDENT# '\n    Attaches a handler which prints the query count (and optionally all\n    individual queries which have been executed) on the console. Does nothing\n    if ``DEBUG = False``.\n\n    Example::\n\n        from feincms.module.page import models, processors\n        models.Page.register_response_processor(\n            processors.debug_sql_queries_response_processor(verbose=True),\n            )\n    ' #NEWLINE# if ( not django_settings . DEBUG ) : #NEWLINE# #INDENT# return ( lambda page , request , response : None ) #NEWLINE# #UNINDENT# def processor( page , request , response ) : #NEWLINE# #INDENT# from django.db import connection #NEWLINE# try : #NEWLINE# #INDENT# import sqlparse #NEWLINE# def print_sql( x ) : #NEWLINE# #INDENT# return sqlparse . format ( x , reindent = True , keyword_case = 'upper' ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# def print_sql( x ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# #UNINDENT# if verbose : #NEWLINE# #INDENT# print ( ( '-' * 60 ) , file = file ) #NEWLINE# #UNINDENT# time = 0.0 #NEWLINE# i = 0 #NEWLINE# for q in connection . queries : #NEWLINE# #INDENT# i += 1 #NEWLINE# if verbose : #NEWLINE# #INDENT# print ( ( '%d : [%s]\n%s\n' % ( i , q [ 'time' ] , print_sql ( q [ 'sql' ] ) ) ) , file = file ) #NEWLINE# #UNINDENT# time += float ( q [ 'time' ] ) #NEWLINE# #UNINDENT# print ( ( '-' * 60 ) , file = file ) #NEWLINE# print ( ( 'Total: %d queries, %.3f ms' % ( i , time ) ) , file = file ) #NEWLINE# print ( ( '-' * 60 ) , file = file ) #NEWLINE# #UNINDENT# return processor