Go to file
Thu Trang Pham ea1e882f32 Version 0.2 2020-11-30 09:18:15 -08:00
.vscode Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
admin_confirm Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
tests Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
.gitignore All tests work 2020-11-07 13:21:24 -08:00
LICENSE Updating for packaging 2020-11-08 11:24:59 -08:00
MANIFEST.in Messy but working save confirmation on change page 2020-10-31 16:29:46 -07:00
Makefile Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
README.md Move the screenshot back so pypi can see it and use commit specific links for screenshots from now on 2020-11-30 09:12:10 -08:00
coverage.svg Formatted with black and reached 100% coverage 2020-11-08 09:51:49 -08:00
pytest.ini Refactored and added pytest.ini file 2020-11-01 07:30:51 -08:00
requirements.txt Got some tests working 2020-11-02 09:58:41 -08:00
screenshot.png Move the screenshot back so pypi can see it and use commit specific links for screenshots from now on 2020-11-30 09:12:10 -08:00
screenshot_confirm_action.png Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
screenshot_confirm_action_no_perm.png Feat/confirm actions (#2) 2020-11-29 13:31:27 -08:00
setup.py Version 0.2 2020-11-30 09:18:15 -08:00
tox.ini Adding tox 2020-11-08 10:58:21 -08:00

README.md

Django Admin Confirm

coverage

AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions.

Screenshot of Change Confirmation Page

Screenshot of Action Confirmation Page

It can be configured to add a confirmation page on ModelAdmin upon:

  • saving changes
  • adding new instances
  • performing actions

Typical Usage:

    from admin_confirm import AdminConfirmMixin

    class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
        confirm_change = True
        confirmation_fields = ['field1', 'field2']

Installation

Install django-admin-confirm by running:

pip install django-admin-confirm

Add to INSTALLED_APPS in your project settings before django.contrib.admin:

INSTALLED_APPS = [
    ...
    'admin_confirm',

    'django.contrib.admin',
    ...
]

Note that this project follows the template override rules of Django. To override a template, your app should be listed before admin_confirm in INSTALLED_APPS.

Configuration Options

Attributes:

  • confirm_change Optional[bool] - decides if changes should trigger confirmation
  • confirm_add Optional[bool] - decides if additions should trigger confirmation
  • confirmation_fields Optional[Array[string]] - sets which fields should trigger confirmation for add/change. For adding new instances, the field would only trigger a confirmation if it's set to a value that's not its default.
  • change_confirmation_template Optional[string] - path to custom html template to use for change/add
  • action_confirmation_template Optional[string] - path to custom html template to use for actions

Note that setting confirmation_fields without setting confirm_change or confirm_add would not trigger confirmation for change/add. Confirmations for actions does not use the confirmation_fields option.

Method Overrides: If you want even more control over the confirmation, these methods can be overridden:

  • get_confirmation_fields(self, request: HttpRequest, obj: Optional[Object]) -> List[str]
  • render_change_confirmation(self, request: HttpRequest, context: dict) -> TemplateResponse
  • render_action_confirmation(self, request: HttpRequest, context: dict) -> TemplateResponse

Usage

Confirm Change:

    from admin_confirm import AdminConfirmMixin

    class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
        confirm_change = True
        confirmation_fields = ['field1', 'field2']

This would confirm changes on changes that include modifications onfield1 and/or field2.

Confirm Add:

    from admin_confirm import AdminConfirmMixin

    class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
        confirm_add = True
        confirmation_fields = ['field1', 'field2']

This would confirm add on adds that set field1 and/or field2 to a non default value.

Note: confirmation_fields apply to both add/change confirmations.

Confirm Action:

    from admin_confirm import AdminConfirmMixin

    class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
        actions = ["action1", "action2"]

        def action1(modeladmin, request, queryset):
            # Do something with the queryset

        @confirm_action
        def action2(modeladmin, request, queryset):
            # Do something with the queryset

        action2.allowed_permissions = ('change',)

This would confirm action2 but not action1.

Action confirmation will respect allowed_permissions and the has_xxx_permission methods.

Contribution & Appreciation

Contributions are most welcome :) Feel free to:

  • address an issue
  • raise an issue
  • add more test cases
  • add feature requests

Your appreciation is also very welcome :) Feel free to:

  • star the project
  • open an issue just to share your thanks

Feature List

This is a list of features which could potentially be added in the future. Some of which might make more sense in their own package.

  • confirmations on changelist actions
  • global actions on changelist page
  • instance actions on change/view page
  • action logs (adding actions to history of instances)
  • add help tooltip/popover to any field for more info
  • add help tooltop/popover/help button to admin actions on changelist
  • run scripts from admin
  • completed action summary page
  • add top and bottom areas to instance pages which can be configured for any content

Support

If you are having issues, please let us know through raising an issue.

License

The project is licensed under the Apache 2.0 license.