Fixed #18572 - Python26 string format incompatibility

Thanks to anonymous/AeroNotix for the report
This commit is contained in:
Luke Plant 2012-07-05 23:23:03 +01:00
parent d3c2eb103f
commit 8fdc56d2a6
5 changed files with 14 additions and 14 deletions

View File

@ -31,7 +31,7 @@ def paginator_number(cl,i):
if i == DOT:
return '... '
elif i == cl.page_num:
return format_html('<span class="this-page">{}</span> ', i+1)
return format_html('<span class="this-page">{0}</span> ', i+1)
else:
return format_html('<a href="{0}"{1}>{2}</a> ',
cl.get_query_string({PAGE_VAR: i}),
@ -162,7 +162,7 @@ def result_headers(cl):
"url_primary": cl.get_query_string({ORDER_VAR: '.'.join(o_list_primary)}),
"url_remove": cl.get_query_string({ORDER_VAR: '.'.join(o_list_remove)}),
"url_toggle": cl.get_query_string({ORDER_VAR: '.'.join(o_list_toggle)}),
"class_attrib": format_html(' class="{}"', ' '.join(th_classes))
"class_attrib": format_html(' class="{0}"', ' '.join(th_classes))
if th_classes else '',
}

View File

@ -167,7 +167,7 @@ class BaseForm(StrAndUnicode):
# punctuation.
if self.label_suffix:
if label[-1] not in ':?.!':
label = format_html('{}{}', label, self.label_suffix)
label = format_html('{0}{1}', label, self.label_suffix)
label = bf.label_tag(label) or ''
else:
label = ''

View File

@ -20,7 +20,7 @@ def flatatt(attrs):
The result is passed through 'mark_safe'.
"""
return format_html_join('', ' {}="{}"', attrs.items())
return format_html_join('', ' {0}="{1}"', attrs.items())
class ErrorDict(dict, StrAndUnicode):
"""
@ -33,7 +33,7 @@ class ErrorDict(dict, StrAndUnicode):
def as_ul(self):
if not self: return ''
return format_html('<ul class="errorlist">{}</ul>',
return format_html('<ul class="errorlist">{0}</ul>',
format_html_join('', '<li>{0}{1}</li>',
((k, force_unicode(v))
for k, v in self.items())
@ -51,8 +51,8 @@ class ErrorList(list, StrAndUnicode):
def as_ul(self):
if not self: return ''
return format_html('<ul class="errorlist">{}</ul>',
format_html_join('', '<li>{}</li>',
return format_html('<ul class="errorlist">{0}</ul>',
format_html_join('', '<li>{0}</li>',
((force_unicode(e),) for e in self)
)
)

View File

@ -254,7 +254,7 @@ class Input(Widget):
if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_unicode(self._format_value(value))
return format_html('<input{} />', flatatt(final_attrs))
return format_html('<input{0} />', flatatt(final_attrs))
class TextInput(Input):
input_type = 'text'
@ -295,7 +295,7 @@ class MultipleHiddenInput(HiddenInput):
# An ID attribute was given. Add a numeric index as a suffix
# so that the inputs don't all have the same ID attribute.
input_attrs['id'] = '%s_%s' % (id_, i)
inputs.append(format_html('<input{} />', flatatt(input_attrs)))
inputs.append(format_html('<input{0} />', flatatt(input_attrs)))
return mark_safe('\n'.join(inputs))
def value_from_datadict(self, data, files, name):
@ -512,7 +512,7 @@ class CheckboxInput(Widget):
if not (value is True or value is False or value is None or value == ''):
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_unicode(value)
return format_html('<input{} />', flatatt(final_attrs))
return format_html('<input{0} />', flatatt(final_attrs))
def value_from_datadict(self, data, files, name):
if name not in data:
@ -544,7 +544,7 @@ class Select(Widget):
def render(self, name, value, attrs=None, choices=()):
if value is None: value = ''
final_attrs = self.build_attrs(attrs, name=name)
output = [format_html('<select{}>', flatatt(final_attrs))]
output = [format_html('<select{0}>', flatatt(final_attrs))]
options = self.render_options(choices, [value])
if options:
output.append(options)
@ -620,7 +620,7 @@ class SelectMultiple(Select):
def render(self, name, value, attrs=None, choices=()):
if value is None: value = []
final_attrs = self.build_attrs(attrs, name=name)
output = [format_html('<select multiple="multiple"{}>', flatatt(final_attrs))]
output = [format_html('<select multiple="multiple"{0}>', flatatt(final_attrs))]
options = self.render_options(choices, value)
if options:
output.append(options)
@ -679,7 +679,7 @@ class RadioInput(SubWidget):
final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value)
if self.is_checked():
final_attrs['checked'] = 'checked'
return format_html('<input{} />', flatatt(final_attrs))
return format_html('<input{0} />', flatatt(final_attrs))
class RadioFieldRenderer(StrAndUnicode):
"""

View File

@ -47,7 +47,7 @@ class CsrfTokenNode(Node):
if csrf_token == 'NOTPROVIDED':
return format_html("")
else:
return format_html("<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='{}' /></div>", csrf_token)
return format_html("<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='{0}' /></div>", csrf_token)
else:
# It's very probable that the token is missing because of
# misconfiguration, so we raise a warning