mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #12066 - Moved auth context processor from core to the auth app. Thanks, Rob Hudson.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12466 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -9,38 +9,25 @@ RequestContext.
|
||||
|
||||
from django.conf import settings
|
||||
from django.middleware.csrf import get_token
|
||||
from django.utils.functional import lazy, memoize, SimpleLazyObject
|
||||
from django.contrib import messages
|
||||
from django.utils.functional import lazy
|
||||
|
||||
def auth(request):
|
||||
"""
|
||||
Returns context variables required by apps that use Django's authentication
|
||||
system.
|
||||
DEPRECATED. This context processor is the old location, and has been moved
|
||||
to `django.contrib.auth.context_processors`.
|
||||
|
||||
If there is no 'user' attribute in the request, uses AnonymousUser (from
|
||||
django.contrib.auth).
|
||||
This function still exists for backwards-compatibility; it will be removed
|
||||
in Django 1.4.
|
||||
"""
|
||||
# If we access request.user, request.session is accessed, which results in
|
||||
# 'Vary: Cookie' being sent in every request that uses this context
|
||||
# processor, which can easily be every request on a site if
|
||||
# TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills
|
||||
# the ability to cache. So, we carefully ensure these attributes are lazy.
|
||||
# We don't use django.utils.functional.lazy() for User, because that
|
||||
# requires knowing the class of the object we want to proxy, which could
|
||||
# break with custom auth backends. LazyObject is a less complete but more
|
||||
# flexible solution that is a good enough wrapper for 'User'.
|
||||
def get_user():
|
||||
if hasattr(request, 'user'):
|
||||
return request.user
|
||||
else:
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
return AnonymousUser()
|
||||
|
||||
return {
|
||||
'user': SimpleLazyObject(get_user),
|
||||
'messages': messages.get_messages(request),
|
||||
'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
|
||||
}
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"The context processor at `django.core.context_processors.auth` is " \
|
||||
"deprecated; use the path `django.contrib.auth.context_processors.auth` " \
|
||||
"instead.",
|
||||
PendingDeprecationWarning
|
||||
)
|
||||
from django.contrib.auth.context_processors import auth as auth_context_processor
|
||||
return auth_context_processor(request)
|
||||
|
||||
def csrf(request):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user