Refs #27795 -- Replaced force_text() with str() in contrib.messages
Thanks Tim Graham for the review.
This commit is contained in:
parent
d1e5516c06
commit
f87256b15e
|
@ -1,6 +1,5 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.messages import constants, utils
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
LEVEL_TAGS = utils.get_level_tags()
|
||||
|
||||
|
@ -21,34 +20,24 @@ class Message:
|
|||
"""
|
||||
Prepare the message for serialization by forcing the ``message``
|
||||
and ``extra_tags`` to str in case they are lazy translations.
|
||||
|
||||
Known "safe" types (None, int, etc.) are not converted (see Django's
|
||||
``force_text`` implementation for details).
|
||||
"""
|
||||
self.message = force_text(self.message, strings_only=True)
|
||||
self.extra_tags = force_text(self.extra_tags, strings_only=True)
|
||||
self.message = str(self.message)
|
||||
self.extra_tags = str(self.extra_tags) if self.extra_tags is not None else None
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, Message) and self.level == other.level and \
|
||||
self.message == other.message
|
||||
|
||||
def __str__(self):
|
||||
return force_text(self.message)
|
||||
return str(self.message)
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
extra_tags = force_text(self.extra_tags, strings_only=True)
|
||||
if extra_tags and self.level_tag:
|
||||
return ' '.join([extra_tags, self.level_tag])
|
||||
elif extra_tags:
|
||||
return extra_tags
|
||||
elif self.level_tag:
|
||||
return self.level_tag
|
||||
return ''
|
||||
return ' '.join(tag for tag in [self.extra_tags, self.level_tag] if tag)
|
||||
|
||||
@property
|
||||
def level_tag(self):
|
||||
return force_text(LEVEL_TAGS.get(self.level, ''), strings_only=True)
|
||||
return LEVEL_TAGS.get(self.level, '')
|
||||
|
||||
|
||||
class BaseStorage:
|
||||
|
|
Loading…
Reference in New Issue