Преглед изворни кода

Fixes #4084: Fix exception when creating an interface with tagged VLANs

Jeremy Stretch пре 6 година
родитељ
комит
cbe090cd3c

+ 1 - 0
docs/release-notes/version-2.7.md

@@ -18,6 +18,7 @@
 * [#4067](https://github.com/netbox-community/netbox/issues/4067) - Correct permission checked when creating a rack (vs. editing)
 * [#4071](https://github.com/netbox-community/netbox/issues/4071) - Enforce "view tag" permission on individual tag view
 * [#4079](https://github.com/netbox-community/netbox/issues/4079) - Fix assignment of power panel when bulk editing power feeds
+* [#4084](https://github.com/netbox-community/netbox/issues/4084) - Fix exception when creating an interface with tagged VLANs
 
 ---
 

+ 4 - 1
netbox/dcim/forms.py

@@ -2606,7 +2606,6 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
                 type=InterfaceTypeChoices.TYPE_LAG
             )
         else:
-            device = self.instance.device
             self.fields['lag'].queryset = Interface.objects.filter(
                 device__in=[self.instance.device, self.instance.device.get_vc_master()],
                 type=InterfaceTypeChoices.TYPE_LAG
@@ -2614,6 +2613,10 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
 
 
 class InterfaceCreateForm(InterfaceCommonForm, ComponentForm, forms.Form):
+    device = forms.ModelChoiceField(
+        queryset=Device.objects.all(),
+        widget=forms.HiddenInput()
+    )
     name_pattern = ExpandableNameField(
         label='Name'
     )

+ 3 - 0
netbox/templates/dcim/device_component_add.html

@@ -6,6 +6,9 @@
 {% block content %}
 <form action="." method="post" class="form form-horizontal">
     {% csrf_token %}
+    {% for field in form.hidden_fields %}
+        {{ field }}
+    {% endfor %}
     <div class="row">
         <div class="col-md-6 col-md-offset-3">
             {% if form.non_field_errors %}

+ 3 - 1
netbox/utilities/views.py

@@ -846,7 +846,9 @@ class ComponentCreateView(View):
     def get(self, request, pk):
 
         parent = get_object_or_404(self.parent_model, pk=pk)
-        form = self.form(parent, initial=request.GET)
+        data = deepcopy(request.GET)
+        data[self.parent_field] = parent.pk
+        form = self.form(parent, initial=data)
 
         return render(request, self.template_name, {
             'parent': parent,