summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-11-27 02:41:27 +0200
committerTim Graham <timograham@gmail.com>2014-12-03 14:27:38 -0500
commit560b4207b1490a7d0cbf70cfbeba7daf2082e5be (patch)
tree9656c5e6a5d0de63024bb5ff2291963f4f236100 /django
parent50c1d8f24b0d04c813b3dd34720df86446091afa (diff)
Removed redundant numbered parameters from str.format().
Since Python 2.7 and 3.1, "{0} {1}" is equivalent to "{} {}".
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/helpers.py2
-rw-r--r--django/contrib/admin/templatetags/admin_list.py22
-rw-r--r--django/contrib/admin/utils.py2
-rw-r--r--django/contrib/admin/widgets.py8
-rw-r--r--django/contrib/auth/forms.py4
-rw-r--r--django/contrib/gis/maps/google/gmap.py12
-rw-r--r--django/contrib/sessions/tests.py2
-rw-r--r--django/forms/forms.py4
-rw-r--r--django/forms/utils.py12
-rw-r--r--django/forms/widgets.py30
-rw-r--r--django/template/defaulttags.py4
-rw-r--r--django/utils/html.py2
-rw-r--r--django/utils/log.py2
13 files changed, 53 insertions, 53 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index a7c95f5046..0383f1c72a 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -178,7 +178,7 @@ class AdminReadonlyField(object):
if not self.is_first:
attrs["class"] = "inline"
label = self.field['label']
- return format_html('<label{0}>{1}:</label>',
+ return format_html('<label{}>{}:</label>',
flatatt(attrs),
capfirst(force_text(label)))
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index 702f1166fe..544c5503ec 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -34,9 +34,9 @@ def paginator_number(cl, i):
if i == DOT:
return '... '
elif i == cl.page_num:
- return format_html('<span class="this-page">{0}</span> ', i + 1)
+ return format_html('<span class="this-page">{}</span> ', i + 1)
else:
- return format_html('<a href="{0}"{1}>{2}</a> ',
+ return format_html('<a href="{}"{}>{}</a> ',
cl.get_query_string({PAGE_VAR: i}),
mark_safe(' class="end"' if i == cl.paginator.num_pages - 1 else ''),
i + 1)
@@ -117,13 +117,13 @@ def result_headers(cl):
# Not sortable
yield {
"text": text,
- "class_attrib": format_html(' class="column-{0}"', field_name),
+ "class_attrib": format_html(' class="column-{}"', field_name),
"sortable": False,
}
continue
# OK, it is sortable if we got this far
- th_classes = ['sortable', 'column-{0}'.format(field_name)]
+ th_classes = ['sortable', 'column-{}'.format(field_name)]
order_type = ''
new_order_type = 'asc'
sort_priority = 0
@@ -168,14 +168,14 @@ 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="{0}"', ' '.join(th_classes)) if th_classes else '',
+ "class_attrib": format_html(' class="{}"', ' '.join(th_classes)) if th_classes else '',
}
def _boolean_icon(field_val):
icon_url = static('admin/img/icon-%s.gif' %
{True: 'yes', False: 'no', None: 'unknown'}[field_val])
- return format_html('<img src="{0}" alt="{1}" />', icon_url, field_val)
+ return format_html('<img src="{}" alt="{}" />', icon_url, field_val)
def items_for_result(cl, result, form):
@@ -249,15 +249,15 @@ def items_for_result(cl, result, form):
value = result.serializable_value(attr)
result_id = escapejs(value)
link_or_text = format_html(
- '<a href="{0}"{1}>{2}</a>',
+ '<a href="{}"{}>{}</a>',
url,
format_html(
' onclick="opener.dismissRelatedLookupPopup(window, '
- '&#39;{0}&#39;); return false;"', result_id
+ '&#39;{}&#39;); return false;"', result_id
) if cl.is_popup else '',
result_repr)
- yield format_html('<{0}{1}>{2}</{3}>',
+ yield format_html('<{}{}>{}</{}>',
table_tag,
row_class,
link_or_text,
@@ -271,9 +271,9 @@ def items_for_result(cl, result, form):
form[cl.model._meta.pk.name].is_hidden)):
bf = form[field_name]
result_repr = mark_safe(force_text(bf.errors) + force_text(bf))
- yield format_html('<td{0}>{1}</td>', row_class, result_repr)
+ yield format_html('<td{}>{}</td>', row_class, result_repr)
if form and not form[cl.model._meta.pk.name].is_hidden:
- yield format_html('<td>{0}</td>', force_text(form[cl.model._meta.pk.name]))
+ yield format_html('<td>{}</td>', force_text(form[cl.model._meta.pk.name]))
class ResultList(list):
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py
index d6756332d3..20e3561e76 100644
--- a/django/contrib/admin/utils.py
+++ b/django/contrib/admin/utils.py
@@ -142,7 +142,7 @@ def get_deleted_objects(objs, opts, user, admin_site, using):
if not user.has_perm(p):
perms_needed.add(opts.verbose_name)
# Display a link to the admin page.
- return format_html('{0}: <a href="{1}">{2}</a>',
+ return format_html('{}: <a href="{}">{}</a>',
capfirst(opts.verbose_name),
admin_url,
obj)
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index 3b14087176..c7312b9a46 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -87,7 +87,7 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget):
forms.MultiWidget.__init__(self, widgets, attrs)
def format_output(self, rendered_widgets):
- return format_html('<p class="datetime">{0} {1}<br />{2} {3}</p>',
+ return format_html('<p class="datetime">{} {}<br />{} {}</p>',
_('Date:'), rendered_widgets[0],
_('Time:'), rendered_widgets[1])
@@ -95,9 +95,9 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget):
class AdminRadioFieldRenderer(RadioFieldRenderer):
def render(self):
"""Outputs a <ul> for this set of radio fields."""
- return format_html('<ul{0}>\n{1}\n</ul>',
+ return format_html('<ul{}>\n{}\n</ul>',
flatatt(self.attrs),
- format_html_join('\n', '<li>{0}</li>',
+ format_html_join('\n', '<li>{}</li>',
((force_text(w),) for w in self)))
@@ -325,7 +325,7 @@ class AdminURLFieldWidget(forms.URLInput):
value = force_text(self._format_value(value))
final_attrs = {'href': smart_urlquote(value)}
html = format_html(
- '<p class="url">{0} <a{1}>{2}</a><br />{3} {4}</p>',
+ '<p class="url">{} <a{}>{}</a><br />{} {}</p>',
_('Currently:'), flatatt(final_attrs), value,
_('Change:'), html
)
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index c54a0862ed..86cfa291c9 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -44,12 +44,12 @@ class ReadOnlyPasswordHashWidget(forms.Widget):
"Invalid password format or unknown hashing algorithm."))
else:
summary = format_html_join('',
- "<strong>{0}</strong>: {1} ",
+ "<strong>{}</strong>: {} ",
((ugettext(key), value)
for key, value in hasher.safe_summary(encoded).items())
)
- return format_html("<div{0}>{1}</div>", flatatt(final_attrs), summary)
+ return format_html("<div{}>{}</div>", flatatt(final_attrs), summary)
class ReadOnlyPasswordHashField(forms.Field):
diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py
index 82e1eeeb24..4694996283 100644
--- a/django/contrib/gis/maps/google/gmap.py
+++ b/django/contrib/gis/maps/google/gmap.py
@@ -121,17 +121,17 @@ class GoogleMap(object):
@property
def body(self):
"Returns HTML body tag for loading and unloading Google Maps javascript."
- return format_html('<body {0} {1}>', self.onload, self.onunload)
+ return format_html('<body {} {}>', self.onload, self.onunload)
@property
def onload(self):
"Returns the `onload` HTML <body> attribute."
- return format_html('onload="{0}.{1}_load()"', self.js_module, self.dom_id)
+ return format_html('onload="{}.{}_load()"', self.js_module, self.dom_id)
@property
def api_script(self):
"Returns the <script> tag for the Google Maps API javascript."
- return format_html('<script src="{0}{1}" type="text/javascript"></script>',
+ return format_html('<script src="{}{}" type="text/javascript"></script>',
self.api_url, self.key)
@property
@@ -142,18 +142,18 @@ class GoogleMap(object):
@property
def scripts(self):
"Returns all <script></script> tags required with Google Maps JavaScript."
- return format_html('{0}\n <script type="text/javascript">\n//<![CDATA[\n{1}//]]>\n </script>',
+ return format_html('{}\n <script type="text/javascript">\n//<![CDATA[\n{}//]]>\n </script>',
self.api_script, mark_safe(self.js))
@property
def style(self):
"Returns additional CSS styling needed for Google Maps on IE."
- return format_html('<style type="text/css">{0}</style>', self.vml_css)
+ return format_html('<style type="text/css">{}</style>', self.vml_css)
@property
def xhtml(self):
"Returns XHTML information needed for IE VML overlays."
- return format_html('<html xmlns="http://www.w3.org/1999/xhtml" {0}>', self.xmlns)
+ return format_html('<html xmlns="http://www.w3.org/1999/xhtml" {}>', self.xmlns)
@property
def icons(self):
diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py
index fe74c3f255..6679899a34 100644
--- a/django/contrib/sessions/tests.py
+++ b/django/contrib/sessions/tests.py
@@ -601,7 +601,7 @@ class SessionMiddlewareTests(unittest.TestCase):
# A deleted cookie header looks like:
# Set-Cookie: sessionid=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
self.assertEqual(
- 'Set-Cookie: {0}=; expires=Thu, 01-Jan-1970 00:00:00 GMT; '
+ 'Set-Cookie: {}=; expires=Thu, 01-Jan-1970 00:00:00 GMT; '
'Max-Age=0; Path=/'.format(settings.SESSION_COOKIE_NAME),
str(response.cookies[settings.SESSION_COOKIE_NAME])
)
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 3f6a876832..e68542e12a 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -645,7 +645,7 @@ class BoundField(object):
# Translators: If found as last label character, these punctuation
# characters will prevent the default label_suffix to be appended to the label
if label_suffix and contents and contents[-1] not in _(':?.!'):
- contents = format_html('{0}{1}', contents, label_suffix)
+ contents = format_html('{}{}', contents, label_suffix)
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
if id_:
@@ -659,7 +659,7 @@ class BoundField(object):
else:
attrs['class'] = self.form.required_css_class
attrs = flatatt(attrs) if attrs else ''
- contents = format_html('<label{0}>{1}</label>', attrs, contents)
+ contents = format_html('<label{}>{}</label>', attrs, contents)
else:
contents = conditional_escape(contents)
return mark_safe(contents)
diff --git a/django/forms/utils.py b/django/forms/utils.py
index 7d4cd90b57..19c27f9b8c 100644
--- a/django/forms/utils.py
+++ b/django/forms/utils.py
@@ -39,8 +39,8 @@ def flatatt(attrs):
key_value_attrs.append((attr, value))
return (
- format_html_join('', ' {0}="{1}"', sorted(key_value_attrs)) +
- format_html_join('', ' {0}', sorted(boolean_attrs))
+ format_html_join('', ' {}="{}"', sorted(key_value_attrs)) +
+ format_html_join('', ' {}', sorted(boolean_attrs))
)
@@ -61,8 +61,8 @@ class ErrorDict(dict):
if not self:
return ''
return format_html(
- '<ul class="errorlist">{0}</ul>',
- format_html_join('', '<li>{0}{1}</li>', ((k, force_text(v)) for k, v in self.items()))
+ '<ul class="errorlist">{}</ul>',
+ format_html_join('', '<li>{}{}</li>', ((k, force_text(v)) for k, v in self.items()))
)
def as_text(self):
@@ -110,9 +110,9 @@ class ErrorList(UserList, list):
return ''
return format_html(
- '<ul class="{0}">{1}</ul>',
+ '<ul class="{}">{}</ul>',
self.error_class,
- format_html_join('', '<li>{0}</li>', ((force_text(e),) for e in self))
+ format_html_join('', '<li>{}</li>', ((force_text(e),) for e in self))
)
def as_text(self):
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 7e3c8f3dca..de75b35932 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -53,7 +53,7 @@ class Media(object):
def render_js(self):
return [
format_html(
- '<script type="text/javascript" src="{0}"></script>',
+ '<script type="text/javascript" src="{}"></script>',
self.absolute_path(path)
) for path in self._js
]
@@ -64,7 +64,7 @@ class Media(object):
media = sorted(self._css.keys())
return chain(*[[
format_html(
- '<link href="{0}" type="text/css" media="{1}" rel="stylesheet" />',
+ '<link href="{}" type="text/css" media="{}" rel="stylesheet" />',
self.absolute_path(path), medium
) for path in self._css[medium]
] for medium in media])
@@ -252,7 +252,7 @@ class Input(Widget):
if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_text(self._format_value(value))
- return format_html('<input{0} />', flatatt(final_attrs))
+ return format_html('<input{} />', flatatt(final_attrs))
class TextInput(Input):
@@ -315,7 +315,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{0} />', flatatt(input_attrs)))
+ inputs.append(format_html('<input{} />', flatatt(input_attrs)))
return mark_safe('\n'.join(inputs))
def value_from_datadict(self, data, files, name):
@@ -429,7 +429,7 @@ class Textarea(Widget):
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
- return format_html('<textarea{0}>\r\n{1}</textarea>',
+ return format_html('<textarea{}>\r\n{}</textarea>',
flatatt(final_attrs),
force_text(value))
@@ -478,7 +478,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_text(value)
- return format_html('<input{0} />', flatatt(final_attrs))
+ return format_html('<input{} />', flatatt(final_attrs))
def value_from_datadict(self, data, files, name):
if name not in data:
@@ -507,7 +507,7 @@ class Select(Widget):
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
- output = [format_html('<select{0}>', flatatt(final_attrs))]
+ output = [format_html('<select{}>', flatatt(final_attrs))]
options = self.render_options(choices, [value])
if options:
output.append(options)
@@ -525,7 +525,7 @@ class Select(Widget):
selected_choices.remove(option_value)
else:
selected_html = ''
- return format_html('<option value="{0}"{1}>{2}</option>',
+ return format_html('<option value="{}"{}>{}</option>',
option_value,
selected_html,
force_text(option_label))
@@ -536,7 +536,7 @@ class Select(Widget):
output = []
for option_value, option_label in chain(self.choices, choices):
if isinstance(option_label, (list, tuple)):
- output.append(format_html('<optgroup label="{0}">', force_text(option_value)))
+ output.append(format_html('<optgroup label="{}">', force_text(option_value)))
for option in option_label:
output.append(self.render_option(selected_choices, *option))
output.append('</optgroup>')
@@ -579,7 +579,7 @@ class SelectMultiple(Select):
if value is None:
value = []
final_attrs = self.build_attrs(attrs, name=name)
- output = [format_html('<select multiple="multiple"{0}>', flatatt(final_attrs))]
+ output = [format_html('<select multiple="multiple"{}>', flatatt(final_attrs))]
options = self.render_options(choices, value)
if options:
output.append(options)
@@ -615,12 +615,12 @@ class ChoiceInput(SubWidget):
def render(self, name=None, value=None, attrs=None, choices=()):
if self.id_for_label:
- label_for = format_html(' for="{0}"', self.id_for_label)
+ label_for = format_html(' for="{}"', self.id_for_label)
else:
label_for = ''
attrs = dict(self.attrs, **attrs) if attrs else self.attrs
return format_html(
- '<label{0}>{1} {2}</label>', label_for, self.tag(attrs), self.choice_label
+ '<label{}>{} {}</label>', label_for, self.tag(attrs), self.choice_label
)
def is_checked(self):
@@ -631,7 +631,7 @@ class ChoiceInput(SubWidget):
final_attrs = dict(attrs, type=self.input_type, name=self.name, value=self.choice_value)
if self.is_checked():
final_attrs['checked'] = 'checked'
- return format_html('<input{0} />', flatatt(final_attrs))
+ return format_html('<input{} />', flatatt(final_attrs))
@property
def id_for_label(self):
@@ -693,7 +693,7 @@ class ChoiceFieldRenderer(object):
if isinstance(choice_label, (tuple, list)):
attrs_plus = self.attrs.copy()
if id_:
- attrs_plus['id'] += '_{0}'.format(i)
+ attrs_plus['id'] += '_{}'.format(i)
sub_ul_renderer = ChoiceFieldRenderer(name=self.name,
value=self.value,
attrs=attrs_plus,
@@ -707,7 +707,7 @@ class ChoiceFieldRenderer(object):
output.append(format_html(self.inner_html,
choice_value=force_text(w), sub_widgets=''))
return format_html(self.outer_html,
- id_attr=format_html(' id="{0}"', id_) if id_ else '',
+ id_attr=format_html(' id="{}"', id_) if id_ else '',
content=mark_safe('\n'.join(output)))
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 51ddfc9819..c6814983e7 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -56,7 +56,7 @@ class CsrfTokenNode(Node):
if csrf_token == 'NOTPROVIDED':
return format_html("")
else:
- return format_html("<input type='hidden' name='csrfmiddlewaretoken' value='{0}' />", csrf_token)
+ return format_html("<input type='hidden' name='csrfmiddlewaretoken' value='{}' />", csrf_token)
else:
# It's very probable that the token is missing because of
# misconfiguration, so we raise a warning
@@ -195,7 +195,7 @@ class ForNode(Node):
# Check loop variable count before unpacking
if num_loopvars != len_item:
warnings.warn(
- "Need {0} values to unpack in for loop; got {1}. "
+ "Need {} values to unpack in for loop; got {}. "
"This will raise an exception in Django 2.0."
.format(num_loopvars, len_item),
RemovedInDjango20Warning)
diff --git a/django/utils/html.py b/django/utils/html.py
index 2dc16d5d71..1247849f31 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -105,7 +105,7 @@ def format_html_join(sep, format_string, args_generator):
Example:
- format_html_join('\n', "<li>{0} {1}</li>", ((u.first_name, u.last_name)
+ format_html_join('\n', "<li>{} {}</li>", ((u.first_name, u.last_name)
for u in users))
"""
diff --git a/django/utils/log.py b/django/utils/log.py
index 6ced3a4a63..fc350e0b5e 100644
--- a/django/utils/log.py
+++ b/django/utils/log.py
@@ -109,7 +109,7 @@ class AdminEmailHandler(logging.Handler):
record.getMessage()
)
filter = get_exception_reporter_filter(request)
- request_repr = '\n{0}'.format(force_text(filter.get_request_repr(request)))
+ request_repr = '\n{}'.format(force_text(filter.get_request_repr(request)))
except Exception:
subject = '%s: %s' % (
record.levelname,