MCPcopy
hub / github.com/django/django / _changeform_view

Method _changeform_view

django/contrib/admin/options.py:2044–2222  ·  view source on GitHub ↗
(self, request, object_id, form_url, extra_context)

Source from the content-addressed store, hash-verified

2042 return self._changeform_view(request, object_id, form_url, extra_context)
2043
2044 def _changeform_view(self, request, object_id, form_url, extra_context):
2045 to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
2046 if to_field and not self.to_field_allowed(request, to_field):
2047 raise DisallowedModelAdminToField(
2048 "The field %s cannot be referenced." % to_field
2049 )
2050
2051 if request.method == "POST" and "_saveasnew" in request.POST:
2052 object_id = None
2053
2054 add = object_id is None
2055
2056 if add:
2057 if not self.has_add_permission(request):
2058 raise PermissionDenied
2059 obj = None
2060
2061 else:
2062 obj = self.get_object(request, unquote(object_id), to_field)
2063 if not self.has_view_or_change_permission(request, obj):
2064 raise PermissionDenied
2065
2066 if obj is None:
2067 return self._get_obj_does_not_exist_redirect(
2068 request, self.opts, object_id
2069 )
2070
2071 action_form = None
2072 # RemovedInDjango70Warning: When the deprecation ends, replace with:
2073 # actions = self.get_actions(
2074 # request, action_location=ActionLocation.CHANGE_FORM
2075 # )
2076 actions = self._get_actions_with_action_location(
2077 request, action_location=ActionLocation.CHANGE_FORM
2078 )
2079 if actions and not add:
2080 action_location = ActionLocation.CHANGE_FORM
2081 action_form = self.action_form(auto_id=None, prefix=action_location.value)
2082 # RemovedInDjango70Warning: When the deprecation ends, replace:
2083 # action_form.fields["action"].choices = self.get_action_choices(
2084 # request, action_location=action_location
2085 # )
2086 action_form.fields["action"].choices = (
2087 self._get_action_choices_with_action_location(
2088 request, action_location=action_location
2089 )
2090 )
2091 fieldsets = self.get_fieldsets(request, obj)
2092 ModelForm = self.get_form(
2093 request, obj, change=not add, fields=flatten_fieldsets(fieldsets)
2094 )
2095 if request.method == "POST":
2096 if (
2097 action_form
2098 and action_form["action"].html_name in request.POST
2099 and "_save" not in request.POST
2100 and "_continue" not in request.POST
2101 and "_addanother" not in request.POST

Callers 1

changeform_viewMethod · 0.95

Calls 15

get_objectMethod · 0.95
get_formMethod · 0.95
response_actionMethod · 0.95
_create_formsetsMethod · 0.95
save_formMethod · 0.95
save_modelMethod · 0.95
save_relatedMethod · 0.95
log_additionMethod · 0.95

Tested by

no test coverage detected