Browse Source

Fixed platform selection during bulk editing of devices

Jeremy Stretch 8 years ago
parent
commit
1f9e4dc707
2 changed files with 14 additions and 5 deletions
  1. 11 2
      netbox/dcim/forms.py
  2. 3 3
      netbox/dcim/views.py

+ 11 - 2
netbox/dcim/forms.py

@@ -533,13 +533,22 @@ class ChildDeviceImportForm(BulkImportForm, BootstrapMixin):
     csv = CSVDataField(csv_form=ChildDeviceFromCSVForm)
 
 
+def device_edit_platform_choices():
+    choices = [
+        (None, '---------'),
+        (0, 'None'),
+    ]
+    choices += [(p.pk, p.name) for p in Platform.objects.all()]
+    return choices
+
+
 class DeviceBulkEditForm(forms.Form, BootstrapMixin):
     pk = forms.ModelMultipleChoiceField(queryset=Device.objects.all(), widget=forms.MultipleHiddenInput)
     device_type = forms.ModelChoiceField(queryset=DeviceType.objects.all(), required=False, label='Type')
     device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
     tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False, label='Tenant')
-    platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False, label='Platform')
-    platform_delete = forms.BooleanField(required=False, label='Set platform to "none"')
+    platform = forms.TypedChoiceField(choices=device_edit_platform_choices, coerce=int, required=False,
+                                      label='Platform')
     status = forms.ChoiceField(choices=FORM_STATUS_CHOICES, required=False, initial='', label='Status')
     serial = forms.CharField(max_length=50, required=False, label='Serial Number')
 

+ 3 - 3
netbox/dcim/views.py

@@ -626,10 +626,10 @@ class DeviceBulkEditView(PermissionRequiredMixin, BulkEditView):
     def update_objects(self, pk_list, form):
 
         fields_to_update = {}
-        if form.cleaned_data['platform']:
-            fields_to_update['platform'] = form.cleaned_data['platform']
-        elif form.cleaned_data['platform_delete']:
+        if form.cleaned_data['platform'] == 0:
             fields_to_update['platform'] = None
+        elif form.cleaned_data['platform']:
+            fields_to_update['platform'] = form.cleaned_data['platform']
         if form.cleaned_data['status']:
             status = form.cleaned_data['status']
             fields_to_update['status'] = True if status == 'True' else False