Skip to content

Commit

Permalink
Fixed E128 flake8 warnings in django/.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Apr 8, 2016
1 parent 2956e2f commit df8d8d4
Show file tree
Hide file tree
Showing 136 changed files with 1,642 additions and 1,213 deletions.
6 changes: 4 additions & 2 deletions django/apps/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,10 @@ def set_available_apps(self, available):
available = set(available)
installed = set(app_config.name for app_config in self.get_app_configs())
if not available.issubset(installed):
raise ValueError("Available apps isn't a subset of installed "
"apps, extra apps: %s" % ", ".join(available - installed))
raise ValueError(
"Available apps isn't a subset of installed apps, extra apps: %s"
% ", ".join(available - installed)
)

self.stored_app_configs.append(self.app_configs)
self.app_configs = OrderedDict(
Expand Down
3 changes: 1 addition & 2 deletions django/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def __init__(self, settings_module):

if (setting in tuple_settings and
not isinstance(setting_value, (list, tuple))):
raise ImproperlyConfigured("The %s setting must be a list or a tuple. "
"Please fix your settings." % setting)
raise ImproperlyConfigured("The %s setting must be a list or a tuple. " % setting)
setattr(self, setting, setting_value)
self._explicit_settings.add(setting)

Expand Down
18 changes: 10 additions & 8 deletions django/contrib/admin/bin/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def main():
Compiler library and Java version 6 or later."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('file', nargs='*')
parser.add_argument("-c", dest="compiler", default="~/bin/compiler.jar",
help="path to Closure Compiler jar file")
parser.add_argument("-v", "--verbose",
action="store_true", dest="verbose")
parser.add_argument("-q", "--quiet",
action="store_false", dest="verbose")
parser.add_argument(
"-c", dest="compiler", default="~/bin/compiler.jar",
help="path to Closure Compiler jar file",
)
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose")
parser.add_argument("-q", "--quiet", action="store_false", dest="verbose")
options = parser.parse_args()

compiler = closure_compiler if closure_compiler else os.path.expanduser(options.compiler)
Expand All @@ -38,8 +38,10 @@ def main():
if not options.file:
if options.verbose:
sys.stdout.write("No filenames given; defaulting to admin scripts\n")
files = [os.path.join(js_path, f) for f in [
"actions.js", "collapse.js", "inlines.js", "prepopulate.js"]]
files = [
os.path.join(js_path, f) for f in
["actions.js", "collapse.js", "inlines.js", "prepopulate.js"]
]
else:
files = options.file

Expand Down
24 changes: 12 additions & 12 deletions django/contrib/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def create(cls, field, request, params, model, model_admin, field_path):
for test, list_filter_class in cls._field_list_filters:
if not test(field):
continue
return list_filter_class(field, request, params,
model, model_admin, field_path=field_path)
return list_filter_class(field, request, params, model, model_admin, field_path=field_path)


class RelatedFieldListFilter(FieldListFilter):
Expand Down Expand Up @@ -200,8 +199,10 @@ def field_choices(self, field, request, model_admin):
def choices(self, changelist):
yield {
'selected': self.lookup_val is None and not self.lookup_val_isnull,
'query_string': changelist.get_query_string({},
[self.lookup_kwarg, self.lookup_kwarg_isnull]),
'query_string': changelist.get_query_string(
{},
[self.lookup_kwarg, self.lookup_kwarg_isnull]
),
'display': _('All'),
}
for pk_val, val in self.lookup_choices:
Expand Down Expand Up @@ -230,8 +231,7 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg2 = '%s__isnull' % field_path
self.lookup_val = request.GET.get(self.lookup_kwarg)
self.lookup_val2 = request.GET.get(self.lookup_kwarg2)
super(BooleanFieldListFilter, self).__init__(field,
request, params, model, model_admin, field_path)
super(BooleanFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path)

def expected_parameters(self):
return [self.lookup_kwarg, self.lookup_kwarg2]
Expand All @@ -257,8 +257,10 @@ def choices(self, changelist):
'display': _('Unknown'),
}

FieldListFilter.register(lambda f: isinstance(f,
(models.BooleanField, models.NullBooleanField)), BooleanFieldListFilter)
FieldListFilter.register(
lambda f: isinstance(f, (models.BooleanField, models.NullBooleanField)),
BooleanFieldListFilter
)


class ChoicesFieldListFilter(FieldListFilter):
Expand Down Expand Up @@ -290,8 +292,7 @@ def choices(self, changelist):
class DateFieldListFilter(FieldListFilter):
def __init__(self, field, request, params, model, model_admin, field_path):
self.field_generic = '%s__' % field_path
self.date_params = {k: v for k, v in params.items()
if k.startswith(self.field_generic)}
self.date_params = {k: v for k, v in params.items() if k.startswith(self.field_generic)}

now = timezone.now()
# When time zone support is enabled, convert "now" to the user's time
Expand Down Expand Up @@ -387,8 +388,7 @@ def expected_parameters(self):
def choices(self, changelist):
yield {
'selected': self.lookup_val is None and self.lookup_val_isnull is None,
'query_string': changelist.get_query_string({},
[self.lookup_kwarg, self.lookup_kwarg_isnull]),
'query_string': changelist.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]),
'display': _('All'),
}
include_none = False
Expand Down
7 changes: 4 additions & 3 deletions django/contrib/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class AdminAuthenticationForm(AuthenticationForm):
A custom authentication form used in the admin app.
"""
error_messages = {
'invalid_login': _("Please enter the correct %(username)s and password "
"for a staff account. Note that both fields may be "
"case-sensitive."),
'invalid_login': _(
"Please enter the correct %(username)s and password for a staff "
"account. Note that both fields may be case-sensitive."
),
}
required_css_class = 'required'

Expand Down
80 changes: 46 additions & 34 deletions django/contrib/admin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

class ActionForm(forms.Form):
action = forms.ChoiceField(label=_('Action:'))
select_across = forms.BooleanField(label='', required=False, initial=0,
widget=forms.HiddenInput({'class': 'select-across'}))
select_across = forms.BooleanField(
label='',
required=False,
initial=0,
widget=forms.HiddenInput({'class': 'select-across'}),
)

checkbox = forms.CheckboxInput({'class': 'action-select'}, lambda value: False)

Expand Down Expand Up @@ -62,7 +66,7 @@ def _media(self):

class Fieldset(object):
def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
description=None, model_admin=None):
description=None, model_admin=None):
self.form = form
self.name, self.fields = name, fields
self.classes = ' '.join(classes)
Expand All @@ -73,9 +77,11 @@ def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
def _media(self):
if 'collapse' in self.classes:
extra = '' if settings.DEBUG else '.min'
js = ['vendor/jquery/jquery%s.js' % extra,
'jquery.init.js',
'collapse%s.js' % extra]
js = [
'vendor/jquery/jquery%s.js' % extra,
'jquery.init.js',
'collapse%s.js' % extra,
]
return forms.Media(js=['admin/js/%s' % url for url in js])
return forms.Media()
media = property(_media)
Expand All @@ -92,9 +98,10 @@ def __init__(self, form, field, readonly_fields=None, model_admin=None):
self.fields = [field]
else:
self.fields = field
self.has_visible_field = not all(field in self.form.fields and
self.form.fields[field].widget.is_hidden
for field in self.fields)
self.has_visible_field = not all(
field in self.form.fields and self.form.fields[field].widget.is_hidden
for field in self.fields
)
self.model_admin = model_admin
if readonly_fields is None:
readonly_fields = ()
Expand All @@ -103,15 +110,15 @@ def __init__(self, form, field, readonly_fields=None, model_admin=None):
def __iter__(self):
for i, field in enumerate(self.fields):
if field in self.readonly_fields:
yield AdminReadonlyField(self.form, field, is_first=(i == 0),
model_admin=self.model_admin)
yield AdminReadonlyField(self.form, field, is_first=(i == 0), model_admin=self.model_admin)
else:
yield AdminField(self.form, field, is_first=(i == 0))

def errors(self):
return mark_safe(
'\n'.join(self.form[f].errors.as_ul()
for f in self.fields if f not in self.readonly_fields).strip('\n')
'\n'.join(
self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields
).strip('\n')
)


Expand All @@ -135,8 +142,10 @@ def label_tag(self):
attrs = {'class': ' '.join(classes)} if classes else {}
# checkboxes should not have a label suffix as the checkbox appears
# to the left of the label.
return self.field.label_tag(contents=mark_safe(contents), attrs=attrs,
label_suffix='' if self.is_checkbox else None)
return self.field.label_tag(
contents=mark_safe(contents), attrs=attrs,
label_suffix='' if self.is_checkbox else None,
)

def errors(self):
return mark_safe(self.field.errors.as_ul())
Expand Down Expand Up @@ -225,7 +234,7 @@ class InlineAdminFormSet(object):
A wrapper around an inline formset for use in the admin system.
"""
def __init__(self, inline, formset, fieldsets, prepopulated_fields=None,
readonly_fields=None, model_admin=None):
readonly_fields=None, model_admin=None):
self.opts = inline
self.formset = formset
self.fieldsets = fieldsets
Expand All @@ -241,16 +250,21 @@ def __init__(self, inline, formset, fieldsets, prepopulated_fields=None,
def __iter__(self):
for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
view_on_site_url = self.opts.get_view_on_site_url(original)
yield InlineAdminForm(self.formset, form, self.fieldsets,
self.prepopulated_fields, original, self.readonly_fields,
model_admin=self.opts, view_on_site_url=view_on_site_url)
yield InlineAdminForm(
self.formset, form, self.fieldsets, self.prepopulated_fields,
original, self.readonly_fields, model_admin=self.opts,
view_on_site_url=view_on_site_url,
)
for form in self.formset.extra_forms:
yield InlineAdminForm(self.formset, form, self.fieldsets,
self.prepopulated_fields, None, self.readonly_fields,
model_admin=self.opts)
yield InlineAdminForm(self.formset, self.formset.empty_form,
yield InlineAdminForm(
self.formset, form, self.fieldsets, self.prepopulated_fields,
None, self.readonly_fields, model_admin=self.opts,
)
yield InlineAdminForm(
self.formset, self.formset.empty_form,
self.fieldsets, self.prepopulated_fields, None,
self.readonly_fields, model_admin=self.opts)
self.readonly_fields, model_admin=self.opts,
)

def fields(self):
fk = getattr(self.formset, "fk", None)
Expand All @@ -260,9 +274,7 @@ def fields(self):
if field_name in self.readonly_fields:
yield {
'label': label_for_field(field_name, self.opts.model, self.opts),
'widget': {
'is_hidden': False
},
'widget': {'is_hidden': False},
'required': False,
'help_text': help_text_for_field(field_name, self.opts.model),
}
Expand Down Expand Up @@ -304,19 +316,20 @@ class InlineAdminForm(AdminForm):
A wrapper around an inline form for use in the admin system.
"""
def __init__(self, formset, form, fieldsets, prepopulated_fields, original,
readonly_fields=None, model_admin=None, view_on_site_url=None):
readonly_fields=None, model_admin=None, view_on_site_url=None):
self.formset = formset
self.model_admin = model_admin
self.original = original
self.show_url = original and view_on_site_url is not None
self.absolute_url = view_on_site_url
super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields,
readonly_fields, model_admin)
super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields, readonly_fields, model_admin)

def __iter__(self):
for name, options in self.fieldsets:
yield InlineFieldset(self.formset, self.form, name,
self.readonly_fields, model_admin=self.model_admin, **options)
yield InlineFieldset(
self.formset, self.form, name, self.readonly_fields,
model_admin=self.model_admin, **options
)

def needs_explicit_pk_field(self):
# Auto fields are editable (oddly), so need to check for auto or non-editable pk
Expand Down Expand Up @@ -358,8 +371,7 @@ def __iter__(self):
for field in self.fields:
if fk and fk.name == field:
continue
yield Fieldline(self.form, field, self.readonly_fields,
model_admin=self.model_admin)
yield Fieldline(self.form, field, self.readonly_fields, model_admin=self.model_admin)


class AdminErrorList(forms.utils.ErrorList):
Expand Down
Loading

0 comments on commit df8d8d4

Please sign in to comment.