summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorDusty Phillips <buchuki@gmail.com>2008-10-06 02:48:24 +0200
committerDusty Phillips <buchuki@gmail.com>2008-10-06 03:05:11 +0200
commit06963130c85f8632b898a2d98e7931951c7735a4 (patch)
treeffb9ce9ab23b8198ba9398f0ef482f1cfea6c679 /main
parent4fd05e721e13b62cc02009c797e275f7bb0ea398 (diff)
downloadarchweb-06963130c85f8632b898a2d98e7931951c7735a4.tar.gz
archweb-06963130c85f8632b898a2d98e7931951c7735a4.tar.xz
use an autouser middleware to set the creator of an object
Diffstat (limited to 'main')
-rw-r--r--main/middleware.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/main/middleware.py b/main/middleware.py
index 01734f5..df0a7a4 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
+