Ticket #15299: 15299.2.diff

File 15299.2.diff, 4.7 KB (added by v1v3kn, 14 years ago)

Changed to std DeprecationWarning, updated deprecation policy

  • docs/topics/auth.txt

     
    13341334
    13351335The currently logged-in user's permissions are stored in the template variable
    13361336``{{ perms }}``. This is an instance of
    1337 :class:`django.core.context_processors.PermWrapper`, which is a
     1337:class:`django.contrib.auth.context_processors.PermWrapper`, which is a
    13381338template-friendly proxy of permissions.
    13391339
    13401340In the ``{{ perms }}`` object, single-attribute lookup is a proxy to
  • docs/ref/templates/api.txt

     
    423423      via the :doc:`messages framework </ref/contrib/messages>`.
    424424
    425425    * ``perms`` -- An instance of
    426       ``django.core.context_processors.PermWrapper``, representing the
     426      ``django.contrib.auth.context_processors.PermWrapper``, representing the
    427427      permissions that the currently logged-in user has.
    428428
     429.. versionchanged:: 1.3
     430    ``perms`` was moved in this release from
     431    ``django.core.context_processors.auth`` to its current location.
     432
    429433.. versionchanged:: 1.2
    430434    This context processor was moved in this release from
    431435    ``django.core.context_processors.auth`` to its current location.
  • django/core/context_processors.py

     
    8686# PermWrapper and PermLookupDict proxy the permissions system into objects that
    8787# the template system can understand.
    8888
     89# Deprecation Warning: PermWrapper would be accessible from django.contrib.auth.context_processors from version 1.3
     90# and it would be removed from django.core.context_processors in future versions.
     91
    8992class PermLookupDict(object):
    9093    def __init__(self, user, module_name):
    9194        self.user, self.module_name = user, module_name
     
    99102    def __nonzero__(self):
    100103        return self.user.has_module_perms(self.module_name)
    101104
     105
    102106class PermWrapper(object):
    103107    def __init__(self, user):
     108        import warnings
     109        warnings.warn(
     110            'PermWrapper would be accessible from django.contrib.auth.context_processors
     111            from version 1.3 and it would be removed from django.core.context_processors in future versions.',
     112            DeprecationWarning
     113        )
    104114        self.user = user
    105115
    106116    def __getitem__(self, module_name):
  • django/contrib/auth/context_processors.py

     
    1 from django.core.context_processors import PermWrapper
    21from django.utils.functional import lazy, memoize, SimpleLazyObject
    32from django.contrib import messages
    43
     4# PermWrapper and PermLookupDict proxy the permissions system into objects that
     5# the template system can understand.
     6
     7class PermLookupDict(object):
     8    def __init__(self, user, module_name):
     9        self.user, self.module_name = user, module_name
     10
     11    def __repr__(self):
     12        return str(self.user.get_all_permissions())
     13
     14    def __getitem__(self, perm_name):
     15        return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
     16
     17    def __nonzero__(self):
     18        return self.user.has_module_perms(self.module_name)
     19
     20
     21class PermWrapper(object):
     22    def __init__(self, user):
     23        self.user = user
     24
     25    def __getitem__(self, module_name):
     26        return PermLookupDict(self.user, module_name)
     27
     28    def __iter__(self):
     29        # I am large, I contain multitudes.
     30        raise TypeError("PermWrapper is not iterable.")
     31
    532def auth(request):
    633    """
    734    Returns context variables required by apps that use Django's authentication
  • docs/internals/deprecation.txt

     
    1818        * The :mod:`django.contrib.gis.db.backend` module, including the
    1919          ``SpatialBackend`` interface, is deprecated since the 1.2 release.
    2020
     21        * In this release :class:`django.core.context_processors.PermWrapper` will be
     22          moved to :class:`django.contrib.auth.context_processors.PermWrapper`. The
     23          former location is deprecated from 1.3 and would be removed in future releases.
     24
    2125    * 1.4
    2226        * ``CsrfResponseMiddleware``.  This has been deprecated since the 1.2
    2327          release, in favour of the template tag method for inserting the CSRF
Back to Top