1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #20610: Added a message level dict to contrib.message context processor.

This commit is contained in:
Baptiste Mispelon
2013-10-28 21:52:11 +01:00
parent e9a356a695
commit 9fde42a69a
5 changed files with 40 additions and 1 deletions

View File

@@ -11,3 +11,11 @@ DEFAULT_TAGS = {
WARNING: 'warning',
ERROR: 'error',
}
DEFAULT_LEVELS = {
'DEBUG': DEBUG,
'INFO': INFO,
'SUCCESS': SUCCESS,
'WARNING': WARNING,
'ERROR': ERROR,
}

View File

@@ -1,8 +1,12 @@
from django.contrib.messages.api import get_messages
from django.contrib.messages.constants import DEFAULT_LEVELS
def messages(request):
"""
Returns a lazy 'messages' context variable.
"""
return {'messages': get_messages(request)}
return {
'messages': get_messages(request),
'DEFAULT_MESSAGE_LEVELS': DEFAULT_LEVELS,
}

View File

@@ -4,6 +4,7 @@ from django import http
from django.conf import settings, global_settings
from django.contrib.messages import constants, utils, get_level, set_level
from django.contrib.messages.api import MessageFailure
from django.contrib.messages.constants import DEFAULT_LEVELS
from django.contrib.messages.storage import default_storage, base
from django.contrib.messages.storage.base import Message
from django.core.urlresolvers import reverse
@@ -189,6 +190,13 @@ class BaseTests(object):
for msg in data['messages']:
self.assertNotContains(response, msg)
def test_context_processor_message_levels(self):
show_url = reverse('django.contrib.messages.tests.urls.show_template_response')
response = self.client.get(show_url)
self.assertTrue('DEFAULT_MESSAGE_LEVELS' in response.context)
self.assertEqual(response.context['DEFAULT_MESSAGE_LEVELS'], DEFAULT_LEVELS)
@override_settings(MESSAGE_LEVEL=constants.DEBUG)
def test_multiple_posts(self):
"""