Ticket #12066: 12066.diff
File 12066.diff, 10.0 KB (added by , 15 years ago) |
---|
-
django/conf/global_settings.py
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 99fc72e..98e90a6 100644
a b TEMPLATE_LOADERS = ( 161 161 # Each one should be a callable that takes the request object as its 162 162 # only parameter and returns a dictionary to add to the context. 163 163 TEMPLATE_CONTEXT_PROCESSORS = ( 164 'django.co re.context_processors.auth',164 'django.contrib.auth.context_processors.auth', 165 165 'django.core.context_processors.debug', 166 166 'django.core.context_processors.i18n', 167 167 'django.core.context_processors.media', -
django/contrib/admin/sites.py
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 5f397ec..31a65e2 100644
a b class AdminSite(object): 151 151 from django.contrib.contenttypes.models import ContentType 152 152 153 153 if not LogEntry._meta.installed: 154 raise ImproperlyConfigured("Put 'django.contrib.admin' in your INSTALLED_APPS setting in order to use the admin application.") 154 raise ImproperlyConfigured("Put 'django.contrib.admin' in your " 155 "INSTALLED_APPS setting in order to use the admin application.") 155 156 if not ContentType._meta.installed: 156 raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in your INSTALLED_APPS setting in order to use the admin application.") 157 if 'django.core.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS: 158 raise ImproperlyConfigured("Put 'django.core.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") 157 raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in " 158 "your INSTALLED_APPS setting in order to use the admin application.") 159 if not ( 160 'django.contrib.auth.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS or 161 'django.core.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS): 162 raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' " 163 "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") 159 164 160 165 def admin_view(self, view, cacheable=False): 161 166 """ -
new file django/contrib/auth/context_processors.py
diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py new file mode 100644 index 0000000..e63e0c5
- + 1 from django.core.context_processors import PermWrapper 2 from django.utils.functional import lazy, memoize, SimpleLazyObject 3 4 def auth(request): 5 """ 6 Returns context variables required by apps that use Django's authentication 7 system. 8 9 If there is no 'user' attribute in the request, uses AnonymousUser (from 10 django.contrib.auth). 11 """ 12 # If we access request.user, request.session is accessed, which results in 13 # 'Vary: Cookie' being sent in every request that uses this context 14 # processor, which can easily be every request on a site if 15 # TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills 16 # the ability to cache. So, we carefully ensure these attributes are lazy. 17 # We don't use django.utils.functional.lazy() for User, because that 18 # requires knowing the class of the object we want to proxy, which could 19 # break with custom auth backends. LazyObject is a less complete but more 20 # flexible solution that is a good enough wrapper for 'User'. 21 def get_user(): 22 if hasattr(request, 'user'): 23 return request.user 24 else: 25 from django.contrib.auth.models import AnonymousUser 26 return AnonymousUser() 27 28 return { 29 'user': SimpleLazyObject(get_user), 30 'messages': lazy(memoize(lambda: get_user().get_and_delete_messages(), {}, 0), list)(), 31 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), 32 } 33 34 -
django/core/context_processors.py
diff --git a/django/core/context_processors.py b/django/core/context_processors.py index 0dbd844..8faf5ac 100644
a b RequestContext. 8 8 """ 9 9 10 10 from django.conf import settings 11 from django.utils.functional import lazy, memoize, SimpleLazyObject12 11 13 12 def auth(request): 14 13 """ 15 Returns context variables required by apps that use Django's authentication16 system.14 DEPRECATED. This context processor is the old location, and has been moved 15 to `django.contrib.auth.context_processors`. 17 16 18 If there is no 'user' attribute in the request, uses AnonymousUser (from19 django.contrib.auth).17 This function still exists for backwards-compatibility; it will be removed 18 in Django 1.4. 20 19 """ 21 # If we access request.user, request.session is accessed, which results in 22 # 'Vary: Cookie' being sent in every request that uses this context 23 # processor, which can easily be every request on a site if 24 # TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills 25 # the ability to cache. So, we carefully ensure these attributes are lazy. 26 # We don't use django.utils.functional.lazy() for User, because that 27 # requires knowing the class of the object we want to proxy, which could 28 # break with custom auth backends. LazyObject is a less complete but more 29 # flexible solution that is a good enough wrapper for 'User'. 30 def get_user(): 31 if hasattr(request, 'user'): 32 return request.user 33 else: 34 from django.contrib.auth.models import AnonymousUser 35 return AnonymousUser() 36 37 return { 38 'user': SimpleLazyObject(get_user), 39 'messages': lazy(memoize(lambda: get_user().get_and_delete_messages(), {}, 0), list)(), 40 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), 41 } 20 import warnings 21 warnings.warn( 22 "The context processor at `django.core.context_processors.auth` is " \ 23 "deprecated; use the path `django.contrib.auth.context_processors.auth` " \ 24 "instead.", 25 PendingDeprecationWarning 26 ) 27 from django.contrib.auth.context_processors import auth as auth_context_processor 28 return auth_context_processor(request) 42 29 43 30 def debug(request): 44 31 "Returns context variables helpful for debugging." -
docs/internals/deprecation.txt
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 7e7f4c6..c77bec8 100644
a b their deprecation, as per the :ref:`Django deprecation policy 13 13 hooking up admin URLs. This has been deprecated since the 1.1 14 14 release. 15 15 16 * 1.4 17 * ``django.core.context_processors.auth``. This release will 18 remove the old method in favor of the new method in 19 ``django.contrib.auth.context_processors.auth``. This has been 20 deprecated since the 1.2 release. 21 16 22 * 2.0 17 23 * ``django.views.defaults.shortcut()``. This function has been moved 18 24 to ``django.contrib.contenttypes.views.shortcut()`` as part of the -
docs/ref/settings.txt
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index e8c673d..7043ef0 100644
a b TEMPLATE_CONTEXT_PROCESSORS 987 987 988 988 Default:: 989 989 990 ("django.co re.context_processors.auth",990 ("django.contrib.auth.context_processors.auth", 991 991 "django.core.context_processors.debug", 992 992 "django.core.context_processors.i18n", 993 993 "django.core.context_processors.media") -
docs/ref/templates/api.txt
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index e3260a9..e92c3b4 100644
a b called **context processors** -- that take a request object as their argument 308 308 and return a dictionary of items to be merged into the context. By default, 309 309 :setting:`TEMPLATE_CONTEXT_PROCESSORS` is set to:: 310 310 311 ("django.co re.context_processors.auth",311 ("django.contrib.auth.context_processors.auth", 312 312 "django.core.context_processors.debug", 313 313 "django.core.context_processors.i18n", 314 314 "django.core.context_processors.media") … … optional, third positional argument, ``processors``. In this example, the 348 348 349 349 Here's what each of the default processors does: 350 350 351 django.co re.context_processors.auth352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 351 django.contrib.auth.context_processors.auth 352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 353 353 354 354 If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every 355 355 ``RequestContext`` will contain these three variables: -
docs/topics/auth.txt
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt index 152246d..44ca2e3 100644
a b The currently logged-in user and his/her permissions are made available in the 1218 1218 Technically, these variables are only made available in the template context 1219 1219 if you use :class:`~django.template.context.RequestContext` *and* your 1220 1220 :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting contains 1221 ``"django.co re.context_processors.auth"``, which is default. For more, see1222 the :ref:`RequestContext docs <subclassing-context-requestcontext>`.1221 ``"django.contrib.auth.context_processors.auth"``, which is default. For 1222 more, see the :ref:`RequestContext docs <subclassing-context-requestcontext>`. 1223 1223 1224 1224 Users 1225 1225 ----- -
tests/regressiontests/context_processors/tests.py
diff --git a/tests/regressiontests/context_processors/tests.py b/tests/regressiontests/context_processors/tests.py index 004f90e..0d19bef 100644
a b class RequestContextProcessorTests(TestCase): 41 41 42 42 class AuthContextProcessorTests(TestCase): 43 43 """ 44 Tests for the ``django.co re.context_processors.auth`` processor44 Tests for the ``django.contrib.auth.context_processors.auth`` processor 45 45 """ 46 46 urls = 'regressiontests.context_processors.urls' 47 47 fixtures = ['context-processors-users.xml']