Author: mtredinnick
Date: 2007-09-16 06:27:40 -0500 (Sun, 16 Sep 2007)
New Revision: 6356

Modified:
   django/trunk/django/core/context_processors.py
Log:
Fixed #4049 -- Improved error handling in auth() context processor. Based on a 
patch from gregorth.


Modified: django/trunk/django/core/context_processors.py
===================================================================
--- django/trunk/django/core/context_processors.py      2007-09-16 10:49:27 UTC 
(rev 6355)
+++ django/trunk/django/core/context_processors.py      2007-09-16 11:27:40 UTC 
(rev 6356)
@@ -13,11 +13,19 @@
     """
     Returns context variables required by apps that use Django's authentication
     system.
+
+    If there is no 'user' attribute in the request, uses AnonymousUser (from
+    django.contrib.auth).
     """
+    if hasattr(request, 'user'):
+        user = request.user
+    else:
+        from django.contrib.auth.models import AnonymousUser
+        user = AnonymousUser()
     return {
-        'user': request.user,
-        'messages': request.user.get_and_delete_messages(),
-        'perms': PermWrapper(request.user),
+        'user': user,
+        'messages': user.get_and_delete_messages(),
+        'perms': PermWrapper(user),
     }
 
 def debug(request):


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to