Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15299 -- Started the process of migrating the auth context pro…

…cessor support classes into the auth context processor module. Thanks to shailesh for the report, and v1v3kn for the draft patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15635 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7aa84917a4ae8ca380fea1ae1937706d367389ed 1 parent 6ce03dd
Russell Keith-Magee authored
29  django/contrib/auth/context_processors.py
... ...
@@ -1,7 +1,34 @@
1  
-from django.core.context_processors import PermWrapper
2 1
 from django.utils.functional import lazy, memoize, SimpleLazyObject
3 2
 from django.contrib import messages
4 3
 
  4
+# PermWrapper and PermLookupDict proxy the permissions system into objects that
  5
+# the template system can understand.
  6
+
  7
+class 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
+
  21
+class 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
+
5 32
 def auth(request):
6 33
     """
7 34
     Returns context variables required by apps that use Django's authentication
52  django/core/context_processors.py
@@ -84,28 +84,30 @@ def request(request):
84 84
     return {'request': request}
85 85
 
86 86
 # PermWrapper and PermLookupDict proxy the permissions system into objects that
87  
-# the template system can understand.
88  
-
89  
-class PermLookupDict(object):
90  
-    def __init__(self, user, module_name):
91  
-        self.user, self.module_name = user, module_name
92  
-
93  
-    def __repr__(self):
94  
-        return str(self.user.get_all_permissions())
95  
-
96  
-    def __getitem__(self, perm_name):
97  
-        return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
98  
-
99  
-    def __nonzero__(self):
100  
-        return self.user.has_module_perms(self.module_name)
101  
-
102  
-class PermWrapper(object):
103  
-    def __init__(self, user):
104  
-        self.user = user
105  
-
106  
-    def __getitem__(self, module_name):
107  
-        return PermLookupDict(self.user, module_name)
108  
-
109  
-    def __iter__(self):
110  
-        # I am large, I contain multitudes.
111  
-        raise TypeError("PermWrapper is not iterable.")
  87
+# the template system can understand. They once lived here -- they have
  88
+# been moved to django.contrib.auth.context_processors.
  89
+
  90
+from django.contrib.auth.context_processors import PermLookupDict as RealPermLookupDict
  91
+from django.contrib.auth.context_processors import PermWrapper as RealPermWrapper
  92
+
  93
+class PermLookupDict(RealPermLookupDict):
  94
+    def __init__(self, *args, **kwargs):
  95
+        import warnings
  96
+        warnings.warn(
  97
+            "`django.core.context_processors.PermLookupDict` is " \
  98
+            "deprecated; use `django.contrib.auth.context_processors.PermLookupDict` " \
  99
+            "instead.",
  100
+            PendingDeprecationWarning
  101
+        )
  102
+        super(PermLookupDict, self).__init__(*args, **kwargs)
  103
+
  104
+class PermWrapper(RealPermWrapper):
  105
+    def __init__(self, *args, **kwargs):
  106
+        import warnings
  107
+        warnings.warn(
  108
+            "`django.core.context_processors.PermWrapper` is " \
  109
+            "deprecated; use `django.contrib.auth.context_processors.PermWrapper` " \
  110
+            "instead.",
  111
+            PendingDeprecationWarning
  112
+        )
  113
+        super(PermWrapper, self).__init__(*args, **kwargs)
10  docs/internals/deprecation.txt
@@ -151,13 +151,19 @@ their deprecation, as per the :ref:`Django deprecation policy
151 151
           The ``supports_inactive_user`` variable is not checked any
152 152
           longer and can be removed.
153 153
 
154  
-        * :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` will raise 
155  
-          a :class:`~django.contrib.gis.geos.GEOSException` when called 
  154
+        * :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` will raise
  155
+          a :class:`~django.contrib.gis.geos.GEOSException` when called
156 156
           on a geometry with no SRID value.
157 157
 
158 158
         * :class:`~django.http.CompatCookie` will be removed in favour of
159 159
           :class:`~django.http.SimpleCookie`.
160 160
 
  161
+        * :class:`django.core.context_processors.PermWrapper` and
  162
+          :class:`django.core.context_processors.PermLookupDict`
  163
+          will be moved to :class:`django.contrib.auth.context_processors.PermWrapper`
  164
+          and :class:`django.contrib.auth.context_processors.PermLookupDict`,
  165
+          respectively.
  166
+
161 167
     * 2.0
162 168
         * ``django.views.defaults.shortcut()``. This function has been moved
163 169
           to ``django.contrib.contenttypes.views.shortcut()`` as part of the
7  docs/ref/templates/api.txt
@@ -423,7 +423,7 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
423 423
       via the :doc:`messages framework </ref/contrib/messages>`.
424 424
 
425 425
     * ``perms`` -- An instance of
426  
-      ``django.core.context_processors.PermWrapper``, representing the
  426
+      ``django.contrib.auth.context_processors.PermWrapper``, representing the
427 427
       permissions that the currently logged-in user has.
428 428
 
429 429
 .. versionchanged:: 1.2
@@ -435,6 +435,11 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
435 435
    ``user.get_and_delete_messages()``. It has been changed to include any
436 436
    messages added via the :doc:`messages framework </ref/contrib/messages>`.
437 437
 
  438
+.. versionchanged:: 1.3
  439
+    Prior to version 1.3, ``PermWrapper`` was located in
  440
+    ``django.contrib.auth.context_processors``.
  441
+
  442
+
438 443
 django.core.context_processors.debug
439 444
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440 445
 
12  docs/releases/1.3.txt
@@ -828,3 +828,15 @@ Rationale for this decision:
828 828
 
829 829
  * This location wasn't included in the translation building process for
830 830
    JavaScript literals.
  831
+
  832
+``PermWrapper`` moved to ``django.contrib.auth.context_processors``
  833
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  834
+
  835
+In Django 1.2, we began the process of changing the location of the
  836
+``auth`` context processor from ``django.core.context_processors`` to
  837
+``django.contrib.auth.context_processors``. However, the
  838
+``PermWrapper`` support class was mistakenly omitted from that
  839
+migration. In Django 1.3, the ``PermWrapper`` class has also been
  840
+moved to ``django.contrib.auth.context_processors``, along with the
  841
+``PermLookupDict`` support class. The new classes are functionally
  842
+identical to their old versions; only the module location has changed.
10  docs/topics/auth.txt
@@ -661,7 +661,7 @@ How to log a user out
661 661
 Login and logout signals
662 662
 ------------------------
663 663
 
664  
-.. versionadded:: 1.3 
  664
+.. versionadded:: 1.3
665 665
 
666 666
 The auth framework uses two :doc:`signals </topics/signals>` that can be used
667 667
 for notification when a user logs in or out.
@@ -949,7 +949,7 @@ includes a few other useful built-in views located in
949 949
     Allows a user to reset their password by generating a one-time use link
950 950
     that can be used to reset the password, and sending that link to the
951 951
     user's registered e-mail address.
952  
-    
  952
+
953 953
     .. versionchanged:: 1.3
954 954
         The ``from_email`` argument was added.
955 955
 
@@ -1334,9 +1334,13 @@ Permissions
1334 1334
 
1335 1335
 The currently logged-in user's permissions are stored in the template variable
1336 1336
 ``{{ 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
1338 1338
 template-friendly proxy of permissions.
1339 1339
 
  1340
+.. versionchanged:: 1.3
  1341
+    Prior to version 1.3, ``PermWrapper`` was located in
  1342
+    ``django.contrib.auth.context_processors``.
  1343
+
1340 1344
 In the ``{{ perms }}`` object, single-attribute lookup is a proxy to
1341 1345
 :meth:`User.has_module_perms <django.contrib.auth.models.User.has_module_perms>`.
1342 1346
 This example would display ``True`` if the logged-in user had any permissions

0 notes on commit 7aa8491

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