Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 67d4289c2ef56022d14a038a644d020997e2d9c9 1 parent 1559f64
Jannis Leidel authored February 21, 2010
2  django/conf/global_settings.py
@@ -183,7 +183,7 @@
183 183
 # Each one should be a callable that takes the request object as its
184 184
 # only parameter and returns a dictionary to add to the context.
185 185
 TEMPLATE_CONTEXT_PROCESSORS = (
186  
-    'django.core.context_processors.auth',
  186
+    'django.contrib.auth.context_processors.auth',
187 187
     'django.core.context_processors.debug',
188 188
     'django.core.context_processors.i18n',
189 189
     'django.core.context_processors.media',
12  django/contrib/admin/sites.py
@@ -155,11 +155,15 @@ def check_dependencies(self):
155 155
         from django.contrib.contenttypes.models import ContentType
156 156
 
157 157
         if not LogEntry._meta.installed:
158  
-            raise ImproperlyConfigured("Put 'django.contrib.admin' in your INSTALLED_APPS setting in order to use the admin application.")
  158
+            raise ImproperlyConfigured("Put 'django.contrib.admin' in your "
  159
+                "INSTALLED_APPS setting in order to use the admin application.")
159 160
         if not ContentType._meta.installed:
160  
-            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in your INSTALLED_APPS setting in order to use the admin application.")
161  
-        if 'django.core.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
162  
-            raise ImproperlyConfigured("Put 'django.core.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.")
  161
+            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
  162
+                "your INSTALLED_APPS setting in order to use the admin application.")
  163
+        if not ('django.contrib.auth.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS or
  164
+            'django.core.context_processors.auth' in settings.TEMPLATE_CONTEXT_PROCESSORS):
  165
+            raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
  166
+                "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.")
163 167
 
164 168
     def admin_view(self, view, cacheable=False):
165 169
         """
33  django/contrib/auth/context_processors.py
... ...
@@ -0,0 +1,33 @@
  1
+from django.core.context_processors import PermWrapper
  2
+from django.utils.functional import lazy, memoize, SimpleLazyObject
  3
+from django.contrib import messages
  4
+
  5
+def auth(request):
  6
+    """
  7
+    Returns context variables required by apps that use Django's authentication
  8
+    system.
  9
+
  10
+    If there is no 'user' attribute in the request, uses AnonymousUser (from
  11
+    django.contrib.auth).
  12
+    """
  13
+    # If we access request.user, request.session is accessed, which results in
  14
+    # 'Vary: Cookie' being sent in every request that uses this context
  15
+    # processor, which can easily be every request on a site if
  16
+    # TEMPLATE_CONTEXT_PROCESSORS has this context processor added.  This kills
  17
+    # the ability to cache.  So, we carefully ensure these attributes are lazy.
  18
+    # We don't use django.utils.functional.lazy() for User, because that
  19
+    # requires knowing the class of the object we want to proxy, which could
  20
+    # break with custom auth backends.  LazyObject is a less complete but more
  21
+    # flexible solution that is a good enough wrapper for 'User'.
  22
+    def get_user():
  23
+        if hasattr(request, 'user'):
  24
+            return request.user
  25
+        else:
  26
+            from django.contrib.auth.models import AnonymousUser
  27
+            return AnonymousUser()
  28
+
  29
+    return {
  30
+        'user': SimpleLazyObject(get_user),
  31
+        'messages': messages.get_messages(request),
  32
+        'perms':  lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
  33
+    }
41  django/core/context_processors.py
@@ -9,38 +9,25 @@
9 9
 
10 10
 from django.conf import settings
11 11
 from django.middleware.csrf import get_token
12  
-from django.utils.functional import lazy, memoize, SimpleLazyObject
13  
-from django.contrib import messages
  12
+from django.utils.functional import lazy
14 13
 
15 14
 def auth(request):
16 15
     """
17  
-    Returns context variables required by apps that use Django's authentication
18  
-    system.
  16
+    DEPRECATED. This context processor is the old location, and has been moved
  17
+    to `django.contrib.auth.context_processors`.
19 18
 
20  
-    If there is no 'user' attribute in the request, uses AnonymousUser (from
21  
-    django.contrib.auth).
  19
+    This function still exists for backwards-compatibility; it will be removed
  20
+    in Django 1.4.
22 21
     """
23  
-    # If we access request.user, request.session is accessed, which results in
24  
-    # 'Vary: Cookie' being sent in every request that uses this context
25  
-    # processor, which can easily be every request on a site if
26  
-    # TEMPLATE_CONTEXT_PROCESSORS has this context processor added.  This kills
27  
-    # the ability to cache.  So, we carefully ensure these attributes are lazy.
28  
-    # We don't use django.utils.functional.lazy() for User, because that
29  
-    # requires knowing the class of the object we want to proxy, which could
30  
-    # break with custom auth backends.  LazyObject is a less complete but more
31  
-    # flexible solution that is a good enough wrapper for 'User'.
32  
-    def get_user():
33  
-        if hasattr(request, 'user'):
34  
-            return request.user
35  
-        else:
36  
-            from django.contrib.auth.models import AnonymousUser
37  
-            return AnonymousUser()
38  
-
39  
-    return {
40  
-        'user': SimpleLazyObject(get_user),
41  
-        'messages': messages.get_messages(request),
42  
-        'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
43  
-    }
  22
+    import warnings
  23
+    warnings.warn(
  24
+        "The context processor at `django.core.context_processors.auth` is " \
  25
+        "deprecated; use the path `django.contrib.auth.context_processors.auth` " \
  26
+        "instead.",
  27
+        PendingDeprecationWarning
  28
+    )
  29
+    from django.contrib.auth.context_processors import auth as auth_context_processor
  30
+    return auth_context_processor(request)
44 31
 
45 32
 def csrf(request):
46 33
     """
5  docs/internals/deprecation.txt
@@ -86,6 +86,11 @@ their deprecation, as per the :ref:`Django deprecation policy
86 86
           ``django.contrib.syndication`` have been deprecated since the 1.2
87 87
           release. The class-based view ``views.Feed`` should be used instead.
88 88
 
  89
+        * ``django.core.context_processors.auth``.  This release will
  90
+          remove the old method in favor of the new method in
  91
+          ``django.contrib.auth.context_processors.auth``.  This has been
  92
+          deprecated since the 1.2 release.
  93
+
89 94
     * 2.0
90 95
         * ``django.views.defaults.shortcut()``. This function has been moved
91 96
           to ``django.contrib.contenttypes.views.shortcut()`` as part of the
2  docs/ref/settings.txt
@@ -1367,7 +1367,7 @@ TEMPLATE_CONTEXT_PROCESSORS
1367 1367
 
1368 1368
 Default::
1369 1369
 
1370  
-    ("django.core.context_processors.auth",
  1370
+    ("django.contrib.auth.context_processors.auth",
1371 1371
     "django.core.context_processors.debug",
1372 1372
     "django.core.context_processors.i18n",
1373 1373
     "django.core.context_processors.media",
6  docs/ref/templates/api.txt
@@ -308,7 +308,7 @@ 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.core.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",
@@ -360,8 +360,8 @@ optional, third positional argument, ``processors``. In this example, the
360 360
 
361 361
 Here's what each of the default processors does:
362 362
 
363  
-django.core.context_processors.auth
364  
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363
+django.contrib.auth.context_processors.auth
  364
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365 365
 
366 366
 If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
367 367
 ``RequestContext`` will contain these three variables:
4  docs/topics/auth.txt
@@ -1236,8 +1236,8 @@ The currently logged-in user and his/her permissions are made available in the
1236 1236
    Technically, these variables are only made available in the template context
1237 1237
    if you use :class:`~django.template.context.RequestContext` *and* your
1238 1238
    :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting contains
1239  
-   ``"django.core.context_processors.auth"``, which is default. For more, see
1240  
-   the :ref:`RequestContext docs <subclassing-context-requestcontext>`.
  1239
+   ``"django.contrib.auth.context_processors.auth"``, which is default. For
  1240
+   more, see the :ref:`RequestContext docs <subclassing-context-requestcontext>`.
1241 1241
 
1242 1242
 Users
1243 1243
 -----
2  tests/regressiontests/context_processors/tests.py
@@ -41,7 +41,7 @@ def test_request_attributes(self):
41 41
 
42 42
 class AuthContextProcessorTests(TestCase):
43 43
     """
44  
-    Tests for the ``django.core.context_processors.auth`` processor
  44
+    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']

0 notes on commit 67d4289

Please sign in to comment.
Something went wrong with that request. Please try again.