From 15babeb5840ab36d47dcf1da4dd7a849db90ae07 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 28 Sep 2018 16:26:08 -0400 Subject: [PATCH] Fixes #2414: Tags field missing from device/VM component creation forms --- CHANGELOG.md | 1 + netbox/dcim/forms.py | 6 ++++++ netbox/templates/dcim/interface_edit.html | 5 ----- .../virtualization/interface_edit.html | 1 + netbox/utilities/views.py | 20 +++++-------------- netbox/virtualization/forms.py | 4 +++- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d88b2daa..853a0df47 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index cec2fafad..e7fa15f7b 100644 --- a/netbox/dcim/forms.py +++ b/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): diff --git a/netbox/templates/dcim/interface_edit.html b/netbox/templates/dcim/interface_edit.html index 6423c61c2..60d233b03 100644 --- a/netbox/templates/dcim/interface_edit.html +++ b/netbox/templates/dcim/interface_edit.html @@ -14,11 +14,6 @@ {% render_field form.mgmt_only %} {% render_field form.description %} {% render_field form.mode %} - - -
-
Tags
-
{% render_field form.tags %}
diff --git a/netbox/templates/virtualization/interface_edit.html b/netbox/templates/virtualization/interface_edit.html index b3aa38fd3..7977f9fed 100644 --- a/netbox/templates/virtualization/interface_edit.html +++ b/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 %} {% if obj.mode %} diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py index abfaeb5da..ef042176e 100644 --- a/netbox/utilities/views.py +++ b/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) diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index ee1007be3..e94c2cdaa 100644 --- a/netbox/virtualization/forms.py +++ b/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):