Skip to content

Commit

Permalink
fix adding defaults and access to new methods and button_type
Browse files Browse the repository at this point in the history
  • Loading branch information
crccheck committed Sep 9, 2024
1 parent c2bbcf3 commit 2e6c5fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{% load add_preserved_filters from admin_urls %}

{% if tool.button_type == 'a' %}
<a href="{% add_preserved_filters action_url %}"
title="{{ tool.standard_attrs.title }}"
{% for k, v in tool.custom_attrs.items %}
{{ k }}="{{ v }}"
{% endfor %}
class="{{ tool.standard_attrs.class }}"
>{{ tool.label|capfirst }}</a>
{% elif tool.button_type == 'form' %}
{% if tool.button_type == 'form' %}
<form method="post" action="{% add_preserved_filters action_url %}">
{% csrf_token %}
<a href="#" onclick="this.parentNode.submit(); return false;"
Expand All @@ -19,4 +11,12 @@
class="{{ tool.standard_attrs.class }}"
>{{ tool.label|capfirst }}</a>
</form>
{% else %}
<a href="{% add_preserved_filters action_url %}"
title="{{ tool.standard_attrs.title }}"
{% for k, v in tool.custom_attrs.items %}
{{ k }}="{{ v }}"
{% endfor %}
class="{{ tool.standard_attrs.class }}"
>{{ tool.label|capfirst }}</a>
{% endif %}
6 changes: 4 additions & 2 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from itertools import chain

from django.contrib import messages
from django.contrib.admin import ModelAdmin
from django.contrib.admin.utils import unquote
from django.db.models.query import QuerySet
from django.http import Http404, HttpResponseRedirect
Expand Down Expand Up @@ -159,7 +160,7 @@ def _get_tool_dict(self, tool_name):
label=getattr(tool, "label", tool_name.replace("_", " ").capitalize()),
standard_attrs=standard_attrs,
custom_attrs=custom_attrs,
button_type=tool.button_type,
button_type=getattr(tool, "button_type", "a"),
)

def _get_button_attrs(self, tool):
Expand Down Expand Up @@ -218,6 +219,7 @@ class BaseActionView(View):
model = None
actions = None
current_app = None
methods = ("GET", "POST")

@property
def view_args(self):
Expand Down Expand Up @@ -249,7 +251,7 @@ def dispatch(self, request, tool, **kwargs):
except KeyError:
raise Http404("Action does not exist")

if request.method not in view.methods:
if request.method not in self.methods:
return HttpResponseNotAllowed(view.methods)

ret = view(request, *self.view_args)
Expand Down

0 comments on commit 2e6c5fb

Please sign in to comment.