All tests work

main
Thu Trang Pham 2020-11-07 13:21:24 -08:00
parent c6a44f6426
commit b845e57285
4 changed files with 36 additions and 36 deletions

4
.gitignore vendored
View File

@ -6,7 +6,7 @@ dist/
sdist/ sdist/
.eggs/ .eggs/
*.egg-info/ *.egg-info/
.DS_Store
# Unit test / coverage reports # Unit test / coverage reports
htmlcov/ htmlcov/
@ -31,4 +31,4 @@ docs/_build/
.idea/ .idea/
# Database # Database
db.sqlite3 db.sqlite3

View File

@ -1,28 +1,27 @@
Django Admin Confirm # Django Admin Confirm
========
AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to changes and additions. AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to changes and additions.
![Screenshot of Confirmation Page](/screenshot.png)
It can be configured to add a confirmation page upon saving changes and/or additions on ModelAdmin. It can be configured to add a confirmation page upon saving changes and/or additions on ModelAdmin.
Typical Usage: Typical Usage:
from admin_confirm import AdminConfirmMixin from admin_confirm import AdminConfirmMixin
class MyModelAdmin(AdminConfirmMixin, ModelAdmin): class MyModelAdmin(AdminConfirmMixin, ModelAdmin):
confirm_change = True confirm_change = True
confirmation_fields = ['field1', 'field2'] confirmation_fields = ['field1', 'field2']
Installation ## Installation
------------
Install django-admin-confirm by running: Install django-admin-confirm by running:
pip install django-admin-confirm pip install django-admin-confirm
Add to INSTALLED_APPS in your project settings before `django.contrib.admin`: Add to INSTALLED_APPS in your project settings before `django.contrib.admin`:
INSTALLED_APPS = [ INSTALLED_APPS = [
... ...
'admin_confirm', 'admin_confirm',
@ -30,51 +29,50 @@ Add to INSTALLED_APPS in your project settings before `django.contrib.admin`:
'django.contrib.admin', 'django.contrib.admin',
... ...
] ]
Note that this project follows the template override rules of Django. 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. To override a template, your app should be listed before `admin_confirm` in INSTALLED_APPS.
## Configuration Options
Configuration Options
-------- - `confirm_change` _Optional[bool]_ - decides if changes should trigger confirmation
- `confirm_change` Optional[bool] - decides if changes should trigger confirmation - `confirm_add` _Optional[bool]_ - decides if additions should trigger confirmation
- `confirm_add` Optional[bool] - decides if additions should trigger confirmation - `confirmation_fields` _Optional[Array[string]]_ - sets which fields changes should trigger confirmation
- `confirmation_fields` Optional[Array[string]] - sets which fields changes/additions should trigger confirmation - `change_confirmation_template` _Optional[string]_ - path to custom html template to use
- `change_confirmation_template` Optional[string] - path to custom html template to use
Note that setting `confirmation_fields` without setting `confirm_change` or `confirm_add` would not trigger confirmation. Note that setting `confirmation_fields` without setting `confirm_change` or `confirm_add` would not trigger confirmation.
Contribution & Appreciation ## Contribution & Appreciation
----------
Contributions are most welcome :) Feel free to: Contributions are most welcome :) Feel free to:
- address an issue - address an issue
- raise an issue - raise an issue
- add more test cases - add more test cases
- add feature requests - add feature requests
Your appreciation is also very welcome :) Feel free to: Your appreciation is also very welcome :) Feel free to:
- star the project - star the project
- open an issue just to share your thanks - open an issue just to share your thanks
Feature List ## Feature List
-------
This is a list of features which could potentially be added in the future. 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.
- global actions on changelist page - [ ] confirmations on changelist actions
- instance actions on change/view page - [ ] global actions on changelist page
- confirmations on changelist actions - [ ] instance actions on change/view page
- run scripts from admin - [ ] action logs (adding actions to history of instances)
- completed action summary page - [ ] add help tooltip/popover to any field for more info
- action logs (adding actions to history of instances) - [ ] run scripts from admin
- [ ] completed action summary page
- [ ] add top and bottom areas to instance pages which can be configured for any content
Support ## Support
-------
If you are having issues, please let us know through raising an issue. If you are having issues, please let us know through raising an issue.
License ## License
-------
The project is licensed under the Apache 2.0 license. The project is licensed under the Apache 2.0 license.

View File

@ -127,9 +127,10 @@ class TestAdminConfirmMixin(TestCase):
self.assertEqual(expected_fields, actual_fields) self.assertEqual(expected_fields, actual_fields)
def test_custom_template(self): def test_custom_template(self):
expected_template = 'my_custom_template.html' expected_template = 'market/admin/my_custom_template.html'
ItemAdmin.confirmation_template = expected_template ItemAdmin.confirmation_template = expected_template
admin = ItemAdmin(Item, AdminSite()) admin = ItemAdmin(Item, AdminSite())
actual_template = admin.render_change_confirmation( actual_template = admin.render_change_confirmation(
self.factory.request(), context={}).template_name self.factory.request(), context={}).template_name
self.assertEqual(expected_template, actual_template) self.assertEqual(expected_template, actual_template)
ItemAdmin.confirmation_template = None

View File

@ -0,0 +1 @@
<!-- Just for testing -->