mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Exposed the request to ObjectEditView's alter_obj()
This commit is contained in:
@ -224,9 +224,9 @@ class CircuitTerminationEditView(PermissionRequiredMixin, ObjectEditView):
|
||||
fields_initial = ['term_side']
|
||||
template_name = 'circuits/circuittermination_edit.html'
|
||||
|
||||
def alter_obj(self, obj, args, kwargs):
|
||||
if 'circuit' in kwargs:
|
||||
obj.circuit = get_object_or_404(Circuit, pk=kwargs['circuit'])
|
||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||
if 'circuit' in url_kwargs:
|
||||
obj.circuit = get_object_or_404(Circuit, pk=url_kwargs['circuit'])
|
||||
return obj
|
||||
|
||||
def get_return_url(self, obj):
|
||||
|
@ -1517,9 +1517,9 @@ class ModuleEditView(PermissionRequiredMixin, ComponentEditView):
|
||||
model = Module
|
||||
form_class = forms.ModuleForm
|
||||
|
||||
def alter_obj(self, obj, args, kwargs):
|
||||
if 'device' in kwargs:
|
||||
obj.device = get_object_or_404(Device, pk=kwargs['device'])
|
||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||
if 'device' in url_kwargs:
|
||||
obj.device = get_object_or_404(Device, pk=url_kwargs['device'])
|
||||
return obj
|
||||
|
||||
|
||||
|
@ -764,9 +764,9 @@ class ServiceEditView(PermissionRequiredMixin, ObjectEditView):
|
||||
form_class = forms.ServiceForm
|
||||
template_name = 'ipam/service_edit.html'
|
||||
|
||||
def alter_obj(self, obj, args, kwargs):
|
||||
if 'device' in kwargs:
|
||||
obj.device = get_object_or_404(Device, pk=kwargs['device'])
|
||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||
if 'device' in url_kwargs:
|
||||
obj.device = get_object_or_404(Device, pk=url_kwargs['device'])
|
||||
return obj
|
||||
|
||||
def get_return_url(self, obj):
|
||||
|
@ -145,9 +145,9 @@ class ObjectEditView(View):
|
||||
return get_object_or_404(self.model, pk=kwargs['pk'])
|
||||
return self.model()
|
||||
|
||||
def alter_obj(self, obj, args, kwargs):
|
||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||
# Allow views to add extra info to an object before it is processed. For example, a parent object can be defined
|
||||
# given some parameter from the request URI.
|
||||
# given some parameter from the request URL.
|
||||
return obj
|
||||
|
||||
def get_return_url(self, obj):
|
||||
@ -159,7 +159,7 @@ class ObjectEditView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
obj = self.get_object(kwargs)
|
||||
obj = self.alter_obj(obj, args, kwargs)
|
||||
obj = self.alter_obj(obj, request, args, kwargs)
|
||||
initial_data = {k: request.GET[k] for k in self.fields_initial if k in request.GET}
|
||||
form = self.form_class(instance=obj, initial=initial_data)
|
||||
|
||||
@ -173,7 +173,7 @@ class ObjectEditView(View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
obj = self.get_object(kwargs)
|
||||
obj = self.alter_obj(obj, args, kwargs)
|
||||
obj = self.alter_obj(obj, request, args, kwargs)
|
||||
form = self.form_class(request.POST, instance=obj)
|
||||
|
||||
if form.is_valid():
|
||||
|
Reference in New Issue
Block a user