mirror of https://github.com/django/django.git
Fixed #29711 -- Added a system check for uniquness of admin actions' __name__.
This commit is contained in:
parent
7598cd4748
commit
70d0a1ca02
1
AUTHORS
1
AUTHORS
|
@ -686,6 +686,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Preston Holmes <preston@ptone.com>
|
Preston Holmes <preston@ptone.com>
|
||||||
Preston Timmons <prestontimmons@gmail.com>
|
Preston Timmons <prestontimmons@gmail.com>
|
||||||
Priyansh Saxena <askpriyansh@gmail.com>
|
Priyansh Saxena <askpriyansh@gmail.com>
|
||||||
|
Przemysław Buczkowski <przemub@przemub.pl>
|
||||||
Przemysław Suliga <http://suligap.net>
|
Przemysław Suliga <http://suligap.net>
|
||||||
Rachel Tobin <rmtobin@me.com>
|
Rachel Tobin <rmtobin@me.com>
|
||||||
Rachel Willmer <http://www.willmer.com/kb/>
|
Rachel Willmer <http://www.willmer.com/kb/>
|
||||||
|
|
|
@ -606,6 +606,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
||||||
*self._check_search_fields(admin_obj),
|
*self._check_search_fields(admin_obj),
|
||||||
*self._check_date_hierarchy(admin_obj),
|
*self._check_date_hierarchy(admin_obj),
|
||||||
*self._check_action_permission_methods(admin_obj),
|
*self._check_action_permission_methods(admin_obj),
|
||||||
|
*self._check_actions_uniqueness(admin_obj),
|
||||||
]
|
]
|
||||||
|
|
||||||
def _check_save_as(self, obj):
|
def _check_save_as(self, obj):
|
||||||
|
@ -944,6 +945,18 @@ class ModelAdminChecks(BaseModelAdminChecks):
|
||||||
)
|
)
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
def _check_actions_uniqueness(self, obj):
|
||||||
|
"""Check that every action has a unique __name__."""
|
||||||
|
names = [name for _, name, _ in obj._get_base_actions()]
|
||||||
|
if len(names) != len(set(names)):
|
||||||
|
return [checks.Error(
|
||||||
|
'__name__ attributes of actions defined in %s must be '
|
||||||
|
'unique.' % obj.__class__,
|
||||||
|
obj=obj.__class__,
|
||||||
|
id='admin.E130',
|
||||||
|
)]
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class InlineModelAdminChecks(BaseModelAdminChecks):
|
class InlineModelAdminChecks(BaseModelAdminChecks):
|
||||||
|
|
||||||
|
|
|
@ -593,6 +593,8 @@ with the admin site:
|
||||||
``DateTimeField``.
|
``DateTimeField``.
|
||||||
* **admin.E129**: ``<modeladmin>`` must define a ``has_<foo>_permission()``
|
* **admin.E129**: ``<modeladmin>`` must define a ``has_<foo>_permission()``
|
||||||
method for the ``<action>`` action.
|
method for the ``<action>`` action.
|
||||||
|
* **admin.E130**: ``__name__`` attributes of actions defined in
|
||||||
|
``<modeladmin>`` must be unique.
|
||||||
|
|
||||||
``InlineModelAdmin``
|
``InlineModelAdmin``
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1309,3 +1309,30 @@ class ActionsCheckTests(CheckTestCase):
|
||||||
'custom_permission_action action.',
|
'custom_permission_action action.',
|
||||||
id='admin.E129',
|
id='admin.E129',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_actions_not_unique(self):
|
||||||
|
def action(modeladmin, request, queryset):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BandAdmin(ModelAdmin):
|
||||||
|
actions = (action, action)
|
||||||
|
|
||||||
|
self.assertIsInvalid(
|
||||||
|
BandAdmin, Band,
|
||||||
|
"__name__ attributes of actions defined in "
|
||||||
|
"<class 'modeladmin.test_checks.ActionsCheckTests."
|
||||||
|
"test_actions_not_unique.<locals>.BandAdmin'> must be unique.",
|
||||||
|
id='admin.E130',
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_actions_unique(self):
|
||||||
|
def action1(modeladmin, request, queryset):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def action2(modeladmin, request, queryset):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BandAdmin(ModelAdmin):
|
||||||
|
actions = (action1, action2)
|
||||||
|
|
||||||
|
self.assertIsValid(BandAdmin, Band)
|
||||||
|
|
Loading…
Reference in New Issue