Use %s when non-ascii characters can be contained
.format() in python 2.7 cannot handle a unicode string if it contains non-ASCII characters. This breaks i18n situations. The behavior of .format() is different between python2 and python3. We should use .format() only when we are confident that .format() can handle passed values (like ASCII string or integer) correctly. This commit does not touch other usages of .format() which work well. Change-Id: I329b33c1c7776d7f24488572107f7ea35f418398 Closes-Bug: #1551014
This commit is contained in:
parent
b21a51325e
commit
bfc0daa683
|
@ -288,8 +288,7 @@ class CheckboxSelectMultiple(forms.CheckboxSelectMultiple):
|
|||
service_description = _("%s processes: ") % current_service
|
||||
service_description = html.conditional_escape(
|
||||
encoding.force_text(service_description))
|
||||
output.append(
|
||||
"<label>{0}</label>".format(service_description))
|
||||
output.append("<label>%s</label>" % service_description)
|
||||
initial_service = current_service
|
||||
output.append(encoding.force_text("<ul>"))
|
||||
if has_id:
|
||||
|
@ -305,8 +304,8 @@ class CheckboxSelectMultiple(forms.CheckboxSelectMultiple):
|
|||
option_label = html.conditional_escape(
|
||||
encoding.force_text(option_label))
|
||||
output.append(
|
||||
'<li><label{0}>{1} {2}</label></li>'.format(
|
||||
label_for, rendered_cb, option_label))
|
||||
'<li><label%s>%s %s</label></li>' %
|
||||
(label_for, rendered_cb, option_label))
|
||||
output.append('</ul>')
|
||||
return safestring.mark_safe('\n'.join(output))
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ class ChooseTemplateForm(forms.SelfHandlingForm):
|
|||
data = saharaclient.nodegroup_template_find(self.request,
|
||||
plugin_name=plugin,
|
||||
hadoop_version=version)
|
||||
choices = [("{0}|{1}".format(ngt.name, ngt.id), ngt.name)
|
||||
choices = [("%s|%s" % (ngt.name, ngt.id), ngt.name)
|
||||
for ngt in data]
|
||||
return choices
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@ class MakeUnProtected(RuleChangeAction):
|
|||
def get_is_public_form(object_type):
|
||||
return forms.BooleanField(
|
||||
label=_("Public"),
|
||||
help_text=_("If selected, {object_type} will be shared across the "
|
||||
"tenants").format(object_type=object_type),
|
||||
help_text=_("If selected, %s will be shared across the "
|
||||
"tenants") % object_type,
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
initial=False,
|
||||
|
@ -133,9 +133,8 @@ def get_is_public_form(object_type):
|
|||
def get_is_protected_form(object_type):
|
||||
return forms.BooleanField(
|
||||
label=_("Protected"),
|
||||
help_text=_("If selected, {object_type} will be protected from "
|
||||
"modifications until this will be unselected").format(
|
||||
object_type=object_type),
|
||||
help_text=_("If selected, %s will be protected from modifications "
|
||||
"until this will be unselected") % object_type,
|
||||
required=False,
|
||||
widget=forms.CheckboxInput(),
|
||||
initial=False)
|
||||
|
|
|
@ -386,14 +386,14 @@ class ShareWidget(forms.MultiWidget):
|
|||
if item_widget_index == 0:
|
||||
output.append("<tr>")
|
||||
output.append(
|
||||
"<td class='col-sm-2 small-padding'>{0}</td>".format(
|
||||
self.widgets[i].attrs["label"]))
|
||||
"<td class='col-sm-2 small-padding'>%s</td>" %
|
||||
self.widgets[i].attrs["label"])
|
||||
# The last 2 form field td need get a larger size
|
||||
if item_widget_index in [1, 2]:
|
||||
size = 4
|
||||
else:
|
||||
size = 2
|
||||
output.append("<td class='col-sm-{0} small-padding'>".format(size)
|
||||
output.append("<td class='col-sm-%s small-padding'>" % size
|
||||
+ widget + "</td>")
|
||||
if item_widget_index == 2:
|
||||
output.append("</tr>")
|
||||
|
|
Loading…
Reference in New Issue