middleware.py 594 B

1234567891011121314151617
  1. from django.conf import settings
  2. from misago.stopwatch import Stopwatch
  3. class StopwatchMiddleware(object):
  4. def process_request(self, request):
  5. request.stopwatch = Stopwatch()
  6. def process_response(self, request, response):
  7. try:
  8. time = request.stopwatch.time()
  9. if settings.STOPWATCH_LOG:
  10. stat_file = open(settings.STOPWATCH_LOG, 'a')
  11. stat_file.write("%s %s s\n" % (request.path_info, time))
  12. stat_file.close()
  13. except AttributeError:
  14. pass
  15. return response