diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py
index 7750ab7..ad72cd8 100644
a
|
b
|
|
1 | 1 | from django.utils.functional import lazy, memoize, SimpleLazyObject |
2 | | from django.contrib import messages |
3 | 2 | |
4 | 3 | # PermWrapper and PermLookupDict proxy the permissions system into objects that |
5 | 4 | # the template system can understand. |
… |
… |
def auth(request):
|
55 | 54 | |
56 | 55 | return { |
57 | 56 | 'user': SimpleLazyObject(get_user), |
58 | | 'messages': messages.get_messages(request), |
59 | 57 | 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), |
60 | 58 | } |
diff --git a/django/contrib/messages/api.py b/django/contrib/messages/api.py
index 1079ae1..9880d7f 100644
a
|
b
|
class MessageFailure(Exception):
|
15 | 15 | |
16 | 16 | def add_message(request, level, message, extra_tags='', fail_silently=False): |
17 | 17 | """ |
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. |
20 | 19 | """ |
21 | 20 | if hasattr(request, '_messages'): |
22 | 21 | return request._messages.add(level, message, extra_tags) |
23 | 22 | 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') |
27 | 25 | |
28 | 26 | |
29 | 27 | def get_messages(request): |
30 | 28 | """ |
31 | 29 | 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. |
33 | 31 | """ |
34 | 32 | if hasattr(request, '_messages'): |
35 | 33 | 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 [] |
45 | 36 | |
46 | 37 | |
47 | 38 | def get_level(request): |
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
|
10 | 10 | from django.contrib.messages.storage import default_storage, base |
11 | 11 | from django.contrib.messages.storage.base import Message |
12 | 12 | from django.core.urlresolvers import reverse |
13 | | from django.contrib.auth.models import User |
14 | 13 | |
15 | 14 | |
16 | 15 | def skipUnlessAuthIsInstalled(func): |
… |
… |
class BaseTest(TestCase):
|
222 | 221 | for msg in data['messages']: |
223 | 222 | self.assertContains(response, msg) |
224 | 223 | |
225 | | def test_middleware_disabled_anon_user(self): |
| 224 | def test_middleware_disabled(self): |
226 | 225 | """ |
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. |
229 | 228 | """ |
230 | 229 | settings.MESSAGE_LEVEL = constants.DEBUG |
231 | 230 | settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) |
… |
… |
class BaseTest(TestCase):
|
251 | 250 | self.assertRaises(MessageFailure, self.client.post, add_url, |
252 | 251 | data, follow=True) |
253 | 252 | |
254 | | def test_middleware_disabled_anon_user_fail_silently(self): |
| 253 | def test_middleware_disabled_fail_silently(self): |
255 | 254 | """ |
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 |
258 | 257 | """ |
259 | 258 | settings.MESSAGE_LEVEL = constants.DEBUG |
260 | 259 | settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) |
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.
|
14 | 14 | Overview |
15 | 15 | ======== |
16 | 16 | |
17 | | There are six steps in activating the Django admin site: |
| 17 | There are seven steps in activating the Django admin site: |
18 | 18 | |
19 | 19 | 1. Add ``'django.contrib.admin'`` to your :setting:`INSTALLED_APPS` |
20 | 20 | setting. |
21 | 21 | |
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. |
25 | 26 | |
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 |
27 | 33 | admin interface. |
28 | 34 | |
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 |
30 | 36 | encapsulates the customized admin functionality and options for that |
31 | 37 | particular model. |
32 | 38 | |
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 |
34 | 40 | ``ModelAdmin`` classes. |
35 | 41 | |
36 | | 6. Hook the ``AdminSite`` instance into your URLconf. |
| 42 | 7. Hook the ``AdminSite`` instance into your URLconf. |
37 | 43 | |
38 | 44 | Other topics |
39 | 45 | ------------ |