c52d964921
First off, the copyright notice is from the other middleware previously removed, so all of that can go, along with some stragglers in the import list. Next, as stated on http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser, you need to be sure to have the import in the model class be the same as the import used in the middleware declaration, which was not true. Whoops. Signed-off-by: Dan McGee <dan@archlinux.org>
17 lines
421 B
Python
17 lines
421 B
Python
import threading
|
|
|
|
user_holder = threading.local()
|
|
user_holder.user = None
|
|
|
|
# http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
|
|
class AutoUserMiddleware(object):
|
|
'''Saves the current user so it can be retrieved by the admin'''
|
|
def process_request(self, request):
|
|
user_holder.user = request.user
|
|
|
|
|
|
def get_user():
|
|
'''Get the currently logged in request.user'''
|
|
return user_holder.user
|
|
|