summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-02-19 23:03:05 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-21 05:25:25 +0100
commit98e6f2396cd02180d772877d167008e00a683e44 (patch)
treeb372430d7f87b6cab940795b3bd62050f8d85fbd /django
parenta084c5d35a6d00abd261338a374a4424764b4aee (diff)
Fixed #35237 -- Merged system checks for admin actions.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/checks.py22
-rw-r--r--django/contrib/admin/options.py5
2 files changed, 12 insertions, 15 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index c1a17af076..94e700cf68 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -816,8 +816,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
*self._check_list_editable(admin_obj),
*self._check_search_fields(admin_obj),
*self._check_date_hierarchy(admin_obj),
- *self._check_action_permission_methods(admin_obj),
- *self._check_actions_uniqueness(admin_obj),
+ *self._check_actions(admin_obj),
]
def _check_save_as(self, obj):
@@ -1195,13 +1194,12 @@ class ModelAdminChecks(BaseModelAdminChecks):
else:
return []
- def _check_action_permission_methods(self, obj):
- """
- Actions with an allowed_permission attribute require the ModelAdmin to
- implement a has_<perm>_permission() method for each permission.
- """
- actions = obj._get_base_actions()
+ def _check_actions(self, obj):
errors = []
+ actions = obj._get_base_actions()
+
+ # Actions with an allowed_permission attribute require the ModelAdmin
+ # to implement a has_<perm>_permission() method for each permission.
for func, name, _ in actions:
if not hasattr(func, "allowed_permissions"):
continue
@@ -1220,12 +1218,8 @@ class ModelAdminChecks(BaseModelAdminChecks):
id="admin.E129",
)
)
- return errors
-
- def _check_actions_uniqueness(self, obj):
- """Check that every action has a unique __name__."""
- errors = []
- names = collections.Counter(name for _, name, _ in obj._get_base_actions())
+ # Names need to be unique.
+ names = collections.Counter(name for _, name, _ in actions)
for name, count in names.items():
if count > 1:
errors.append(
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index e93fdf4047..47b4821fcc 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -1033,7 +1033,10 @@ class ModelAdmin(BaseModelAdmin):
@staticmethod
def _get_action_description(func, name):
- return getattr(func, "short_description", capfirst(name.replace("_", " ")))
+ try:
+ return func.short_description
+ except AttributeError:
+ return capfirst(name.replace("_", " "))
def _get_base_actions(self):
"""Return the list of actions, prior to any request-based filtering."""