From b917403c934060635141b8e770f166946ace4e8f Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 12 Aug 2020 10:05:12 -0400 Subject: [PATCH] Replace 'nullable' attribute with null_option --- netbox/dcim/forms.py | 16 ++++------------ netbox/ipam/forms.py | 16 ++++------------ netbox/project-static/js/forms.js | 8 ++++---- netbox/tenancy/forms.py | 4 +--- netbox/virtualization/forms.py | 12 +++--------- 5 files changed, 16 insertions(+), 40 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 9c590c996..f6d8fccab 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -1747,12 +1747,10 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): cluster_group = DynamicModelChoiceField( queryset=ClusterGroup.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'cluster': 'group_id' - }, - attrs={ - 'nullable': 'true' } ) ) @@ -3438,12 +3436,10 @@ class ConnectCableToDeviceForm(BootstrapMixin, forms.ModelForm): queryset=Rack.objects.all(), label='Rack', required=False, + null_option='None', widget=APISelect( filter_for={ 'termination_b_device': 'rack_id', - }, - attrs={ - 'nullable': 'true', } ) ) @@ -3982,12 +3978,10 @@ class VirtualChassisCreateForm(BootstrapMixin, forms.ModelForm): rack = DynamicModelChoiceField( queryset=Rack.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'members': 'rack_id' - }, - attrs={ - 'nullable': 'true', } ) ) @@ -4118,12 +4112,10 @@ class VCMemberSelectForm(BootstrapMixin, forms.Form): rack = DynamicModelChoiceField( queryset=Rack.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'device': 'rack_id' - }, - attrs={ - 'nullable': 'true', } ) ) diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 59ccf7807..d86895b2c 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -257,13 +257,11 @@ class PrefixForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): site = DynamicModelChoiceField( queryset=Site.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'vlan_group': 'site_id', 'vlan': 'site_id', - }, - attrs={ - 'nullable': 'true', } ) ) @@ -271,12 +269,10 @@ class PrefixForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): queryset=VLANGroup.objects.all(), required=False, label='VLAN group', + null_option='None', widget=APISelect( filter_for={ 'vlan': 'group_id' - }, - attrs={ - 'nullable': 'true', } ) ) @@ -556,12 +552,10 @@ class IPAddressForm(BootstrapMixin, TenancyForm, ReturnURLForm, CustomFieldModel required=False, label='Rack', display_field='display_name', + null_option='None', widget=APISelect( filter_for={ 'nat_device': 'rack_id' - }, - attrs={ - 'nullable': 'true' } ) ) @@ -985,12 +979,10 @@ class VLANForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): site = DynamicModelChoiceField( queryset=Site.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'group': 'site_id' - }, - attrs={ - 'nullable': 'true', } ) ) diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index c496a0377..c06eb3045 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -74,7 +74,7 @@ $(document).ready(function() { form.submit(); }); - // Parse URLs which may contain variable refrences to other field values + // Parse URLs which may contain variable references to other field values function parseURL(url) { var filter_regex = /\{\{([a-z_]+)\}\}/g; var match; @@ -87,7 +87,7 @@ $(document).ready(function() { rendered_url = rendered_url.replace(match[0], custom_attr); } else if (filter_field.val()) { rendered_url = rendered_url.replace(match[0], filter_field.val()); - } else if (filter_field.attr('nullable') == 'true') { + } else if (filter_field.attr('data-null-option')) { rendered_url = rendered_url.replace(match[0], 'null'); } } @@ -123,7 +123,7 @@ $(document).ready(function() { // API backed selection // Includes live search and chained fields - // The `multiple` setting may be controled via a data-* attribute + // The `multiple` setting may be controlled via a data-* attribute $('.netbox-select2-api').select2({ allowClear: true, placeholder: "---------", @@ -165,7 +165,7 @@ $(document).ready(function() { filter_for_elements.each(function(index, filter_for_element) { var param_name = $(filter_for_element).attr(attr_name); var is_required = $(filter_for_element).attr("required"); - var is_nullable = $(filter_for_element).attr("nullable"); + var is_nullable = $(filter_for_element).attr("data-null-option"); var is_visible = $(filter_for_element).is(":visible"); var value = $(filter_for_element).val(); diff --git a/netbox/tenancy/forms.py b/netbox/tenancy/forms.py index 13ff4da65..94df2fc95 100644 --- a/netbox/tenancy/forms.py +++ b/netbox/tenancy/forms.py @@ -119,12 +119,10 @@ class TenancyForm(forms.Form): tenant_group = DynamicModelChoiceField( queryset=TenantGroup.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ 'tenant': 'group_id', - }, - attrs={ - 'nullable': 'true', } ) ) diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index e42a6597e..b05dbb476 100644 --- a/netbox/virtualization/forms.py +++ b/netbox/virtualization/forms.py @@ -197,12 +197,10 @@ class ClusterAddDevicesForm(BootstrapMixin, forms.Form): region = DynamicModelChoiceField( queryset=Region.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ "site": "region_id", - }, - attrs={ - 'nullable': 'true', } ) ) @@ -219,12 +217,10 @@ class ClusterAddDevicesForm(BootstrapMixin, forms.Form): rack = DynamicModelChoiceField( queryset=Rack.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ "devices": "rack_id" - }, - attrs={ - 'nullable': 'true', } ) ) @@ -278,12 +274,10 @@ class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldModelForm): cluster_group = DynamicModelChoiceField( queryset=ClusterGroup.objects.all(), required=False, + null_option='None', widget=APISelect( filter_for={ "cluster": "group_id", - }, - attrs={ - 'nullable': 'true', } ) )