summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/middleware.py15
-rw-r--r--settings.py1
2 files changed, 16 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
+
diff --git a/settings.py b/settings.py
index 515d63b..5f9d082 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'