Middelware to remember sql query log from before a redirect

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from django.http import HttpResponseRedirect
from django.core.exceptions import MiddlewareNotUsed

class SqlDebuggingRedirWrapMiddleware(object):
    def __init__(self):
        if not (getattr(settings, 'DEBUG', False)):
            raise django.exceptions.MiddlewareNotUsed()
        
    def process_response(self, request, response):
        if isinstance(response, HttpResponseRedirect):
            request.session['_redir_queries'] = connection.queries
        return response
    
    def process_request(self, request):        
        if '_redir_queries' in request.session:
            connection.queries[0:0] = request.session['_redir_queries']
            del request.session['_redir_queries']

More like this

  1. another request logging middleware with request time and extra info by yoav 1 year, 5 months ago
  2. Log all interaction with user to the DB by inuwashi 2 years, 4 months ago
  3. request_logger by amitu 4 years, 2 months ago
  4. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  5. Remember path decorator by robhudson 3 years, 5 months ago

Comments

(Forgotten your password?)