From f87256b15e375c6c57fe425c33ae23e116da3e84 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 10 May 2017 22:39:08 +0200 Subject: [PATCH] Refs #27795 -- Replaced force_text() with str() in contrib.messages Thanks Tim Graham for the review. --- django/contrib/messages/storage/base.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/django/contrib/messages/storage/base.py b/django/contrib/messages/storage/base.py index 43fe3da23cf..fd5d0c24aa8 100644 --- a/django/contrib/messages/storage/base.py +++ b/django/contrib/messages/storage/base.py @@ -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: