mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
Fixed E128 flake8 warnings in django/.
This commit is contained in:
@@ -775,8 +775,10 @@ class ChoiceField(Field):
|
||||
|
||||
def __init__(self, choices=(), required=True, widget=None, label=None,
|
||||
initial=None, help_text='', *args, **kwargs):
|
||||
super(ChoiceField, self).__init__(required=required, widget=widget, label=label,
|
||||
initial=initial, help_text=help_text, *args, **kwargs)
|
||||
super(ChoiceField, self).__init__(
|
||||
required=required, widget=widget, label=label, initial=initial,
|
||||
help_text=help_text, *args, **kwargs
|
||||
)
|
||||
self.choices = choices
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
@@ -1090,9 +1092,10 @@ class FilePathField(ChoiceField):
|
||||
initial=None, help_text='', *args, **kwargs):
|
||||
self.path, self.match, self.recursive = path, match, recursive
|
||||
self.allow_files, self.allow_folders = allow_files, allow_folders
|
||||
super(FilePathField, self).__init__(choices=(), required=required,
|
||||
widget=widget, label=label, initial=initial, help_text=help_text,
|
||||
*args, **kwargs)
|
||||
super(FilePathField, self).__init__(
|
||||
choices=(), required=required, widget=widget, label=label,
|
||||
initial=initial, help_text=help_text, *args, **kwargs
|
||||
)
|
||||
|
||||
if self.required:
|
||||
self.choices = []
|
||||
|
||||
@@ -38,8 +38,7 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass):
|
||||
current_fields.sort(key=lambda x: x[1].creation_counter)
|
||||
attrs['declared_fields'] = OrderedDict(current_fields)
|
||||
|
||||
new_class = (super(DeclarativeFieldsMetaclass, mcs)
|
||||
.__new__(mcs, name, bases, attrs))
|
||||
new_class = super(DeclarativeFieldsMetaclass, mcs).__new__(mcs, name, bases, attrs)
|
||||
|
||||
# Walk through the MRO.
|
||||
declared_fields = OrderedDict()
|
||||
|
||||
@@ -738,14 +738,15 @@ class BaseModelFormSet(BaseFormSet):
|
||||
"field": unique_check[0],
|
||||
}
|
||||
else:
|
||||
return ugettext("Please correct the duplicate data for %(field)s, "
|
||||
"which must be unique.") % {
|
||||
return ugettext("Please correct the duplicate data for %(field)s, which must be unique.") % {
|
||||
"field": get_text_list(unique_check, six.text_type(_("and"))),
|
||||
}
|
||||
|
||||
def get_date_error_message(self, date_check):
|
||||
return ugettext("Please correct the duplicate data for %(field_name)s "
|
||||
"which must be unique for the %(lookup)s in %(date_field)s.") % {
|
||||
return ugettext(
|
||||
"Please correct the duplicate data for %(field_name)s "
|
||||
"which must be unique for the %(lookup)s in %(date_field)s."
|
||||
) % {
|
||||
'field_name': date_check[2],
|
||||
'date_field': date_check[3],
|
||||
'lookup': six.text_type(date_check[1]),
|
||||
@@ -1126,8 +1127,7 @@ class ModelChoiceIterator(object):
|
||||
yield self.choice(obj)
|
||||
|
||||
def __len__(self):
|
||||
return (len(self.queryset) +
|
||||
(1 if self.field.empty_label is not None else 0))
|
||||
return (len(self.queryset) + (1 if self.field.empty_label is not None else 0))
|
||||
|
||||
def choice(self, obj):
|
||||
return (self.field.prepare_value(obj), self.field.label_from_instance(obj))
|
||||
@@ -1252,8 +1252,10 @@ class ModelMultipleChoiceField(ModelChoiceField):
|
||||
|
||||
def __init__(self, queryset, required=True, widget=None, label=None,
|
||||
initial=None, help_text='', *args, **kwargs):
|
||||
super(ModelMultipleChoiceField, self).__init__(queryset, None,
|
||||
required, widget, label, initial, help_text, *args, **kwargs)
|
||||
super(ModelMultipleChoiceField, self).__init__(
|
||||
queryset, None, required, widget, label, initial, help_text,
|
||||
*args, **kwargs
|
||||
)
|
||||
|
||||
def to_python(self, value):
|
||||
if not value:
|
||||
|
||||
@@ -147,8 +147,7 @@ class MediaDefiningClass(type):
|
||||
Metaclass for classes that can have media definitions.
|
||||
"""
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
new_class = (super(MediaDefiningClass, mcs)
|
||||
.__new__(mcs, name, bases, attrs))
|
||||
new_class = super(MediaDefiningClass, mcs).__new__(mcs, name, bases, attrs)
|
||||
|
||||
if 'media' not in attrs:
|
||||
new_class.media = media_property(new_class)
|
||||
@@ -433,9 +432,7 @@ class Textarea(Widget):
|
||||
if value is None:
|
||||
value = ''
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
return format_html('<textarea{}>\r\n{}</textarea>',
|
||||
flatatt(final_attrs),
|
||||
force_text(value))
|
||||
return format_html('<textarea{}>\r\n{}</textarea>', flatatt(final_attrs), force_text(value))
|
||||
|
||||
|
||||
class DateTimeBaseInput(TextInput):
|
||||
@@ -447,8 +444,7 @@ class DateTimeBaseInput(TextInput):
|
||||
self.format = format if format else None
|
||||
|
||||
def _format_value(self, value):
|
||||
return formats.localize_input(value,
|
||||
self.format or formats.get_format(self.format_key)[0])
|
||||
return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])
|
||||
|
||||
|
||||
class DateInput(DateTimeBaseInput):
|
||||
@@ -536,10 +532,7 @@ class Select(Widget):
|
||||
selected_choices.remove(option_value)
|
||||
else:
|
||||
selected_html = ''
|
||||
return format_html('<option value="{}"{}>{}</option>',
|
||||
option_value,
|
||||
selected_html,
|
||||
force_text(option_label))
|
||||
return format_html('<option value="{}"{}>{}</option>', option_value, selected_html, force_text(option_label))
|
||||
|
||||
def render_options(self, selected_choices):
|
||||
# Normalize to strings.
|
||||
@@ -561,9 +554,11 @@ class NullBooleanSelect(Select):
|
||||
A Select Widget intended to be used with NullBooleanField.
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
choices = (('1', ugettext_lazy('Unknown')),
|
||||
('2', ugettext_lazy('Yes')),
|
||||
('3', ugettext_lazy('No')))
|
||||
choices = (
|
||||
('1', ugettext_lazy('Unknown')),
|
||||
('2', ugettext_lazy('Yes')),
|
||||
('3', ugettext_lazy('No')),
|
||||
)
|
||||
super(NullBooleanSelect, self).__init__(attrs, choices)
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
@@ -575,12 +570,14 @@ class NullBooleanSelect(Select):
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
value = data.get(name)
|
||||
return {'2': True,
|
||||
True: True,
|
||||
'True': True,
|
||||
'3': False,
|
||||
'False': False,
|
||||
False: False}.get(value)
|
||||
return {
|
||||
'2': True,
|
||||
True: True,
|
||||
'True': True,
|
||||
'3': False,
|
||||
'False': False,
|
||||
False: False,
|
||||
}.get(value)
|
||||
|
||||
|
||||
class SelectMultiple(Select):
|
||||
@@ -714,16 +711,18 @@ class ChoiceFieldRenderer(object):
|
||||
choices=choice_label,
|
||||
)
|
||||
sub_ul_renderer.choice_input_class = self.choice_input_class
|
||||
output.append(format_html(self.inner_html, choice_value=choice_value,
|
||||
sub_widgets=sub_ul_renderer.render()))
|
||||
output.append(format_html(
|
||||
self.inner_html, choice_value=choice_value,
|
||||
sub_widgets=sub_ul_renderer.render(),
|
||||
))
|
||||
else:
|
||||
w = self.choice_input_class(self.name, self.value,
|
||||
self.attrs.copy(), choice, i)
|
||||
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="{}"', id_) if id_ else '',
|
||||
content=mark_safe('\n'.join(output)))
|
||||
w = self.choice_input_class(self.name, self.value, self.attrs.copy(), choice, i)
|
||||
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="{}"', id_) if id_ else '',
|
||||
content=mark_safe('\n'.join(output)),
|
||||
)
|
||||
|
||||
|
||||
class RadioFieldRenderer(ChoiceFieldRenderer):
|
||||
@@ -889,8 +888,10 @@ class SplitDateTimeWidget(MultiWidget):
|
||||
supports_microseconds = False
|
||||
|
||||
def __init__(self, attrs=None, date_format=None, time_format=None):
|
||||
widgets = (DateInput(attrs=attrs, format=date_format),
|
||||
TimeInput(attrs=attrs, format=time_format))
|
||||
widgets = (
|
||||
DateInput(attrs=attrs, format=date_format),
|
||||
TimeInput(attrs=attrs, format=time_format),
|
||||
)
|
||||
super(SplitDateTimeWidget, self).__init__(widgets, attrs)
|
||||
|
||||
def decompress(self, value):
|
||||
|
||||
Reference in New Issue
Block a user