crccheck / django-object-actions

A Django app for easily adding object tools in the Django admin
https://pypi.org/project/django-object-actions/
Apache License 2.0
669 stars 82 forks source link

wip to select GET or POST for actions #168

Closed SupraSummus closed 1 week ago

SupraSummus commented 6 months ago

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.

crccheck commented 1 week ago

I'll merge this as a broken commit so you get attribution, but I'll work on the next commit to fix CI. I'd like to remove button_type (or make it a secret option) so users will only need to pick the method GET or POST. Since we need to support GET and POST for backwards compatibility, your way is good

SupraSummus commented 6 days ago

@crccheck thanks a lot!