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:
parent
b4d0310807
commit
af49cf1f15
@ -12,7 +12,7 @@ Horizon Style Commandments
|
|||||||
django.core.urlresolvers.reverse_lazy,
|
django.core.urlresolvers.reverse_lazy,
|
||||||
django.template.loader.render_to_string,
|
django.template.loader.render_to_string,
|
||||||
django.utils.datastructures.SortedDict,
|
django.utils.datastructures.SortedDict,
|
||||||
django.utils.encoding.force_unicode,
|
django.utils.encoding.force_text,
|
||||||
django.utils.html.conditional_escape,
|
django.utils.html.conditional_escape,
|
||||||
django.utils.html.escape,
|
django.utils.html.escape,
|
||||||
django.utils.http.urlencode,
|
django.utils.http.urlencode,
|
||||||
|
@ -261,7 +261,7 @@ def handle(request, message=None, redirect=None, ignore=False,
|
|||||||
exc_type, exc_value, exc_traceback = exc_value.wrapped
|
exc_type, exc_value, exc_traceback = exc_value.wrapped
|
||||||
wrap = True
|
wrap = True
|
||||||
|
|
||||||
log_entry = encoding.force_unicode(exc_value)
|
log_entry = encoding.force_text(exc_value)
|
||||||
|
|
||||||
# We trust messages from our own exceptions
|
# We trust messages from our own exceptions
|
||||||
if issubclass(exc_type, HorizonException):
|
if issubclass(exc_type, HorizonException):
|
||||||
@ -271,9 +271,9 @@ def handle(request, message=None, redirect=None, ignore=False,
|
|||||||
message = exc_value._safe_message
|
message = exc_value._safe_message
|
||||||
# If the message has a placeholder for the exception, fill it in
|
# If the message has a placeholder for the exception, fill it in
|
||||||
elif message and "%(exc)s" in message:
|
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:
|
if message:
|
||||||
message = encoding.force_unicode(message)
|
message = encoding.force_text(message)
|
||||||
|
|
||||||
if issubclass(exc_type, UNAUTHORIZED):
|
if issubclass(exc_type, UNAUTHORIZED):
|
||||||
if ignore:
|
if ignore:
|
||||||
|
@ -20,7 +20,7 @@ from django.core.exceptions import ValidationError # noqa
|
|||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
from django.forms import fields
|
from django.forms import fields
|
||||||
from django.forms import widgets
|
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.functional import Promise # noqa
|
||||||
from django.utils import html
|
from django.utils import html
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@ -144,21 +144,21 @@ class SelectWidget(widgets.Select):
|
|||||||
super(SelectWidget, self).__init__(attrs, choices)
|
super(SelectWidget, self).__init__(attrs, choices)
|
||||||
|
|
||||||
def render_option(self, selected_choices, option_value, option_label):
|
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 \
|
other_html = (option_value in selected_choices) and \
|
||||||
u' selected="selected"' or ''
|
u' selected="selected"' or ''
|
||||||
if not isinstance(option_label, (basestring, Promise)):
|
if not isinstance(option_label, (basestring, Promise)):
|
||||||
for data_attr in self.data_attrs:
|
for data_attr in self.data_attrs:
|
||||||
data_value = html.conditional_escape(
|
data_value = html.conditional_escape(
|
||||||
force_unicode(getattr(option_label,
|
force_text(getattr(option_label,
|
||||||
data_attr, "")))
|
data_attr, "")))
|
||||||
other_html += ' data-%s="%s"' % (data_attr, data_value)
|
other_html += ' data-%s="%s"' % (data_attr, data_value)
|
||||||
|
|
||||||
if self.transform:
|
if self.transform:
|
||||||
option_label = self.transform(option_label)
|
option_label = self.transform(option_label)
|
||||||
return u'<option value="%s"%s>%s</option>' % (
|
return u'<option value="%s"%s>%s</option>' % (
|
||||||
html.escape(option_value), other_html,
|
html.escape(option_value), other_html,
|
||||||
html.conditional_escape(force_unicode(option_label)))
|
html.conditional_escape(force_text(option_label)))
|
||||||
|
|
||||||
|
|
||||||
class DynamicSelectWidget(widgets.Select):
|
class DynamicSelectWidget(widgets.Select):
|
||||||
|
@ -19,7 +19,7 @@ messaging needs (e.g. AJAX communication, etc.).
|
|||||||
|
|
||||||
from django.contrib import messages as _messages
|
from django.contrib import messages as _messages
|
||||||
from django.contrib.messages import constants
|
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
|
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):
|
if isinstance(message, SafeData):
|
||||||
extra_tags = extra_tags + ' safe'
|
extra_tags = extra_tags + ' safe'
|
||||||
request.horizon['async_messages'].append([tag,
|
request.horizon['async_messages'].append([tag,
|
||||||
force_unicode(message),
|
force_text(message),
|
||||||
extra_tags])
|
extra_tags])
|
||||||
else:
|
else:
|
||||||
return _messages.add_message(request, level, message,
|
return _messages.add_message(request, level, message,
|
||||||
|
@ -16,7 +16,7 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils.datastructures import SortedDict
|
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 django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from horizon.base import Horizon # noqa
|
from horizon.base import Horizon # noqa
|
||||||
@ -118,9 +118,9 @@ def quota(val, units=None):
|
|||||||
if val == float("inf"):
|
if val == float("inf"):
|
||||||
return _("No Limit")
|
return _("No Limit")
|
||||||
elif units is not None:
|
elif units is not None:
|
||||||
return "%s %s %s" % (val, units, force_unicode(_("Available")))
|
return "%s %s %s" % (val, units, force_text(_("Available")))
|
||||||
else:
|
else:
|
||||||
return "%s %s" % (val, force_unicode(_("Available")))
|
return "%s %s" % (val, force_text(_("Available")))
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
@ -30,7 +30,7 @@ from django.core.handlers import wsgi
|
|||||||
from django import http
|
from django import http
|
||||||
from django import test as django_test
|
from django import test as django_test
|
||||||
from django.test.client import RequestFactory # noqa
|
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
|
from django.utils import unittest
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -156,7 +156,7 @@ class TestCase(django_test.TestCase):
|
|||||||
|
|
||||||
# Otherwise, make sure we got the expected messages.
|
# Otherwise, make sure we got the expected messages.
|
||||||
for msg_type, count in kwargs.items():
|
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]
|
for m in messages if msg_type in m.tags]
|
||||||
assert len(msgs) == count, \
|
assert len(msgs) == count, \
|
||||||
"%s messages not as expected: %s" % (msg_type.title(),
|
"%s messages not as expected: %s" % (msg_type.title(),
|
||||||
|
@ -332,7 +332,7 @@ class GetUserHomeTests(BaseHorizonTests):
|
|||||||
base.Horizon.get_user_home(self.test_user))
|
base.Horizon.get_user_home(self.test_user))
|
||||||
|
|
||||||
def test_using_module_function(self):
|
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
|
settings.HORIZON_CONFIG['user_home'] = module_func
|
||||||
conf.HORIZON_CONFIG._setup()
|
conf.HORIZON_CONFIG._setup()
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon.test import helpers as test
|
from horizon.test import helpers as test
|
||||||
@ -25,7 +25,7 @@ class HandleTests(test.TestCase):
|
|||||||
# Japanese translation of:
|
# Japanese translation of:
|
||||||
# 'Because the container is not empty, it can not be deleted.'
|
# '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 = self.request
|
||||||
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from django import http
|
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 django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from horizon import messages
|
from horizon import messages
|
||||||
@ -27,7 +27,7 @@ class MessageTests(test.TestCase):
|
|||||||
def test_middleware_header(self):
|
def test_middleware_header(self):
|
||||||
req = self.request
|
req = self.request
|
||||||
string = "Giant ants are attacking San Francisco!"
|
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.assertTrue("async_messages" in req.horizon)
|
||||||
self.assertItemsEqual(req.horizon['async_messages'], [])
|
self.assertItemsEqual(req.horizon['async_messages'], [])
|
||||||
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||||
@ -41,7 +41,7 @@ class MessageTests(test.TestCase):
|
|||||||
def test_safe_message(self):
|
def test_safe_message(self):
|
||||||
req = self.request
|
req = self.request
|
||||||
string = mark_safe("We are now safe from ants! Go <a>here</a>!")
|
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.assertTrue("async_messages" in req.horizon)
|
||||||
self.assertItemsEqual(req.horizon['async_messages'], [])
|
self.assertItemsEqual(req.horizon['async_messages'], [])
|
||||||
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||||
|
@ -16,13 +16,13 @@ import re
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import logout # noqa
|
from django.contrib.auth import logout # noqa
|
||||||
from django import http
|
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.functional import lazy # noqa
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
|
|
||||||
def _lazy_join(separator, strings):
|
def _lazy_join(separator, strings):
|
||||||
return separator.join([force_unicode(s)
|
return separator.join([force_text(s)
|
||||||
for s in strings])
|
for s in strings])
|
||||||
|
|
||||||
lazy_join = lazy(_lazy_join, unicode)
|
lazy_join = lazy(_lazy_join, unicode)
|
||||||
|
@ -23,7 +23,7 @@ from django import template
|
|||||||
from django.template.defaultfilters import linebreaks # noqa
|
from django.template.defaultfilters import linebreaks # noqa
|
||||||
from django.template.defaultfilters import safe # noqa
|
from django.template.defaultfilters import safe # noqa
|
||||||
from django.template.defaultfilters import slugify # 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.importlib import import_module # noqa
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
import six
|
import six
|
||||||
@ -139,7 +139,7 @@ class Action(forms.Form):
|
|||||||
self.required_css_class = 'required'
|
self.required_css_class = 'required'
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return force_unicode(self.name)
|
return force_text(self.name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
||||||
@ -159,7 +159,7 @@ class Action(forms.Form):
|
|||||||
context = template.RequestContext(self.request, extra_context)
|
context = template.RequestContext(self.request, extra_context)
|
||||||
text += tmpl.render(context)
|
text += tmpl.render(context)
|
||||||
else:
|
else:
|
||||||
text += linebreaks(force_unicode(self.help_text))
|
text += linebreaks(force_text(self.help_text))
|
||||||
return safe(text)
|
return safe(text)
|
||||||
|
|
||||||
def add_error(self, message):
|
def add_error(self, message):
|
||||||
@ -285,7 +285,7 @@ class Step(object):
|
|||||||
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
return "<%s: %s>" % (self.__class__.__name__, self.slug)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return force_unicode(self.name)
|
return force_text(self.name)
|
||||||
|
|
||||||
def __init__(self, workflow):
|
def __init__(self, workflow):
|
||||||
super(Step, self).__init__()
|
super(Step, self).__init__()
|
||||||
@ -426,7 +426,7 @@ class Step(object):
|
|||||||
|
|
||||||
def get_help_text(self):
|
def get_help_text(self):
|
||||||
"""Returns the help text for this step."""
|
"""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()
|
text += self.action.get_help_text()
|
||||||
return safe(text)
|
return safe(text)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.core import validators
|
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 django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
@ -116,7 +116,7 @@ class UploadObject(forms.SelfHandlingForm):
|
|||||||
data['container_name'],
|
data['container_name'],
|
||||||
object_path,
|
object_path,
|
||||||
object_file)
|
object_file)
|
||||||
msg = force_unicode(_("Object was successfully uploaded."))
|
msg = force_text(_("Object was successfully uploaded."))
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return obj
|
return obj
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -18,7 +18,7 @@ from django.forms import util
|
|||||||
from django.forms import widgets
|
from django.forms import widgets
|
||||||
from django import template
|
from django import template
|
||||||
from django.template import defaultfilters
|
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.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ class JobBinaryCreateForm(forms.SelfHandlingForm):
|
|||||||
context = template.RequestContext(self.request, extra_context)
|
context = template.RequestContext(self.request, extra_context)
|
||||||
text += tmpl.render(context)
|
text += tmpl.render(context)
|
||||||
else:
|
else:
|
||||||
text += defaultfilters.linebreaks(force_unicode(self.help_text))
|
text += defaultfilters.linebreaks(force_text(self.help_text))
|
||||||
return defaultfilters.safe(text)
|
return defaultfilters.safe(text)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -100,6 +100,6 @@ class UserSettingsForm(forms.SelfHandlingForm):
|
|||||||
|
|
||||||
with translation.override(lang_code):
|
with translation.override(lang_code):
|
||||||
messages.success(request,
|
messages.success(request,
|
||||||
encoding.force_unicode(_("Settings saved.")))
|
encoding.force_text(_("Settings saved.")))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
2
tox.ini
2
tox.ini
@ -74,7 +74,7 @@ import_exceptions = collections.defaultdict,
|
|||||||
django.template.loader.render_to_string,
|
django.template.loader.render_to_string,
|
||||||
django.test.utils.override_settings,
|
django.test.utils.override_settings,
|
||||||
django.utils.datastructures.SortedDict,
|
django.utils.datastructures.SortedDict,
|
||||||
django.utils.encoding.force_unicode,
|
django.utils.encoding.force_text,
|
||||||
django.utils.html.conditional_escape,
|
django.utils.html.conditional_escape,
|
||||||
django.utils.html.escape,
|
django.utils.html.escape,
|
||||||
django.utils.http.urlencode,
|
django.utils.http.urlencode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user