From 50f1717525cfa3690e1cdf15869608f7a2bf2884 Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Mon, 27 Feb 2006 23:03:35 +0000 Subject: [PATCH] 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 --- django/contrib/auth/middleware.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 django/contrib/auth/middleware.py diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py new file mode 100644 index 0000000000..f7106eb9be --- /dev/null +++ b/django/contrib/auth/middleware.py @@ -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