Replace force_unicode with force_text

Django changed the name to force_unicode and it's only available in
python2 as an alias of force_text. The new name is available since
Django 1.4.2

Closes-Bug: #1345642
Change-Id: Ida8c545ceec7c31999f2497d540a0dc5a653d286
This commit is contained in:
Felipe Reyes 2014-07-16 17:50:03 +02:00
parent b4d0310807
commit af49cf1f15
15 changed files with 35 additions and 35 deletions

View File

@ -12,7 +12,7 @@ Horizon Style Commandments
django.core.urlresolvers.reverse_lazy,
django.template.loader.render_to_string,
django.utils.datastructures.SortedDict,
django.utils.encoding.force_unicode,
django.utils.encoding.force_text,
django.utils.html.conditional_escape,
django.utils.html.escape,
django.utils.http.urlencode,

View File

@ -261,7 +261,7 @@ def handle(request, message=None, redirect=None, ignore=False,
exc_type, exc_value, exc_traceback = exc_value.wrapped
wrap = True
log_entry = encoding.force_unicode(exc_value)
log_entry = encoding.force_text(exc_value)
# We trust messages from our own exceptions
if issubclass(exc_type, HorizonException):
@ -271,9 +271,9 @@ def handle(request, message=None, redirect=None, ignore=False,
message = exc_value._safe_message
# If the message has a placeholder for the exception, fill it in
elif message and "%(exc)s" in message:
message = encoding.force_unicode(message) % {"exc": log_entry}
message = encoding.force_text(message) % {"exc": log_entry}
if message:
message = encoding.force_unicode(message)
message = encoding.force_text(message)
if issubclass(exc_type, UNAUTHORIZED):
if ignore:

View File

@ -20,7 +20,7 @@ from django.core.exceptions import ValidationError # noqa
from django.core import urlresolvers
from django.forms import fields
from django.forms import widgets
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.functional import Promise # noqa
from django.utils import html
from django.utils.translation import ugettext_lazy as _
@ -144,21 +144,21 @@ class SelectWidget(widgets.Select):
super(SelectWidget, self).__init__(attrs, choices)
def render_option(self, selected_choices, option_value, option_label):
option_value = force_unicode(option_value)
option_value = force_text(option_value)
other_html = (option_value in selected_choices) and \
u' selected="selected"' or ''
if not isinstance(option_label, (basestring, Promise)):
for data_attr in self.data_attrs:
data_value = html.conditional_escape(
force_unicode(getattr(option_label,
data_attr, "")))
force_text(getattr(option_label,
data_attr, "")))
other_html += ' data-%s="%s"' % (data_attr, data_value)
if self.transform:
option_label = self.transform(option_label)
return u'<option value="%s"%s>%s</option>' % (
html.escape(option_value), other_html,
html.conditional_escape(force_unicode(option_label)))
html.conditional_escape(force_text(option_label)))
class DynamicSelectWidget(widgets.Select):

View File

