Skip to content

Commit

Permalink
refactor: move defaults to a const
Browse files Browse the repository at this point in the history
  • Loading branch information
crccheck committed Sep 9, 2024
1 parent 6c6e6f0 commit 04e96a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion django_object_actions/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 04e96a5

Please sign in to comment.