Просмотр исходного кода

Fixes #2414: Tags field missing from device/VM component creation forms

Jeremy Stretch 7 лет назад
Родитель
Сommit
15babeb584

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ v2.4.5 (FUTURE)
 ## Bug Fixes
 
 * [#2406](https://github.com/digitalocean/netbox/issues/2406) - Remove hard-coded limit of 1000 objects from API-populated form fields
+* [#2414](https://github.com/digitalocean/netbox/issues/2414) - Tags field missing from device/VM component creation forms
 * [#2442](https://github.com/digitalocean/netbox/issues/2442) - Nullify "next" link in API when limit=0 is passed
 * [#2443](https://github.com/digitalocean/netbox/issues/2443) - Enforce JSON object format when creating config contexts
 * [#2444](https://github.com/digitalocean/netbox/issues/2444) - Improve validation of interface MAC addresses

+ 6 - 0
netbox/dcim/forms.py

@@ -1194,6 +1194,7 @@ class ConsolePortForm(BootstrapMixin, forms.ModelForm):
 
 class ConsolePortCreateForm(ComponentForm):
     name_pattern = ExpandableNameField(label='Name')
+    tags = TagField(required=False)
 
 
 class ConsoleConnectionCSVForm(forms.ModelForm):
@@ -1364,6 +1365,7 @@ class ConsoleServerPortForm(BootstrapMixin, forms.ModelForm):
 
 class ConsoleServerPortCreateForm(ComponentForm):
     name_pattern = ExpandableNameField(label='Name')
+    tags = TagField(required=False)
 
 
 class ConsoleServerPortConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.Form):
@@ -1461,6 +1463,7 @@ class PowerPortForm(BootstrapMixin, forms.ModelForm):
 
 class PowerPortCreateForm(ComponentForm):
     name_pattern = ExpandableNameField(label='Name')
+    tags = TagField(required=False)
 
 
 class PowerConnectionCSVForm(forms.ModelForm):
@@ -1631,6 +1634,7 @@ class PowerOutletForm(BootstrapMixin, forms.ModelForm):
 
 class PowerOutletCreateForm(ComponentForm):
     name_pattern = ExpandableNameField(label='Name')
+    tags = TagField(required=False)
 
 
 class PowerOutletConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.Form):
@@ -1864,6 +1868,7 @@ class InterfaceCreateForm(ComponentForm, forms.Form):
     )
     description = forms.CharField(max_length=100, required=False)
     mode = forms.ChoiceField(choices=add_blank_choice(IFACE_MODE_CHOICES), required=False)
+    tags = TagField(required=False)
 
     def __init__(self, *args, **kwargs):
 
@@ -2101,6 +2106,7 @@ class DeviceBayForm(BootstrapMixin, forms.ModelForm):
 
 class DeviceBayCreateForm(ComponentForm):
     name_pattern = ExpandableNameField(label='Name')
+    tags = TagField(required=False)
 
 
 class PopulateDeviceBayForm(BootstrapMixin, forms.Form):

+ 0 - 5
netbox/templates/dcim/interface_edit.html

@@ -14,11 +14,6 @@
             {% render_field form.mgmt_only %}
             {% render_field form.description %}
             {% render_field form.mode %}
-        </div>
-    </div>
-    <div class="panel panel-default">
-        <div class="panel-heading"><strong>Tags</strong></div>
-        <div class="panel-body">
             {% render_field form.tags %}
         </div>
     </div>

+ 1 - 0
netbox/templates/virtualization/interface_edit.html

@@ -11,6 +11,7 @@
             {% render_field form.mtu %}
             {% render_field form.description %}
             {% render_field form.mode %}
+            {% render_field form.tags %}
         </div>
     </div>
     {% if obj.mode %}

+ 5 - 15
netbox/utilities/views.py

@@ -710,24 +710,14 @@ class ComponentCreateView(View):
         if form.is_valid():
 
             new_components = []
-            data = deepcopy(form.cleaned_data)
+            data = deepcopy(request.POST)
+            data[self.parent_field] = parent.pk
 
             for name in form.cleaned_data['name_pattern']:
 
-                # Initialize data for the individual component form
-                component_data = {
-                    self.parent_field: parent.pk,
-                    'name': name,
-                }
-
-                # Replace objects with their primary key to keep component_form.clean() happy
-                for k, v in data.items():
-                    if hasattr(v, 'pk'):
-                        component_data[k] = v.pk
-                    else:
-                        component_data[k] = v
-
-                component_form = self.model_form(component_data)
+                # Initialize the individual component form
+                data['name'] = name
+                component_form = self.model_form(data)
 
                 if component_form.is_valid():
                     new_components.append(component_form)

+ 3 - 1
netbox/virtualization/forms.py

@@ -419,11 +419,12 @@ class VirtualMachineFilterForm(BootstrapMixin, CustomFieldFilterForm):
 #
 
 class InterfaceForm(BootstrapMixin, forms.ModelForm):
+    tags = TagField(required=False)
 
     class Meta:
         model = Interface
         fields = [
-            'virtual_machine', 'name', 'form_factor', 'enabled', 'mac_address', 'mtu', 'description', 'mode',
+            'virtual_machine', 'name', 'form_factor', 'enabled', 'mac_address', 'mtu', 'description', 'mode', 'tags',
             'untagged_vlan', 'tagged_vlans',
         ]
         widgets = {
@@ -462,6 +463,7 @@ class InterfaceCreateForm(ComponentForm):
     mtu = forms.IntegerField(required=False, min_value=1, max_value=32767, label='MTU')
     mac_address = forms.CharField(required=False, label='MAC Address')
     description = forms.CharField(max_length=100, required=False)
+    tags = TagField(required=False)
 
     def __init__(self, *args, **kwargs):