Ticket #12066: 12066.diff

File 12066.diff, 10.0 KB (added by Rob Hudson, 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 = (  
    161161# Each one should be a callable that takes the request object as its
    162162# only parameter and returns a dictionary to add to the context.
    163163TEMPLATE_CONTEXT_PROCESSORS = (
    164     'django.core.context_processors.auth',
     164    'django.contrib.auth.context_processors.auth',
    165165    'django.core.context_processors.debug',
    166166    'django.core.context_processors.i18n',
    167167    '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):  
    151151        from django.contrib.contenttypes.models import ContentType
    152152
    153153        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.")
    155156        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.")
    159164
    160165    def admin_view(self, view, cacheable=False):
    161166        """
  • 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
    - +  
     1from django.core.context_processors import PermWrapper
     2from django.utils.functional import lazy, memoize, SimpleLazyObject
     3
     4def 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.  
    88"""
    99
    1010from django.conf import settings
    11 from django.utils.functional import lazy, memoize, SimpleLazyObject
    1211
    1312def auth(request):
    1413    """
    15     Returns context variables required by apps that use Django's authentication
    16     system.
     14    DEPRECATED. This context processor is the old location, and has been moved
     15    to `django.contrib.auth.context_processors`.
    1716
    18     If there is no 'user' attribute in the request, uses AnonymousUser (from
    19     django.contrib.auth).
     17    This function still exists for backwards-compatibility; it will be removed
     18    in Django 1.4.
    2019    """
    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)
    4229
    4330def debug(request):
    4431    "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  
    1313          hooking up admin URLs.  This has been deprecated since the 1.1
    1414          release.
    1515
     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
    1622    * 2.0
    1723        * ``django.views.defaults.shortcut()``. This function has been moved
    1824          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  
    987987
    988988Default::
    989989
    990     ("django.core.context_processors.auth",
     990    ("django.contrib.auth.context_processors.auth",
    991991    "django.core.context_processors.debug",
    992992    "django.core.context_processors.i18n",
    993993    "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  
    308308and return a dictionary of items to be merged into the context. By default,
    309309:setting:`TEMPLATE_CONTEXT_PROCESSORS` is set to::
    310310
    311     ("django.core.context_processors.auth",
     311    ("django.contrib.auth.context_processors.auth",
    312312    "django.core.context_processors.debug",
    313313    "django.core.context_processors.i18n",
    314314    "django.core.context_processors.media")
    optional, third positional argument, ``processors``. In this example, the  
    348348
    349349Here's what each of the default processors does:
    350350
    351 django.core.context_processors.auth
    352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     351django.contrib.auth.context_processors.auth
     352~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    353353
    354354If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
    355355``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  
    12181218   Technically, these variables are only made available in the template context
    12191219   if you use :class:`~django.template.context.RequestContext` *and* your
    12201220   :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting contains
    1221    ``"django.core.context_processors.auth"``, which is default. For more, see
    1222    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>`.
    12231223
    12241224Users
    12251225-----
  • 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):  
    4141
    4242class AuthContextProcessorTests(TestCase):
    4343    """
    44     Tests for the ``django.core.context_processors.auth`` processor
     44    Tests for the ``django.contrib.auth.context_processors.auth`` processor
    4545    """
    4646    urls = 'regressiontests.context_processors.urls'
    4747    fixtures = ['context-processors-users.xml']
Back to Top