diff --git a/django_object_actions/__init__.py b/django_object_actions/__init__.py index 3508dd0..8566c9e 100644 --- a/django_object_actions/__init__.py +++ b/django_object_actions/__init__.py @@ -7,14 +7,13 @@ from .utils import ( BaseDjangoObjectActions, DjangoObjectActions, - takes_instance_or_queryset, action, + takes_instance_or_queryset, ) - __all__ = [ "BaseDjangoObjectActions", "DjangoObjectActions", - "takes_instance_or_queryset", "action", + "takes_instance_or_queryset", ] diff --git a/django_object_actions/tests/test_admin.py b/django_object_actions/tests/test_admin.py index 698b401..9c7838d 100644 --- a/django_object_actions/tests/test_admin.py +++ b/django_object_actions/tests/test_admin.py @@ -2,18 +2,20 @@ Integration tests that actually try and use the tools setup in admin.py """ +from unittest.mock import patch + from django.contrib.admin.utils import quote from django.http import HttpResponse from django.urls import reverse -from unittest.mock import patch -from .tests import LoggedInTestCase from example_project.polls.factories import ( CommentFactory, PollFactory, RelatedDataFactory, ) +from .tests import LoggedInTestCase + class CommentTests(LoggedInTestCase): def test_action_on_a_model_with_uuid_pk_works(self): diff --git a/django_object_actions/tests/test_utils.py b/django_object_actions/tests/test_utils.py index 6cd0fc4..0df3969 100644 --- a/django_object_actions/tests/test_utils.py +++ b/django_object_actions/tests/test_utils.py @@ -1,13 +1,14 @@ from unittest import mock from django.test import TestCase + from example_project.polls.models import Poll from ..utils import ( - BaseDjangoObjectActions, BaseActionView, - takes_instance_or_queryset, + BaseDjangoObjectActions, action, + takes_instance_or_queryset, ) diff --git a/django_object_actions/tests/tests.py b/django_object_actions/tests/tests.py index ac457f9..1b8c575 100644 --- a/django_object_actions/tests/tests.py +++ b/django_object_actions/tests/tests.py @@ -1,5 +1,5 @@ -from django.urls import reverse from django.test import TestCase +from django.urls import reverse from example_project.polls.factories import UserFactory from example_project.polls.models import Choice diff --git a/django_object_actions/utils.py b/django_object_actions/utils.py index 765b704..280cdde 100644 --- a/django_object_actions/utils.py +++ b/django_object_actions/utils.py @@ -6,10 +6,10 @@ from django.db.models.query import QuerySet from django.http import Http404, HttpResponseRedirect from django.http.response import HttpResponseBase, HttpResponseNotAllowed +from django.urls import re_path, reverse from django.views.generic import View from django.views.generic.detail import SingleObjectMixin from django.views.generic.list import MultipleObjectMixin -from django.urls import re_path, reverse DEFAULT_METHODS_ALLOWED = ("GET", "POST") DEFAULT_BUTTON_TYPE = "a" @@ -245,8 +245,8 @@ def dispatch(self, request, tool, **kwargs): try: view = self.actions[tool] - except KeyError: - raise Http404("Action does not exist") + except KeyError as exc: + raise Http404("Action does not exist") from exc allowed_methods = getattr(view, "methods", DEFAULT_METHODS_ALLOWED) if request.method.upper() not in allowed_methods: @@ -363,5 +363,4 @@ def decorator(func): if function is None: return decorator - else: - return decorator(function) + return decorator(function) diff --git a/example_project/polls/admin.py b/example_project/polls/admin.py index 3d43a61..78de9ba 100644 --- a/example_project/polls/admin.py +++ b/example_project/polls/admin.py @@ -6,11 +6,11 @@ from django_object_actions import ( DjangoObjectActions, - takes_instance_or_queryset, action, + takes_instance_or_queryset, ) -from .models import Choice, Poll, Comment, RelatedData +from .models import Choice, Comment, Poll, RelatedData class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin): @@ -110,7 +110,7 @@ def delete_all_choices(self, request, obj): if request.method == "POST": obj.choice_set.all().delete() - return + return None self.message_user(request, "All choices deleted") return render(request, "clear_choices.html", {"object": obj}) diff --git a/example_project/polls/factories.py b/example_project/polls/factories.py index 05f24a4..16208df 100644 --- a/example_project/polls/factories.py +++ b/example_project/polls/factories.py @@ -43,8 +43,7 @@ class Meta: def get_random_string(length): letters = string.ascii_lowercase - result_str = "".join(random.choice(letters) for i in range(length)) - return result_str + return "".join(random.choice(letters) for i in range(length)) class RelatedDataFactory(factory.django.DjangoModelFactory): diff --git a/example_project/polls/migrations/0001_initial.py b/example_project/polls/migrations/0001_initial.py index 5d53eca..1ce4b9e 100644 --- a/example_project/polls/migrations/0001_initial.py +++ b/example_project/polls/migrations/0001_initial.py @@ -1,7 +1,7 @@ # Generated by Django 1.9.2 on 2016-02-25 17:25 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/example_project/polls/migrations/0002_auto_20200805_0239.py b/example_project/polls/migrations/0002_auto_20200805_0239.py index 599d26d..583ef75 100644 --- a/example_project/polls/migrations/0002_auto_20200805_0239.py +++ b/example_project/polls/migrations/0002_auto_20200805_0239.py @@ -1,8 +1,9 @@ # Generated by Django 3.1 on 2020-08-05 02:39 -from django.db import migrations, models import uuid +from django.db import migrations, models + class Migration(migrations.Migration): dependencies = [ diff --git a/example_project/urls.py b/example_project/urls.py index 47b4296..9500210 100644 --- a/example_project/urls.py +++ b/example_project/urls.py @@ -1,7 +1,7 @@ -from django.urls import path from django.contrib import admin -from example_project.polls.admin import support_admin +from django.urls import path +from example_project.polls.admin import support_admin urlpatterns = [ path("admin/", admin.site.urls), diff --git a/pyproject.toml b/pyproject.toml index 7100717..2e58532 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,4 +67,14 @@ exclude_lines = [ [tool.ruff] [tool.ruff.lint] -extend-select = ["UP"] +extend-select = [ + "A", # flake8-builtins + "B", # flake8-bugbear + "G", # flake8-logging-format + "I", # isort + "N", # pep8-naming + "RET", # flakes8-return + "RUF", # Ruff-specific rules + "UP", # pyupgrade +] +ignore = ["RUF012"]