TrangPham / django-admin-confirm

AdminConfirmMixin is a mixin for ModelAdmin that adds confirmations to changes, additions and actions.
Other
129 stars 16 forks source link

Feature: Confirm Chagelist Actions #1

Closed TrangPham closed 3 years ago

TrangPham commented 3 years ago

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.

TrangPham commented 3 years ago

There is a design choice here and some tradeoffs.

Option 1:

Pros:

Cons:

Option 2:

Option 3:

Option 3 seems to have the best of both worlds, so this is what we're going with.

TrangPham commented 3 years ago

Implemented :)

TrangPham commented 3 years ago

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?

TrangPham commented 3 years ago

🤷 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