Fixed #15757 - removed remaining instances of get_and_delete_messages

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16022 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2011-04-07 22:01:23 +00:00
parent b7715b4ae6
commit 8d4b414760
8 changed files with 30 additions and 117 deletions

View file

@ -52,7 +52,10 @@ their deprecation, as per the :ref:`Django deprecation policy
``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

View file

@ -14,26 +14,32 @@ Django's admin interface.
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
------------

View file

@ -419,9 +419,6 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
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 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
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``.

View file

@ -19,10 +19,6 @@ The auth system consists of:
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 @@ Methods
(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 @@ group ``'Special users'``, and you could write code that could, say, give them
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