@ -19,7 +19,7 @@ messaging needs (e.g. AJAX communication, etc.).
from django.contrib import messages as _messages
from django.contrib.messages import constants
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.safestring import SafeData # noqa
@ -32,7 +32,7 @@ def add_message(request, level, message, extra_tags='', fail_silently=False):
if isinstance(message, SafeData):
extra_tags = extra_tags + ' safe'
request.horizon['async_messages'].append([tag,
force_unicode(message),
force_text(message),
extra_tags])
else:
return _messages.add_message(request, level, message,

View File

@ -16,7 +16,7 @@ from __future__ import absolute_import
from django import template
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from horizon.base import Horizon # noqa
@ -118,9 +118,9 @@ def quota(val, units=None):
if val == float("inf"):
return _("No Limit")
elif units is not None:
return "%s %s %s" % (val, units, force_unicode(_("Available")))
return "%s %s %s" % (val, units, force_text(_("Available")))
else:
return "%s %s" % (val, force_unicode(_("Available")))
return "%s %s" % (val, force_text(_("Available")))
@register.filter

View File

@ -30,7 +30,7 @@ from django.core.handlers import wsgi
from django import http
from django import test as django_test
from django.test.client import RequestFactory # noqa
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils import unittest
LOG = logging.getLogger(__name__)
@ -156,7 +156,7 @@ class TestCase(django_test.TestCase):
# Otherwise, make sure we got the expected messages.
for msg_type, count in kwargs.items():
msgs = [force_unicode(m.message)
msgs = [force_text(m.message)
for m in messages if msg_type in m.tags]
assert len(msgs) == count, \
"%s messages not as expected: %s" % (msg_type.title(),

View File

@ -332,7 +332,7 @@ class GetUserHomeTests(BaseHorizonTests):
base.Horizon.get_user_home(self.test_user))
def test_using_module_function(self):
module_func = 'django.utils.encoding.force_unicode'
module_func = 'django.utils.encoding.force_text'
settings.HORIZON_CONFIG['user_home'] = module_func
conf.HORIZON_CONFIG._setup()

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from horizon import exceptions
from horizon.test import helpers as test
@ -25,7 +25,7 @@ class HandleTests(test.TestCase):
# Japanese translation of:
# 'Because the container is not empty, it can not be deleted.'
expected = ['error', force_unicode(translated_unicode), '']
expected = ['error', force_text(translated_unicode), '']
req = self.request
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'

View File

@ -15,7 +15,7 @@
import json
from django import http
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from horizon import messages
@ -27,7 +27,7 @@ class MessageTests(test.TestCase):
def test_middleware_header(self):
req = self.request
string = "Giant ants are attacking San Francisco!"
expected = ["error", force_unicode(string), ""]
expected = ["error", force_text(string), ""]
self.assertTrue("async_messages" in req.horizon)
self.assertItemsEqual(req.horizon['async_messages'], [])
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
@ -41,7 +41,7 @@ class MessageTests(test.TestCase):
def test_safe_message(self):
req = self.request
string = mark_safe("We are now safe from ants! Go <a>here</a>!")
expected = ["error", force_unicode(string), " safe"]
expected = ["error", force_text(string), " safe"]
self.assertTrue("async_messages" in req.horizon)
self.assertItemsEqual(req.horizon['async_messages'], [])
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'

View File

@ -16,13 +16,13 @@ import re
from django.conf import settings
from django.contrib.auth import logout # noqa
from django import http
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.functional import lazy # noqa
from django.utils import translation
def _lazy_join(separator, strings):
return separator.join([force_unicode(s)
return separator.join([force_text(s)
for s in strings])
lazy_join = lazy(_lazy_join, unicode)

View File

@ -23,7 +23,7 @@ from django import template
from django.template.defaultfilters import linebreaks # noqa
from django.template.defaultfilters import safe # noqa
from django.template.defaultfilters import slugify # noqa
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.importlib import import_module # noqa
from django.utils.translation import ugettext_lazy as _
import six
@ -139,7 +139,7 @@ class Action(forms.Form):
self.required_css_class = 'required'
def __unicode__(self):
return force_unicode(self.name)
return force_text(self.name)
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.slug)
@ -159,7 +159,7 @@ class Action(forms.Form):
context = template.RequestContext(self.request, extra_context)
text += tmpl.render(context)
else:
text += linebreaks(force_unicode(self.help_text))
text += linebreaks(force_text(self.help_text))
return safe(text)
def add_error(self, message):
@ -285,7 +285,7 @@ class Step(object):
return "<%s: %s>" % (self.__class__.__name__, self.slug)
def __unicode__(self):
return force_unicode(self.name)
return force_text(self.name)
def __init__(self, workflow):
super(Step, self).__init__()
@ -426,7 +426,7 @@ class Step(object):
def get_help_text(self):
"""Returns the help text for this step."""
text = linebreaks(force_unicode(self.help_text))
text = linebreaks(force_text(self.help_text))
text += self.action.get_help_text()
return safe(text)

View File

@ -18,7 +18,7 @@
from django.core.urlresolvers import reverse
from django.core import validators
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
@ -116,7 +116,7 @@ class UploadObject(forms.SelfHandlingForm):
data['container_name'],
object_path,
object_file)
msg = force_unicode(_("Object was successfully uploaded."))
msg = force_text(_("Object was successfully uploaded."))
messages.success(request, msg)
return obj
except Exception:

View File

@ -18,7 +18,7 @@ from django.forms import util
from django.forms import widgets
from django import template
from django.template import defaultfilters
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
@ -136,7 +136,7 @@ class JobBinaryCreateForm(forms.SelfHandlingForm):
context = template.RequestContext(self.request, extra_context)
text += tmpl.render(context)
else:
text += defaultfilters.linebreaks(force_unicode(self.help_text))
text += defaultfilters.linebreaks(force_text(self.help_text))
return defaultfilters.safe(text)
class Meta:

View File

@ -100,6 +100,6 @@ class UserSettingsForm(forms.SelfHandlingForm):
with translation.override(lang_code):
messages.success(request,
encoding.force_unicode(_("Settings saved.")))
encoding.force_text(_("Settings saved.")))
return response

View File

@ -74,7 +74,7 @@ import_exceptions = collections.defaultdict,
django.template.loader.render_to_string,
django.test.utils.override_settings,
django.utils.datastructures.SortedDict,
django.utils.encoding.force_unicode,
django.utils.encoding.force_text,
django.utils.html.conditional_escape,
django.utils.html.escape,
django.utils.http.urlencode,