Fixed #4049 -- Improved error handling in auth() context processor. Based on a patch from gregorth.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6356 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-09-16 11:27:40 +00:00
parent e988aa3989
commit c694587ebb
1 changed files with 11 additions and 3 deletions

View File

@ -13,11 +13,19 @@ def auth(request):
"""
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):