From 04e96a5536e746c57fcf26f55526be5262cd8562 Mon Sep 17 00:00:00 2001 From: crccheck Date: Mon, 9 Sep 2024 05:58:04 +0000 Subject: [PATCH] refactor: move defaults to a const --- django_object_actions/tests/tests.py | 1 - django_object_actions/utils.py | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django_object_actions/tests/tests.py b/django_object_actions/tests/tests.py index e78fa4b..bee08b3 100644 --- a/django_object_actions/tests/tests.py +++ b/django_object_actions/tests/tests.py @@ -46,7 +46,6 @@ def test_can_return_template(self): # it's good to document that this is something we can do. url = reverse("admin:polls_poll_actions", args=(1, "delete_all_choices")) response = self.client.get(url) - print(url, response) self.assertTemplateUsed(response, "clear_choices.html") def test_message_user_sends_message(self): diff --git a/django_object_actions/utils.py b/django_object_actions/utils.py index 99afb40..4cd7d96 100644 --- a/django_object_actions/utils.py +++ b/django_object_actions/utils.py @@ -11,6 +11,9 @@ from django.views.generic.list import MultipleObjectMixin from django.urls import re_path, reverse +DEFAULT_METHODS_ALLOWED = ("GET", "POST") +DEFAULT_BUTTON_TYPE = "a" + class BaseDjangoObjectActions(object): """ @@ -250,8 +253,7 @@ def dispatch(self, request, tool, **kwargs): raise Http404("Action does not exist") # TODO move ('get', 'post' config default someplace else) - allowed_methods = getattr(view, "methods", ("GET", "POST")) - print("dispatch", request.method, allowed_methods) + allowed_methods = getattr(view, "methods", DEFAULT_METHODS_ALLOWED) if request.method.upper() not in allowed_methods: return HttpResponseNotAllowed(allowed_methods) @@ -324,8 +326,8 @@ def action( description=None, label=None, attrs=None, - methods=("GET", "POST"), - button_type="a", + methods=DEFAULT_METHODS_ALLOWED, + button_type=DEFAULT_BUTTON_TYPE, ): """ Conveniently add attributes to an action function: