magic-removal: added middleware for adding request.user
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2423 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9cdd49c1e0
commit
50f1717525
|
@ -0,0 +1,13 @@
|
|||
class RequestUserMiddleware:
|
||||
def process_request(self, request):
|
||||
from django.contrib.auth.models import User, SESSION_KEY
|
||||
try:
|
||||
user_id = request.session[SESSION_KEY]
|
||||
if not user_id:
|
||||
raise ValueError
|
||||
user = User.objects.get(pk=user_id)
|
||||
except (AttributeError, KeyError, ValueError, User.DoesNotExist):
|
||||
from django.parts.auth import anonymoususers
|
||||
user = anonymoususers.AnonymousUser()
|
||||
request.user = user
|
||||
return None
|
Loading…
Reference in New Issue