-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip to select GET or POST for actions (#168)
Another try at enforcing POST actions. This change is more gradual than #149 - when library user doesn't change default options the behavior is exactly the same as before the change, that is: 1. Action buttons send GET requests 2. Action handlers accept GET and POST requests However, user can change this behavior using `methods` and `button_type` kwargs. For example `@action(methods=['POST'], button_type='form')` results in 1. Action button sends POST requests 2. Action handler accepts only POST request Unfortunately I have this tested only within my project. Also the docs are missing. And one more thing - I think it is better to use `<input type="submit">` instead of js to submit the form. This js is need to make the buttons look the same in both versions. With proper CSS (that is beyond my ability to write ;) ) js is avoidable and we could be using pretty semantic html submit button. I took the form button template from #149.
- Loading branch information
1 parent
813687e
commit 1274ae7
Showing
4 changed files
with
35 additions
and
22 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
django_object_actions/templates/django_object_actions/action_trigger.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% 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' %} | ||
<form method="post" action="{% add_preserved_filters action_url %}"> | ||
{% csrf_token %} | ||
<a href="#" onclick="this.parentNode.submit(); return false;" | ||
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> | ||
</form> | ||
{% endif %} |
9 changes: 1 addition & 8 deletions
9
django_object_actions/templates/django_object_actions/change_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
django_object_actions/templates/django_object_actions/change_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters