PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/middleware/threadlocals.py

http://ddtcms.googlecode.com/
Python | 17 lines | 10 code | 2 blank | 5 comment | 0 complexity | 068ad5c9d5016c324fc9b0aedde54619 MD5 | raw file
 1# -*- coding: utf-8 -*-

 2# Description: thread locals middleware

 3# Create: 2008-6-4

 4try:
 5    from threading import local
 6except ImportError:
 7    from django.utils._threading_local import local
 8
 9_thread_locals = local()
10def get_current_user():
11    return getattr(_thread_locals, 'user', None)
12
13class ThreadLocals(object):
14    """Middleware that gets various objects from the

15    request object and saves them in thread local storage."""
16    def process_request(self, request):
17        _thread_locals.user = getattr(request, 'user', None)