Mercurial > public > madeira
annotate mysite/sqllog.py @ 22:ccb0f675427e django1.3
Making a branch to upgrade the code to Django 1.3.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 28 Mar 2011 01:59:09 +0000 |
parents | 0dcfcdf50c62 |
children |
rev | line source |
---|---|
bgneal@1 | 1 from django.db import connection |
bgneal@1 | 2 from django.template import Template, Context |
bgneal@1 | 3 |
bgneal@1 | 4 class SQLLogMiddleware: |
bgneal@1 | 5 |
bgneal@1 | 6 def process_response ( self, request, response ): |
bgneal@1 | 7 time = 0.0 |
bgneal@1 | 8 for q in connection.queries: |
bgneal@1 | 9 time += float(q['time']) |
bgneal@1 | 10 t = Template(''' |
bgneal@1 | 11 <p><em>Total query count:</em> {{ count }}<br/> |
bgneal@1 | 12 <em>Total execution time:</em> {{ time }}</p> |
bgneal@1 | 13 <ol class="sqllog"> |
bgneal@1 | 14 {% for sql in sqllog %} |
bgneal@1 | 15 <li>{{ sql.time }}: {{ sql.sql }}</li> |
bgneal@1 | 16 {% endfor %} |
bgneal@1 | 17 </ol> |
bgneal@1 | 18 ''') |
bgneal@1 | 19 response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))) |
bgneal@1 | 20 return response |