diff options
author | Dusty Phillips <buchuki@gmail.com> | 2008-10-05 20:48:24 -0400 |
---|---|---|
committer | Dusty Phillips <buchuki@gmail.com> | 2008-10-05 21:05:11 -0400 |
commit | 06963130c85f8632b898a2d98e7931951c7735a4 (patch) | |
tree | ffb9ce9ab23b8198ba9398f0ef482f1cfea6c679 /main | |
parent | 4fd05e721e13b62cc02009c797e275f7bb0ea398 (diff) |
use an autouser middleware to set the creator of an object
Diffstat (limited to 'main')
-rw-r--r-- | main/middleware.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/main/middleware.py b/main/middleware.py index 01734f5e..df0a7a4b 100644 --- a/main/middleware.py +++ b/main/middleware.py @@ -31,6 +31,7 @@ from django.conf import settings from django.contrib.auth.views import login from django.http import HttpResponseRedirect import re +import threading class RequireLoginMiddleware(object): """ @@ -50,3 +51,17 @@ class RequireLoginMiddleware(object): else: return HttpResponseRedirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) + +user_holder = threading.local() +user_holder.user = None + +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 + |