Mercurial > public > madeira
diff mysite/sqllog.py @ 1:0dcfcdf50c62
Initial import of Madeira project from the private repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2009 03:10:59 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mysite/sqllog.py Mon Apr 06 03:10:59 2009 +0000 @@ -0,0 +1,20 @@ +from django.db import connection +from django.template import Template, Context + +class SQLLogMiddleware: + + def process_response ( self, request, response ): + time = 0.0 + for q in connection.queries: + time += float(q['time']) + t = Template(''' + <p><em>Total query count:</em> {{ count }}<br/> + <em>Total execution time:</em> {{ time }}</p> + <ol class="sqllog"> + {% for sql in sqllog %} + <li>{{ sql.time }}: {{ sql.sql }}</li> + {% endfor %} + </ol> + ''') + response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))) + return response