From 98e6f2396cd02180d772877d167008e00a683e44 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 19 Feb 2024 23:03:05 +0000 Subject: [PATCH] Fixed #35237 -- Merged system checks for admin actions. --- django/contrib/admin/checks.py | 22 ++++++++-------------- django/contrib/admin/options.py | 5 ++++- 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__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__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."""