Adds confirmation to Django Admin changes, additions and actions
Reason this release was yanked:
This version contains numerous bugs and should not be utilized. Please consider using 0.2.3 or newer versions
Project description
Django Admin Confirm
AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions.
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 confirmationconfirm_add
Optional[bool] - decides if additions should trigger confirmationconfirmation_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/addaction_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
Local Development Setup
Install pyenv Install python 3.8
Create virtualenv via pyenv
pyenv vituralenv 3.8 django-admin-confirm-3.8
Now your terminal should have (django-admin-confirm-3.8)
prefix, because .python-version
should have auto switch your virtual env
Run migrations and create a superuser and run the server
./tests/manage.py migrate
./tests/manage.py createsuperuser
./tests/manage.py runserver
You should be able to see the test app at localhost:8000/admin
Running tests:
make test
tox
Testing new changes on test project:
pip install -e .
make run
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file django_admin_confirm-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: django_admin_confirm-0.2.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eebc9e2b01fc93001cba0dc9a10abf1d5433332d267981e1be2d62720f1fd684 |
|
MD5 | fdd25ceccd92cff468f5a980ce49c8d9 |
|
BLAKE2b-256 | 5f4d227ab10cca14f4762ab53e6ac7dedb773a442cf92d65a6d852b2e1682650 |