From f3ff443373bacaa1dc9f1f19521b207fe781298c Mon Sep 17 00:00:00 2001 From: arthur Date: Sat, 7 May 2016 22:59:15 +0200 Subject: [PATCH] Fix flake8 errors --- .eggs/README.txt | 6 ++++++ djadmin2/__init__.py | 6 ++---- djadmin2/actions.py | 1 - djadmin2/core.py | 1 - djadmin2/filters.py | 6 +++--- djadmin2/forms.py | 17 ++++++++++------- djadmin2/permissions.py | 5 ++--- djadmin2/tests/test_actions.py | 14 +++++++------- djadmin2/tests/test_admin2tags.py | 2 +- djadmin2/tests/test_renderers.py | 2 +- djadmin2/tests/test_types.py | 1 - djadmin2/tests/test_utils.py | 6 ++---- djadmin2/tests/test_views.py | 1 - djadmin2/utils.py | 10 ++++------ djadmin2/views.py | 4 +++- 15 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 .eggs/README.txt diff --git a/.eggs/README.txt b/.eggs/README.txt new file mode 100644 index 0000000..5d01668 --- /dev/null +++ b/.eggs/README.txt @@ -0,0 +1,6 @@ +This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. + +This directory caches those eggs to prevent repeated downloads. + +However, it is safe to delete this directory. + diff --git a/djadmin2/__init__.py b/djadmin2/__init__.py index d7ea63c..dfc150f 100644 --- a/djadmin2/__init__.py +++ b/djadmin2/__init__.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import division, absolute_import, unicode_literals +from . import core +from . import types __version__ = '0.6.1' @@ -10,10 +12,6 @@ VERSION = __version__ # synonym # Default datetime input and output formats ISO_8601 = 'iso-8601' -from . import core -from . import types - - default = core.Admin2() ModelAdmin2 = types.ModelAdmin2 Admin2TabularInline = types.Admin2TabularInline diff --git a/djadmin2/actions.py b/djadmin2/actions.py index fc90bd7..ffab8a4 100644 --- a/djadmin2/actions.py +++ b/djadmin2/actions.py @@ -169,7 +169,6 @@ class DeleteSelectedAction(BaseListAction): # objects, so render a template asking for their confirmation. return self.get(request) - def process_queryset(self): # The user has confirmed that they want to delete the objects. self.get_queryset().delete() diff --git a/djadmin2/core.py b/djadmin2/core.py index fcd8e3d..105671a 100644 --- a/djadmin2/core.py +++ b/djadmin2/core.py @@ -208,4 +208,3 @@ class Admin2(object): def urls(self): # We set the application and instance namespace here return self.get_urls(), self.name, self.name - diff --git a/djadmin2/filters.py b/djadmin2/filters.py index fe275c0..a2c894f 100644 --- a/djadmin2/filters.py +++ b/djadmin2/filters.py @@ -6,9 +6,9 @@ import collections from itertools import chain from django import forms -from django.forms.util import flatatt +from django.forms.utils import flatatt from django.utils.html import format_html -from django.utils.encoding import force_text, force_bytes +from django.utils.encoding import force_text from django.utils.safestring import mark_safe from django.forms import widgets as django_widgets from django.utils import six @@ -97,7 +97,7 @@ def build_list_filter(request, model_admin, queryset): 'fields': fields, }, ) - return type(type_str('%sFilterSet' % queryset.model.__name__),(django_filters.FilterSet, ),filterset_dict,)(request.GET, queryset=queryset) + return type(type_str('%sFilterSet' % queryset.model.__name__), (django_filters.FilterSet, ), filterset_dict,)(request.GET, queryset=queryset) def build_date_filter(request, model_admin, queryset, field_name="published_date"): diff --git a/djadmin2/forms.py b/djadmin2/forms.py index 7721f97..7688cd2 100644 --- a/djadmin2/forms.py +++ b/djadmin2/forms.py @@ -166,9 +166,7 @@ _django_to_floppyforms_widget = { django.forms.extras.widgets.SelectDateWidget: _create_widget( floppyforms.widgets.SelectDateWidget, - init_arguments= - ('years',) - if django.VERSION >= (1, 7) else ('years', 'required')), + init_arguments=('years',) if django.VERSION >= (1, 7) else ('years', 'required')), } _django_field_to_floppyform_widget = { @@ -272,8 +270,10 @@ def modelform_factory(model, form=django.forms.models.ModelForm, fields=None, # Translators : %(username)s will be replaced by the username_field name # (default : username, but could be email, or something else) -ERROR_MESSAGE = ugettext_lazy("Please enter the correct %(username)s and password " - "for a staff account. Note that both fields may be case-sensitive.") +ERROR_MESSAGE = ugettext_lazy( + "Please enter the correct %(username)s and password " + "for a staff account. Note that both fields may be case-sensitive." +) class AdminAuthenticationForm(AuthenticationForm): @@ -285,8 +285,11 @@ class AdminAuthenticationForm(AuthenticationForm): error_messages = { 'required': ugettext_lazy("Please log in again, because your session has expired."), } - this_is_the_login_form = django.forms.BooleanField(widget=floppyforms.HiddenInput, - initial=1, error_messages=error_messages) + this_is_the_login_form = django.forms.BooleanField( + widget=floppyforms.HiddenInput, + initial=1, + error_messages=error_messages + ) def clean(self): username = self.cleaned_data.get('username') diff --git a/djadmin2/permissions.py b/djadmin2/permissions.py index 08acbd2..665e248 100644 --- a/djadmin2/permissions.py +++ b/djadmin2/permissions.py @@ -82,13 +82,13 @@ def model_permission(permission): assert model_class, ( 'Cannot apply model permissions on a view that does not ' 'have a `.model` or `.queryset` property.') - + try: # django 1.8+ model_name = model_class._meta.model_name except AttributeError: model_name = model_class._meta.module_name - + permission_name = permission.format( app_label=model_class._meta.app_label, model_name=model_name) @@ -363,7 +363,6 @@ class TemplatePermissionChecker(object): else: return self._view.has_permission(self._obj) - def __str__(self): if self._view is None: return '' diff --git a/djadmin2/tests/test_actions.py b/djadmin2/tests/test_actions.py index ff11118..f4bd6c4 100644 --- a/djadmin2/tests/test_actions.py +++ b/djadmin2/tests/test_actions.py @@ -26,24 +26,24 @@ class ActionTest(TestCase): self.admin2.registry[Thing].list_actions.extend([ TestAction, test_function, - ]) + ]) self.assertEquals( get_description( self.admin2.registry[Thing].list_actions[0] - ), + ), 'Delete selected items' - ) + ) self.assertEquals( get_description( self.admin2.registry[Thing].list_actions[1] - ), + ), 'Test Action Class' - ) + ) self.assertEquals( get_description( self.admin2.registry[Thing].list_actions[2] - ), + ), 'Test function' - ) + ) self.admin2.registry[Thing].list_actions.remove(TestAction) self.admin2.registry[Thing].list_actions.remove(test_function) diff --git a/djadmin2/tests/test_admin2tags.py b/djadmin2/tests/test_admin2tags.py index 0d9bf5b..61c5042 100644 --- a/djadmin2/tests/test_admin2tags.py +++ b/djadmin2/tests/test_admin2tags.py @@ -89,7 +89,7 @@ class TagsTests(TestCase): self.assertEquals( admin2_tags.formset_visible_fieldlist(formset), [u'Visible 1', u'Visible 2'] - ) + ) def test_verbose_name_for(self): app_verbose_names = { diff --git a/djadmin2/tests/test_renderers.py b/djadmin2/tests/test_renderers.py index 76c3ef6..a2921e3 100644 --- a/djadmin2/tests/test_renderers.py +++ b/djadmin2/tests/test_renderers.py @@ -109,7 +109,7 @@ class NumberRendererTest(TestCase): self.assertEqual('42.5', out) def testEndlessFloat(self): - out = self.renderer(1.0/3, None) + out = self.renderer(1.0 / 3, None) if six.PY2: self.assertEqual('0.333333333333', out) else: diff --git a/djadmin2/tests/test_types.py b/djadmin2/tests/test_types.py index 088f083..ed0a92d 100644 --- a/djadmin2/tests/test_types.py +++ b/djadmin2/tests/test_types.py @@ -1,6 +1,5 @@ from django.db import models from django.test import TestCase -from django.views.generic import View from .. import views from ..types import ModelAdmin2, immutable_admin_factory diff --git a/djadmin2/tests/test_utils.py b/djadmin2/tests/test_utils.py index 6c69d3e..c53946d 100644 --- a/djadmin2/tests/test_utils.py +++ b/djadmin2/tests/test_utils.py @@ -40,7 +40,7 @@ class UtilsTest(TestCase): self.assertEquals( UtilsTestModel._meta, utils.model_options(UtilsTestModel) - ) + ) UtilsTestModel._meta.verbose_name = "Utils Test Model" UtilsTestModel._meta.verbose_name_plural = "Utils Test Models" @@ -55,7 +55,7 @@ class UtilsTest(TestCase): self.assertEquals( self.instance._meta, utils.model_options(self.instance) - ) + ) self.instance._meta.verbose_name = "Utils Test Model" self.instance._meta.verbose_name_plural = "Utils Test Models" @@ -166,8 +166,6 @@ class UtilsTest(TestCase): "str" ) - - def test_get_attr(self): class Klass(object): attr = "value" diff --git a/djadmin2/tests/test_views.py b/djadmin2/tests/test_views.py index 8609e71..1e25e76 100644 --- a/djadmin2/tests/test_views.py +++ b/djadmin2/tests/test_views.py @@ -1,5 +1,4 @@ from django.test import TestCase -from django.views.generic import View from .. import views diff --git a/djadmin2/utils.py b/djadmin2/utils.py index df7a91e..f59e29e 100644 --- a/djadmin2/utils.py +++ b/djadmin2/utils.py @@ -10,6 +10,7 @@ from django.db.models.fields.related import ForeignObjectRel from django.utils import six from django.utils.encoding import force_bytes, force_text + def lookup_needs_distinct(opts, lookup_path): """ Returns True if 'distinct()' should be used to query the given lookup path. @@ -91,10 +92,8 @@ def get_attr(obj, attr): and the __str__ attribute. """ if attr == '__str__': - if six.PY2: - value = unicode(obj) - else: - value = str(obj) + from builtins import str as text + value = text(obj) else: attribute = getattr(obj, attr) value = attribute() if callable(attribute) else attribute @@ -109,7 +108,6 @@ class NestedObjects(Collector): https://github.com/django/django/blob/1.8c1/django/contrib/admin/utils.py#L160-L221 """ - def __init__(self, *args, **kwargs): super(NestedObjects, self).__init__(*args, **kwargs) self.edges = {} # {from_instance: [to_instances]} @@ -199,4 +197,4 @@ def type_str(text): if six.PY2: return force_bytes(text) else: - return force_text(text) \ No newline at end of file + return force_text(text) diff --git a/djadmin2/views.py b/djadmin2/views.py index ccafd35..3f3867c 100644 --- a/djadmin2/views.py +++ b/djadmin2/views.py @@ -30,6 +30,7 @@ from .viewmixins import Admin2Mixin, AdminModel2Mixin, Admin2ModelFormMixin from .filters import build_list_filter, build_date_filter from .models import LogEntry + class AdminView(object): def __init__(self, url, view, name=None): @@ -462,7 +463,7 @@ class ModelDeleteView(AdminModel2Mixin, generic.DeleteView): opts = utils.model_options(obj) return '%s: %s' % (force_text(capfirst(opts.verbose_name)), force_text(obj)) - + using = router.db_for_write(self.get_object()._meta.model) collector = utils.NestedObjects(using=using) collector.collect([self.get_object()]) @@ -542,6 +543,7 @@ class PasswordChangeView(Admin2Mixin, generic.UpdateView): from django.contrib.auth import get_user_model return get_user_model()._default_manager.all() + class PasswordChangeDoneView(Admin2Mixin, generic.TemplateView): default_template_name = 'auth/password_change_done.html'