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 | |
parent | 4fd05e721e13b62cc02009c797e275f7bb0ea398 (diff) |
use an autouser middleware to set the creator of an object
-rw-r--r-- | main/middleware.py | 15 | ||||
-rw-r--r-- | settings.py | 1 |
2 files changed, 16 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 + diff --git a/settings.py b/settings.py index 515d63bd..5f9d082b 100644 --- a/settings.py +++ b/settings.py @@ -61,6 +61,7 @@ MIDDLEWARE_CLASSES += ( "django.middleware.common.CommonMiddleware", "django.middleware.doc.XViewMiddleware", "archweb_dev.main.middleware.RequireLoginMiddleware", + "archweb_dev.main.middleware.AutoUserMiddleware", ) ROOT_URLCONF = 'archweb_dev.urls' |