Closed TrangPham closed 3 years ago
There is a design choice here and some tradeoffs.
Option 1:
confirm_action
option to an admin
confirmation_actions
option to list which actions should be confirmedresponse_action
on the ModelAdminGo
button actually call the response_action
with a parameter indicating that confirmation is required
confirm_action
option when first pressed and then after the confirmation template will call the ActionForm again without the confirm_action
. This would be similar to how the confirm_add/confirm_change overrides changeform_view
Pros:
Cons:
Option 2:
@confirm_action
Option 3:
confirm_action
and confirmation_actions
? And then we can be flexible in the way the end-user can configure the confirmation for actions?
Option 3 seems to have the best of both worlds, so this is what we're going with.
Implemented :)
Actually I will leave this open since I actually have not implemented option#3. I only added the @confirm_action
wrapper and it's working now.
Task: https://github.com/TrangPham/django-admin-confirm/projects/1#card-50139999
The new config options would be:
Which would match the other config options... which is nice.
I'm not actually sure if I should add the other options. Is that nice and simple or is that just way too many different ways to configure confirm_action
?
🤷 I keep going back and forth on this. I think I will consider this done now. I don't think anyone but me cares :P Maybe I'm just being nitpicky on myself
Here's some basic research:
Beware of: https://docs.djangoproject.com/en/3.1/ref/contrib/admin/actions/#actions-that-provide-intermediate-pages
ActionForm
https://github.com/django/django/blob/b79088306513d5ed76d31ac40ab3c15f858946ea/django/contrib/admin/helpers.py#L22
Built in Delete action has a confirmation page: https://github.com/django/django/blob/master/django/contrib/admin/actions.py https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/delete_selected_confirmation.html
This is the code that actually runs the action: https://github.com/django/django/blob/aade2b461acafd16cfc82449b3df88a0f1c1c197/django/contrib/admin/options.py#L1354
So you'll want to surround that and then call the action. This won't work well if the end-user is already returning a custom form.