MCPcopy
hub / github.com/django/django / response_action

Method response_action

django/contrib/admin/options.py:1804–1897  ·  view source on GitHub ↗

Handle an admin action. Returns an HttpResponse if the action was handled, and None otherwise.

(
        self, request, queryset, action_location=ActionLocation.CHANGE_LIST
    )

Source from the content-addressed store, hash-verified

1802 return self._response_post_save(request, obj)
1803
1804 def response_action(
1805 self, request, queryset, action_location=ActionLocation.CHANGE_LIST
1806 ):
1807 """
1808 Handle an admin action. Returns an HttpResponse if the action was
1809 handled, and None otherwise.
1810 """
1811
1812 # There can be multiple action forms on the page (at the top
1813 # and bottom of the change list, for example). Get the action
1814 # whose button was pushed.
1815 try:
1816 action_index = int(request.POST.get("index", 0))
1817 except ValueError:
1818 action_index = 0
1819
1820 # Construct the action form.
1821 data = request.POST.copy()
1822 data.pop(helpers.ACTION_CHECKBOX_NAME, None)
1823 data.pop("index", None)
1824
1825 # Use the action whose button was pushed
1826 try:
1827 data.update({"action": data.getlist("action")[action_index]})
1828 except IndexError:
1829 # If we didn't get an action from the chosen form that's invalid
1830 # POST data, so by deleting action it'll fail the validation check
1831 # below. So no need to do anything here
1832 pass
1833
1834 prefix = (
1835 action_location.value
1836 if action_location != ActionLocation.CHANGE_LIST
1837 else ""
1838 )
1839 action_form = self.action_form(data, auto_id=None, prefix=prefix)
1840 # RemovedInDjango70Warning: When the deprecation ends, replace with:
1841 # action_form.fields["action"].choices = self.get_action_choices(
1842 # request, action_location=action_location
1843 # )
1844 action_form.fields["action"].choices = (
1845 self._get_action_choices_with_action_location(
1846 request, action_location=action_location
1847 )
1848 )
1849
1850 # If the form's valid we can handle the action.
1851 if action_form.is_valid():
1852 action = action_form.cleaned_data["action"]
1853 select_across = action_form.cleaned_data["select_across"]
1854 if action_location == ActionLocation.CHANGE_FORM:
1855 select_across = False
1856 # RemovedInDjango70Warning: When the deprecation ends, replace:
1857 # actions = self.get_actions(
1858 # request, action_location=action_location
1859 # )
1860 actions = self._get_actions_with_action_location(
1861 request, action_location=action_location

Callers 2

_changeform_viewMethod · 0.95
changelist_viewMethod · 0.95

Calls 12

message_userMethod · 0.95
get_full_pathMethod · 0.80
getMethod · 0.45
copyMethod · 0.45
popMethod · 0.45
updateMethod · 0.45
getlistMethod · 0.45
is_validMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected