From 560b4207b1490a7d0cbf70cfbeba7daf2082e5be Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Thu, 27 Nov 2014 02:41:27 +0200 Subject: Removed redundant numbered parameters from str.format(). Since Python 2.7 and 3.1, "{0} {1}" is equivalent to "{} {}". --- django/forms/forms.py | 4 ++-- django/forms/utils.py | 12 ++++++------ django/forms/widgets.py | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'django/forms') 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('{1}', attrs, contents) + contents = format_html('{}', 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( - '
    {0}
', - format_html_join('', '
  • {0}{1}
  • ', ((k, force_text(v)) for k, v in self.items())) + '
      {}
    ', + format_html_join('', '
  • {}{}
  • ', ((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( - '
      {1}
    ', + '
      {}
    ', self.error_class, - format_html_join('', '
  • {0}
  • ', ((force_text(e),) for e in self)) + format_html_join('', '
  • {}
  • ', ((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( - '', + '', 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( - '', + '', 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('', flatatt(final_attrs)) + return format_html('', 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('', flatatt(input_attrs))) + inputs.append(format_html('', 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('\r\n{1}', + return format_html('\r\n{}', 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('', flatatt(final_attrs)) + return format_html('', 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('', flatatt(final_attrs))] + output = [format_html('', 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('', + return format_html('', 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('', force_text(option_value))) + output.append(format_html('', force_text(option_value))) for option in option_label: output.append(self.render_option(selected_choices, *option)) output.append('') @@ -579,7 +579,7 @@ class SelectMultiple(Select): if value is None: value = [] final_attrs = self.build_attrs(attrs, name=name) - output = [format_html('', 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( - '{1} {2}', label_for, self.tag(attrs), self.choice_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('', flatatt(final_attrs)) + return format_html('', 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))) -- cgit v1.3