Skip to content

Commit f52099f

Browse files
committed
refactor: move defaults to a const
1 parent 6c6e6f0 commit f52099f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

django_object_actions/tests/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def test_can_return_template(self):
4646
# it's good to document that this is something we can do.
4747
url = reverse("admin:polls_poll_actions", args=(1, "delete_all_choices"))
4848
response = self.client.get(url)
49-
print(url, response)
5049
self.assertTemplateUsed(response, "clear_choices.html")
5150

5251
def test_message_user_sends_message(self):

django_object_actions/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from django.views.generic.list import MultipleObjectMixin
1212
from django.urls import re_path, reverse
1313

14+
DEFAULT_METHODS_ALLOWED = ("GET", "POST")
15+
DEFAULT_BUTTON_TYPE = "a"
16+
1417

1518
class BaseDjangoObjectActions(object):
1619
"""
@@ -159,7 +162,7 @@ def _get_tool_dict(self, tool_name):
159162
label=getattr(tool, "label", tool_name.replace("_", " ").capitalize()),
160163
standard_attrs=standard_attrs,
161164
custom_attrs=custom_attrs,
162-
button_type=getattr(tool, "button_type", "a"),
165+
button_type=getattr(tool, "button_type", DEFAULT_BUTTON_TYPE),
163166
)
164167

165168
def _get_button_attrs(self, tool):
@@ -249,9 +252,7 @@ def dispatch(self, request, tool, **kwargs):
249252
except KeyError:
250253
raise Http404("Action does not exist")
251254

252-
# TODO move ('get', 'post' config default someplace else)
253-
allowed_methods = getattr(view, "methods", ("GET", "POST"))
254-
print("dispatch", request.method, allowed_methods)
255+
allowed_methods = getattr(view, "methods", DEFAULT_METHODS_ALLOWED)
255256
if request.method.upper() not in allowed_methods:
256257
return HttpResponseNotAllowed(allowed_methods)
257258

@@ -324,8 +325,8 @@ def action(
324325
description=None,
325326
label=None,
326327
attrs=None,
327-
methods=("GET", "POST"),
328-
button_type="a",
328+
methods=DEFAULT_METHODS_ALLOWED,
329+
button_type=DEFAULT_BUTTON_TYPE,
329330
):
330331
"""
331332
Conveniently add attributes to an action function:

0 commit comments

Comments
 (0)