Author: lukeplant
Date: 2011-04-07 15:01:23 -0700 (Thu, 07 Apr 2011)
New Revision: 16022

Modified:
   django/trunk/django/contrib/auth/context_processors.py
   django/trunk/django/contrib/auth/models.py
   django/trunk/django/contrib/messages/api.py
   django/trunk/django/contrib/messages/tests/base.py
   django/trunk/docs/internals/deprecation.txt
   django/trunk/docs/ref/contrib/admin/index.txt
   django/trunk/docs/ref/templates/api.txt
   django/trunk/docs/topics/auth.txt
Log:
Fixed #15757 - removed remaining instances of get_and_delete_messages

Thanks to void for the report, and julien for the bulk of the patch.

Modified: django/trunk/django/contrib/auth/context_processors.py
===================================================================
--- django/trunk/django/contrib/auth/context_processors.py      2011-04-06 
11:19:37 UTC (rev 16021)
+++ django/trunk/django/contrib/auth/context_processors.py      2011-04-07 
22:01:23 UTC (rev 16022)
@@ -1,5 +1,4 @@
 from django.utils.functional import lazy, memoize, SimpleLazyObject
-from django.contrib import messages
 
 # PermWrapper and PermLookupDict proxy the permissions system into objects that
 # the template system can understand.
@@ -55,6 +54,5 @@
 
     return {
         'user': SimpleLazyObject(get_user),
-        'messages': messages.get_messages(request),
         'perms':  lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
     }

Modified: django/trunk/django/contrib/auth/models.py
===================================================================
--- django/trunk/django/contrib/auth/models.py  2011-04-06 11:19:37 UTC (rev 
16021)
+++ django/trunk/django/contrib/auth/models.py  2011-04-07 22:01:23 UTC (rev 
16022)
@@ -445,9 +445,6 @@
     def has_module_perms(self, module):
         return _user_has_module_perms(self, module)
 
-    def get_and_delete_messages(self):
-        return []
-
     def is_anonymous(self):
         return True
 

Modified: django/trunk/django/contrib/messages/api.py
===================================================================
--- django/trunk/django/contrib/messages/api.py 2011-04-06 11:19:37 UTC (rev 
16021)
+++ django/trunk/django/contrib/messages/api.py 2011-04-07 22:01:23 UTC (rev 
16022)
@@ -15,35 +15,26 @@
 
 def add_message(request, level, message, extra_tags='', fail_silently=False):
     """
-    Attempts to add a message to the request using the 'messages' app, falling
-    back to the user's message_set if MessageMiddleware hasn't been enabled.
+    Attempts to add a message to the request using the 'messages' app.
     """
     if hasattr(request, '_messages'):
         return request._messages.add(level, message, extra_tags)
     if not fail_silently:
-        raise MessageFailure('Without the django.contrib.messages '
-                                'middleware, messages can only be added to '
-                                'authenticated users.')
+        raise MessageFailure('You cannot add messages without installing '
+                    'django.contrib.messages.middleware.MessageMiddleware')
 
 
 def get_messages(request):
     """
     Returns the message storage on the request if it exists, otherwise returns
-    user.message_set.all() as the old auth context processor did.
+    an empty list.
     """
     if hasattr(request, '_messages'):
         return request._messages
+    else:
+        return []
 
-    def get_user():
-        if hasattr(request, 'user'):
-            return request.user
-        else:
-            from django.contrib.auth.models import AnonymousUser
-            return AnonymousUser()
 
-    return lazy(memoize(get_user().get_and_delete_messages, {}, 0), list)()
-
-
 def get_level(request):
     """
     Returns the minimum level of messages to be recorded.

Modified: django/trunk/django/contrib/messages/tests/base.py
===================================================================
--- django/trunk/django/contrib/messages/tests/base.py  2011-04-06 11:19:37 UTC 
(rev 16021)
+++ django/trunk/django/contrib/messages/tests/base.py  2011-04-07 22:01:23 UTC 
(rev 16022)
@@ -10,7 +10,6 @@
 from django.contrib.messages.storage import default_storage, base
 from django.contrib.messages.storage.base import Message
 from django.core.urlresolvers import reverse
-from django.contrib.auth.models import User
 
 
 def skipUnlessAuthIsInstalled(func):
@@ -222,10 +221,10 @@
         for msg in data['messages']:
             self.assertContains(response, msg)
 
-    def test_middleware_disabled_anon_user(self):
+    def test_middleware_disabled(self):
         """
-        Tests that, when the middleware is disabled and a user is not logged
-        in, an exception is raised when one attempts to store a message.
+        Tests that, when the middleware is disabled, an exception is raised
+        when one attempts to store a message.
         """
         settings.MESSAGE_LEVEL = constants.DEBUG
         settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
@@ -251,10 +250,10 @@
             self.assertRaises(MessageFailure, self.client.post, add_url,
                               data, follow=True)
 
-    def test_middleware_disabled_anon_user_fail_silently(self):
+    def test_middleware_disabled_fail_silently(self):
         """
-        Tests that, when the middleware is disabled and a user is not logged
-        in, an exception is not raised if 'fail_silently' = True
+        Tests that, when the middleware is disabled, an exception is not
+        raised if 'fail_silently' = True
         """
         settings.MESSAGE_LEVEL = constants.DEBUG
         settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)

Modified: django/trunk/docs/internals/deprecation.txt
===================================================================
--- django/trunk/docs/internals/deprecation.txt 2011-04-06 11:19:37 UTC (rev 
16021)
+++ django/trunk/docs/internals/deprecation.txt 2011-04-07 22:01:23 UTC (rev 
16022)
@@ -52,7 +52,10 @@
           ``user.get_and_delete_messages()``), which have
           been deprecated since the 1.2 release, will be removed.  The
           :doc:`messages framework </ref/contrib/messages>` should be used
-          instead.
+          instead. The related ``messages`` variable returned by the
+          auth context processor will also be removed. Note that this
+          means that the admin application depends on the messages
+          context processor.
 
         * Authentication backends need to support the ``obj`` parameter for
           permission checking. The ``supports_object_permissions`` variable

Modified: django/trunk/docs/ref/contrib/admin/index.txt
===================================================================
--- django/trunk/docs/ref/contrib/admin/index.txt       2011-04-06 11:19:37 UTC 
(rev 16021)
+++ django/trunk/docs/ref/contrib/admin/index.txt       2011-04-07 22:01:23 UTC 
(rev 16022)
@@ -14,26 +14,32 @@
 Overview
 ========
 
-There are six steps in activating the Django admin site:
+There are seven steps in activating the Django admin site:
 
     1. Add ``'django.contrib.admin'`` to your :setting:`INSTALLED_APPS`
        setting.
 
-    2. Admin has two dependencies - :mod:`django.contrib.auth` and
-       :mod:`django.contrib.contenttypes`. If these applications are not
-       in your :setting:`INSTALLED_APPS` list, add them.
+    2. Admin has three dependencies - :mod:`django.contrib.auth`,
+       :mod:`django.contrib.contenttypes` and :mod:`django.contrib.messages`.
+       If these applications are not in your :setting:`INSTALLED_APPS` list,
+       add them.
 
-    3. Determine which of your application's models should be editable in the
+    3. Add ``django.contrib.messages.context_processors.messages`` to
+       :setting:`TEMPLATE_CONTEXT_PROCESSORS` and
+       :class:`~django.contrib.messages.middleware.MessageMiddleware` to
+       :setting:`MIDDLEWARE_CLASSES`.
+
+    4. Determine which of your application's models should be editable in the
        admin interface.
 
-    4. For each of those models, optionally create a ``ModelAdmin`` class that
+    5. For each of those models, optionally create a ``ModelAdmin`` class that
        encapsulates the customized admin functionality and options for that
        particular model.
 
-    5. Instantiate an ``AdminSite`` and tell it about each of your models and
+    6. Instantiate an ``AdminSite`` and tell it about each of your models and
        ``ModelAdmin`` classes.
 
-    6. Hook the ``AdminSite`` instance into your URLconf.
+    7. Hook the ``AdminSite`` instance into your URLconf.
 
 Other topics
 ------------

Modified: django/trunk/docs/ref/templates/api.txt
===================================================================
--- django/trunk/docs/ref/templates/api.txt     2011-04-06 11:19:37 UTC (rev 
16021)
+++ django/trunk/docs/ref/templates/api.txt     2011-04-07 22:01:23 UTC (rev 
16022)
@@ -419,9 +419,6 @@
       logged-in user (or an ``AnonymousUser`` instance, if the client isn't
       logged in).
 
-    * ``messages`` -- A list of messages (as strings) that have been set
-      via the :doc:`messages framework </ref/contrib/messages>`.
-
     * ``perms`` -- An instance of
       ``django.contrib.auth.context_processors.PermWrapper``, representing the
       permissions that the currently logged-in user has.
@@ -430,11 +427,6 @@
     This context processor was moved in this release from
     ``django.core.context_processors.auth`` to its current location.
 
-.. versionchanged:: 1.2
-   Prior to version 1.2, the ``messages`` variable was a lazy accessor for
-   ``user.get_and_delete_messages()``. It has been changed to include any
-   messages added via the :doc:`messages framework </ref/contrib/messages>`.
-
 .. versionchanged:: 1.3
     Prior to version 1.3, ``PermWrapper`` was located in
     ``django.contrib.auth.context_processors``.

Modified: django/trunk/docs/topics/auth.txt
===================================================================
--- django/trunk/docs/topics/auth.txt   2011-04-06 11:19:37 UTC (rev 16021)
+++ django/trunk/docs/topics/auth.txt   2011-04-07 22:01:23 UTC (rev 16022)
@@ -19,11 +19,7 @@
       a certain task.
     * Groups: A generic way of applying labels and permissions to more than one
       user.
-    * Messages: A simple way to queue messages for given users.
 
-.. deprecated:: 1.2
-   The Messages component of the auth system will be removed in Django 1.4.
-
 Installation
 ============
 
@@ -256,11 +252,6 @@
         (the Django app label). If the user is inactive, this method will
         always return ``False``.
 
-    .. method:: models.User.get_and_delete_messages()
-
-        Returns a list of :class:`~django.contrib.auth.models.Message` objects
-        in the user's queue and deletes the messages from the queue.
-
     .. method:: models.User.email_user(subject, message, from_email=None)
 
         Sends an email to the user. If
@@ -1387,70 +1378,6 @@
 access to a members-only portion of your site, or send them members-only email
 messages.
 
-Messages
-========
-
-.. deprecated:: 1.2
-   This functionality will be removed in Django 1.4.  You should use the
-   :doc:`messages framework </ref/contrib/messages>` for all new projects and
-   begin to update your existing code immediately.
-
-The message system is a lightweight way to queue messages for given users.
-
-A message is associated with a :class:`~django.contrib.auth.models.User`.
-There's no concept of expiration or timestamps.
-
-Messages are used by the Django admin after successful actions. For example,
-``"The poll Foo was created successfully."`` is a message.
-
-The API is simple:
-
-.. method:: models.User.message_set.create(message)
-
-    To create a new message, use
-    ``user_obj.message_set.create(message='message_text')``.
-
-    To retrieve/delete messages, use
-    :meth:`user_obj.get_and_delete_messages() 
<django.contrib.auth.models.User.get_and_delete_messages>`,
-    which returns a list of ``Message`` objects in the user's queue (if any)
-    and deletes the messages from the queue.
-
-In this example view, the system saves a message for the user after creating
-a playlist::
-
-    def create_playlist(request, songs):
-        # Create the playlist with the given songs.
-        # ...
-        request.user.message_set.create(message="Your playlist was added 
successfully.")
-        return render_to_response("playlists/create.html",
-            context_instance=RequestContext(request))
-
-When you use :class:`~django.template.context.RequestContext`, the currently
-logged-in user and his/her messages are made available in the
-:doc:`template context </ref/templates/api>` as the template variable
-``{{ messages }}``. Here's an example of template code that displays messages:
-
-.. code-block:: html+django
-
-    {% if messages %}
-    <ul>
-        {% for message in messages %}
-        <li>{{ message }}</li>
-        {% endfor %}
-    </ul>
-    {% endif %}
-
-.. versionchanged:: 1.2
-   The ``messages`` template variable uses a backwards compatible method in the
-   :doc:`messages framework </ref/contrib/messages>` to retrieve messages from
-   both the user ``Message`` model and from the new framework.  Unlike in
-   previous revisions, the messages will not be erased unless they are actually
-   displayed.
-
-Finally, note that this messages framework only works with users in the user
-database. To send messages to anonymous users, use the
-:doc:`messages framework </ref/contrib/messages>`.
-
 .. _authentication-backends:
 
 Other authentication sources

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to