Mercurial > public > madeira
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:df0370bfe3f0 | 1:0dcfcdf50c62 |
---|---|
1 from django.db import connection | |
2 from django.template import Template, Context | |
3 | |
4 class SQLLogMiddleware: | |
5 | |
6 def process_response ( self, request, response ): | |
7 time = 0.0 | |
8 for q in connection.queries: | |
9 time += float(q['time']) | |
10 t = Template(''' | |
11 <p><em>Total query count:</em> {{ count }}<br/> | |
12 <em>Total execution time:</em> {{ time }}</p> | |
13 <ol class="sqllog"> | |
14 {% for sql in sqllog %} | |
15 <li>{{ sql.time }}: {{ sql.sql }}</li> | |
16 {% endfor %} | |
17 </ol> | |
18 ''') | |
19 response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))) | |
20 return response |