MCPcopy
hub / github.com/django/django / get_action

Method get_action

django/contrib/admin/options.py:1216–1251  ·  view source on GitHub ↗

Return a given action from a parameter, which can either be a callable, or the name of a method on the ModelAdmin. Return is a tuple of (callable, name, description).

(self, action, action_location=ActionLocation.CHANGE_LIST)

Source from the content-addressed store, hash-verified

1214 return choices
1215
1216 def get_action(self, action, action_location=ActionLocation.CHANGE_LIST):
1217 """
1218 Return a given action from a parameter, which can either be a callable,
1219 or the name of a method on the ModelAdmin. Return is a tuple of
1220 (callable, name, description).
1221 """
1222 # If the action is a callable, just use it.
1223 if callable(action):
1224 func = action
1225 action = action.__name__
1226
1227 # Next, look for a method. Grab it off self.__class__ to get an unbound
1228 # method instead of a bound one; this ensures that the calling
1229 # conventions are the same for functions and methods.
1230 elif hasattr(self.__class__, action):
1231 func = getattr(self.__class__, action)
1232
1233 # Finally, look for a named method on the admin site
1234 else:
1235 try:
1236 func = self.admin_site.get_action(action)
1237 except KeyError:
1238 return None
1239 # Filter out actions based on the action type.
1240 locations = getattr(func, "locations", [ActionLocation.CHANGE_LIST])
1241 if action_location not in locations:
1242 return None
1243
1244 description = self._get_action_description(func, action)
1245 return Action(
1246 func=func,
1247 name=action,
1248 description=description,
1249 plural_description=getattr(func, "plural_description", description),
1250 locations=locations,
1251 )
1252
1253 def get_list_display(self, request):
1254 """

Callers 1

_get_base_actionsMethod · 0.95

Calls 3

callableFunction · 0.85
ActionClass · 0.70

Tested by

no test coverage detected