/middleware/threadlocals.py

http://ddtcms.googlecode.com/ · Python · 17 lines · 10 code · 2 blank · 5 comment · 2 complexity · 068ad5c9d5016c324fc9b0aedde54619 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. # Description: thread locals middleware
  3. # Create: 2008-6-4
  4. try:
  5. from threading import local
  6. except ImportError:
  7. from django.utils._threading_local import local
  8. _thread_locals = local()
  9. def get_current_user():
  10. return getattr(_thread_locals, 'user', None)
  11. class ThreadLocals(object):
  12. """Middleware that gets various objects from the
  13. request object and saves them in thread local storage."""
  14. def process_request(self, request):
  15. _thread_locals.user = getattr(request, 'user', None)