mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 02:58:17 -06:00
Add import for device-bays
This commit is contained in:
parent
6d4507035f
commit
ac8df27d97
@ -3450,6 +3450,56 @@ class PopulateDeviceBayForm(BootstrapMixin, forms.Form):
|
|||||||
).exclude(pk=device_bay.device.pk)
|
).exclude(pk=device_bay.device.pk)
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceBayCSVForm(forms.ModelForm):
|
||||||
|
device = FlexibleModelChoiceField(
|
||||||
|
queryset=Device.objects.all(),
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name or ID of device',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Device not found.',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
installed_device = FlexibleModelChoiceField(
|
||||||
|
queryset=Device.objects.all(),
|
||||||
|
required=False,
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name or ID of device',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Child device not found.',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = DeviceBay
|
||||||
|
fields = DeviceBay.csv_headers
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Limit installed device choices to devices of the correct type and location
|
||||||
|
if self.is_bound:
|
||||||
|
try:
|
||||||
|
device = self.fields['device'].to_python(self.data['device'])
|
||||||
|
except forms.ValidationError:
|
||||||
|
device = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
device = self.instance.device
|
||||||
|
except Device.DoesNotExist:
|
||||||
|
device = None
|
||||||
|
|
||||||
|
if device:
|
||||||
|
self.fields['installed_device'].queryset = Device.objects.filter(
|
||||||
|
site=device.site,
|
||||||
|
rack=device.rack,
|
||||||
|
parent_bay__isnull=True,
|
||||||
|
device_type__u_height=0,
|
||||||
|
device_type__subdevice_role=SUBDEVICE_ROLE_CHILD
|
||||||
|
).exclude(pk=device.pk)
|
||||||
|
else:
|
||||||
|
self.fields['installed_device'].queryset = Interface.objects.none()
|
||||||
|
|
||||||
|
|
||||||
class DeviceBayBulkRenameForm(BulkRenameForm):
|
class DeviceBayBulkRenameForm(BulkRenameForm):
|
||||||
pk = forms.ModelMultipleChoiceField(
|
pk = forms.ModelMultipleChoiceField(
|
||||||
queryset=DeviceBay.objects.all(),
|
queryset=DeviceBay.objects.all(),
|
||||||
|
@ -765,6 +765,16 @@ class DeviceBayTable(BaseTable):
|
|||||||
fields = ('name',)
|
fields = ('name',)
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceBayImportTable(BaseTable):
|
||||||
|
device = tables.LinkColumn('dcim:device', args=[Accessor('device.pk')], verbose_name='Device')
|
||||||
|
installed_device = tables.LinkColumn('dcim:device', args=[Accessor('installed_device.pk')], verbose_name='Installed Device')
|
||||||
|
|
||||||
|
class Meta(BaseTable.Meta):
|
||||||
|
model = DeviceBay
|
||||||
|
fields = ('device', 'name', 'installed_device', 'description')
|
||||||
|
empty_text = False
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cables
|
# Cables
|
||||||
#
|
#
|
||||||
|
@ -263,6 +263,7 @@ urlpatterns = [
|
|||||||
path(r'device-bays/<int:pk>/populate/', views.DeviceBayPopulateView.as_view(), name='devicebay_populate'),
|
path(r'device-bays/<int:pk>/populate/', views.DeviceBayPopulateView.as_view(), name='devicebay_populate'),
|
||||||
path(r'device-bays/<int:pk>/depopulate/', views.DeviceBayDepopulateView.as_view(), name='devicebay_depopulate'),
|
path(r'device-bays/<int:pk>/depopulate/', views.DeviceBayDepopulateView.as_view(), name='devicebay_depopulate'),
|
||||||
path(r'device-bays/rename/', views.DeviceBayBulkRenameView.as_view(), name='devicebay_bulk_rename'),
|
path(r'device-bays/rename/', views.DeviceBayBulkRenameView.as_view(), name='devicebay_bulk_rename'),
|
||||||
|
path(r'device-bays/import/', views.DeviceBayBulkImportView.as_view(), name='devicebay_import'),
|
||||||
|
|
||||||
# Inventory items
|
# Inventory items
|
||||||
path(r'inventory-items/', views.InventoryItemListView.as_view(), name='inventoryitem_list'),
|
path(r'inventory-items/', views.InventoryItemListView.as_view(), name='inventoryitem_list'),
|
||||||
|
@ -1685,6 +1685,14 @@ class DeviceBayDepopulateView(PermissionRequiredMixin, View):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceBayBulkImportView(PermissionRequiredMixin, BulkImportView):
|
||||||
|
permission_required = 'dcim.add_devicebay'
|
||||||
|
model_form = forms.DeviceBayCSVForm
|
||||||
|
table = tables.DeviceBayImportTable
|
||||||
|
# TODO: change after netbox-community#3564 has been implemented
|
||||||
|
# default_return_url = 'dcim:devicebay_list'
|
||||||
|
|
||||||
|
|
||||||
class DeviceBayBulkRenameView(PermissionRequiredMixin, BulkRenameView):
|
class DeviceBayBulkRenameView(PermissionRequiredMixin, BulkRenameView):
|
||||||
permission_required = 'dcim.change_devicebay'
|
permission_required = 'dcim.change_devicebay'
|
||||||
queryset = DeviceBay.objects.all()
|
queryset = DeviceBay.objects.all()
|
||||||
|
Loading…
Reference in New Issue
Block a user