Ticket #15757: 15757.contrib-messages-cleanup.diff

File 15757.contrib-messages-cleanup.diff, 6.1 KB (added by julien, 4 years ago)
  • django/contrib/auth/context_processors.py

    diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py
    index 7750ab7..ad72cd8 100644
    a b  
    11from django.utils.functional import lazy, memoize, SimpleLazyObject
    2 from django.contrib import messages
    32
    43# PermWrapper and PermLookupDict proxy the permissions system into objects that
    54# the template system can understand.
    def auth(request): 
    5554
    5655    return {
    5756        'user': SimpleLazyObject(get_user),
    58         'messages': messages.get_messages(request),
    5957        'perms':  lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
    6058    }
  • django/contrib/messages/api.py

    diff --git a/django/contrib/messages/api.py b/django/contrib/messages/api.py
    index 1079ae1..9880d7f 100644
    a b class MessageFailure(Exception): 
    1515
    1616def add_message(request, level, message, extra_tags='', fail_silently=False):
    1717    """
    18     Attempts to add a message to the request using the 'messages' app, falling
    19     back to the user's message_set if MessageMiddleware hasn't been enabled.
     18    Attempts to add a message to the request using the 'messages' app.
    2019    """
    2120    if hasattr(request, '_messages'):
    2221        return request._messages.add(level, message, extra_tags)
    2322    if not fail_silently:
    24         raise MessageFailure('Without the django.contrib.messages '
    25                                 'middleware, messages can only be added to '
    26                                 'authenticated users.')
     23        raise MessageFailure('You cannot add messages without installing '
     24                    'django.contrib.messages.middleware.MessageMiddleware')
    2725
    2826
    2927def get_messages(request):
    3028    """
    3129    Returns the message storage on the request if it exists, otherwise returns
    32     user.message_set.all() as the old auth context processor did.
     30    an empty list.
    3331    """
    3432    if hasattr(request, '_messages'):
    3533        return request._messages
    36 
    37     def get_user():
    38         if hasattr(request, 'user'):
    39             return request.user
    40         else:
    41             from django.contrib.auth.models import AnonymousUser
    42             return AnonymousUser()
    43 
    44     return lazy(memoize(get_user().get_and_delete_messages, {}, 0), list)()
     34    else:
     35        return []
    4536
    4637
    4738def get_level(request):
  • django/contrib/messages/tests/base.py

    diff --git a/django/contrib/messages/tests/base.py b/django/contrib/messages/tests/base.py
    index 932ca27..c6886a8 100644
    a b from django.contrib.messages.api import MessageFailure 
    1010from django.contrib.messages.storage import default_storage, base
    1111from django.contrib.messages.storage.base import Message
    1212from django.core.urlresolvers import reverse
    13 from django.contrib.auth.models import User
    1413
    1514
    1615def skipUnlessAuthIsInstalled(func):
    class BaseTest(TestCase): 
    222221        for msg in data['messages']:
    223222            self.assertContains(response, msg)
    224223
    225     def test_middleware_disabled_anon_user(self):
     224    def test_middleware_disabled(self):
    226225        """
    227         Tests that, when the middleware is disabled and a user is not logged
    228         in, an exception is raised when one attempts to store a message.
     226        Tests that, when the middleware is disabled, an exception is raised
     227        when one attempts to store a message.
    229228        """
    230229        settings.MESSAGE_LEVEL = constants.DEBUG
    231230        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
    class BaseTest(TestCase): 
    251250            self.assertRaises(MessageFailure, self.client.post, add_url,
    252251                              data, follow=True)
    253252
    254     def test_middleware_disabled_anon_user_fail_silently(self):
     253    def test_middleware_disabled_fail_silently(self):
    255254        """
    256         Tests that, when the middleware is disabled and a user is not logged
    257         in, an exception is not raised if 'fail_silently' = True
     255        Tests that, when the middleware is disabled, an exception is not
     256        raised if 'fail_silently' = True
    258257        """
    259258        settings.MESSAGE_LEVEL = constants.DEBUG
    260259        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index cd6ff31..e20a2e1 100644
    a b Django's admin interface. 
    1414Overview
    1515========
    1616
    17 There are six steps in activating the Django admin site:
     17There are seven steps in activating the Django admin site:
    1818
    1919    1. Add ``'django.contrib.admin'`` to your :setting:`INSTALLED_APPS`
    2020       setting.
    2121
    22     2. Admin has two dependencies - :mod:`django.contrib.auth` and
    23        :mod:`django.contrib.contenttypes`. If these applications are not
    24        in your :setting:`INSTALLED_APPS` list, add them.
     22    2. Admin has three dependencies - :mod:`django.contrib.auth`,
     23       :mod:`django.contrib.contenttypes` and :mod:`django.contrib.messages`.
     24       If these applications are not in your :setting:`INSTALLED_APPS` list,
     25       add them.
    2526
    26     3. Determine which of your application's models should be editable in the
     27    3. Add ``django.contrib.messages.context_processors.messages`` to
     28       :setting:`TEMPLATE_CONTEXT_PROCESSORS` and
     29       :class:`~django.contrib.messages.middleware.MessageMiddleware` to
     30       :setting:`MIDDLEWARE_CLASSES`.
     31
     32    4. Determine which of your application's models should be editable in the
    2733       admin interface.
    2834
    29     4. For each of those models, optionally create a ``ModelAdmin`` class that
     35    5. For each of those models, optionally create a ``ModelAdmin`` class that
    3036       encapsulates the customized admin functionality and options for that
    3137       particular model.
    3238
    33     5. Instantiate an ``AdminSite`` and tell it about each of your models and
     39    6. Instantiate an ``AdminSite`` and tell it about each of your models and
    3440       ``ModelAdmin`` classes.
    3541
    36     6. Hook the ``AdminSite`` instance into your URLconf.
     42    7. Hook the ``AdminSite`` instance into your URLconf.
    3743
    3844Other topics
    3945------------
Back to Top