~dylanmccall/harvest/gsoc-client-stuff

« back to all changes in this revision

Viewing changes to harvest/common/middleware/timer.py

  • Committer: Dylan McCall
  • Date: 2010-07-04 20:31:12 UTC
  • Revision ID: dylanmccall@gmail.com-20100704203112-njszrm9j4gn0grq0
Added timer middleware, which adds a request header saying how long a page took to generate.

Added a little hack in harvest.js to display that header after loading new results with XHR.

Made some more text translatable in harvest/templates/base.html.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from time import time
 
2
 
 
3
class TimerMiddleware(object):
 
4
    def process_request(self, request):
 
5
        request._tm_start_time = time()
 
6
    
 
7
    def process_response(self, request, response):
 
8
        if not hasattr(request, "_tm_start_time"):
 
9
            return
 
10
        
 
11
        total_time = time() - request._tm_start_time
 
12
        
 
13
        response['X-Django-Request-Time'] = '%fs' % total_time
 
14
        
 
15
        return response