mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 20:22:53 -06:00
* 11670: Add optional weight to DeviceType import This is 1 of 2 commits to address issue #11670 To maintain consistency, the import design of the DeviceType weight follows the same pattern used for importing weight and weight units in DCIM Racks. * Closes #11670: Add weight to ModuleType import This is commit 2 of 2 to address and close #11670. To maintain consistency, the import design of the ModuleType weight follows the same pattern used for importing weight and weight units in DCIM Racks. * Merge tests; misc cleanup --------- Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
e1b7a3aeb6
commit
c55c14ea4c
@ -292,12 +292,21 @@ class DeviceTypeImportForm(NetBoxModelImportForm):
|
|||||||
required=False,
|
required=False,
|
||||||
help_text=_('The default platform for devices of this type (optional)')
|
help_text=_('The default platform for devices of this type (optional)')
|
||||||
)
|
)
|
||||||
|
weight = forms.DecimalField(
|
||||||
|
required=False,
|
||||||
|
help_text=_('Device weight'),
|
||||||
|
)
|
||||||
|
weight_unit = CSVChoiceField(
|
||||||
|
choices=WeightUnitChoices,
|
||||||
|
required=False,
|
||||||
|
help_text=_('Unit for device weight')
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DeviceType
|
model = DeviceType
|
||||||
fields = [
|
fields = [
|
||||||
'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
|
'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
|
||||||
'subdevice_role', 'airflow', 'description', 'comments',
|
'subdevice_role', 'airflow', 'description', 'weight', 'weight_unit', 'comments',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -306,10 +315,19 @@ class ModuleTypeImportForm(NetBoxModelImportForm):
|
|||||||
queryset=Manufacturer.objects.all(),
|
queryset=Manufacturer.objects.all(),
|
||||||
to_field_name='name'
|
to_field_name='name'
|
||||||
)
|
)
|
||||||
|
weight = forms.DecimalField(
|
||||||
|
required=False,
|
||||||
|
help_text=_('Module weight'),
|
||||||
|
)
|
||||||
|
weight_unit = CSVChoiceField(
|
||||||
|
choices=WeightUnitChoices,
|
||||||
|
required=False,
|
||||||
|
help_text=_('Unit for module weight')
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleType
|
model = ModuleType
|
||||||
fields = ['manufacturer', 'model', 'part_number', 'description', 'comments']
|
fields = ['manufacturer', 'model', 'part_number', 'description', 'weight', 'weight_unit', 'comments']
|
||||||
|
|
||||||
|
|
||||||
class DeviceRoleImportForm(NetBoxModelImportForm):
|
class DeviceRoleImportForm(NetBoxModelImportForm):
|
||||||
|
@ -184,6 +184,8 @@ class DeviceType(PrimaryModel, WeightMixin):
|
|||||||
'subdevice_role': self.subdevice_role,
|
'subdevice_role': self.subdevice_role,
|
||||||
'airflow': self.airflow,
|
'airflow': self.airflow,
|
||||||
'comments': self.comments,
|
'comments': self.comments,
|
||||||
|
'weight': float(self.weight) if self.weight is not None else None,
|
||||||
|
'weight_unit': self.weight_unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Component templates
|
# Component templates
|
||||||
@ -361,6 +363,8 @@ class ModuleType(PrimaryModel, WeightMixin):
|
|||||||
'model': self.model,
|
'model': self.model,
|
||||||
'part_number': self.part_number,
|
'part_number': self.part_number,
|
||||||
'comments': self.comments,
|
'comments': self.comments,
|
||||||
|
'weight': float(self.weight) if self.weight is not None else None,
|
||||||
|
'weight_unit': self.weight_unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Component templates
|
# Component templates
|
||||||
|
@ -681,11 +681,15 @@ class DeviceTypeTestCase(
|
|||||||
"""
|
"""
|
||||||
IMPORT_DATA = """
|
IMPORT_DATA = """
|
||||||
manufacturer: Generic
|
manufacturer: Generic
|
||||||
default_platform: Platform
|
|
||||||
model: TEST-1000
|
model: TEST-1000
|
||||||
slug: test-1000
|
slug: test-1000
|
||||||
|
default_platform: Platform
|
||||||
u_height: 2
|
u_height: 2
|
||||||
|
is_full_depth: false
|
||||||
|
airflow: front-to-rear
|
||||||
subdevice_role: parent
|
subdevice_role: parent
|
||||||
|
weight: 10
|
||||||
|
weight_unit: kg
|
||||||
comments: Test comment
|
comments: Test comment
|
||||||
console-ports:
|
console-ports:
|
||||||
- name: Console Port 1
|
- name: Console Port 1
|
||||||
@ -794,8 +798,16 @@ inventory-items:
|
|||||||
self.assertHttpStatus(response, 200)
|
self.assertHttpStatus(response, 200)
|
||||||
|
|
||||||
device_type = DeviceType.objects.get(model='TEST-1000')
|
device_type = DeviceType.objects.get(model='TEST-1000')
|
||||||
self.assertEqual(device_type.comments, 'Test comment')
|
self.assertEqual(device_type.manufacturer.pk, manufacturer.pk)
|
||||||
self.assertEqual(device_type.default_platform.pk, platform.pk)
|
self.assertEqual(device_type.default_platform.pk, platform.pk)
|
||||||
|
self.assertEqual(device_type.slug, 'test-1000')
|
||||||
|
self.assertEqual(device_type.u_height, 2)
|
||||||
|
self.assertFalse(device_type.is_full_depth)
|
||||||
|
self.assertEqual(device_type.airflow, DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR)
|
||||||
|
self.assertEqual(device_type.subdevice_role, SubdeviceRoleChoices.ROLE_PARENT)
|
||||||
|
self.assertEqual(device_type.weight, 10)
|
||||||
|
self.assertEqual(device_type.weight_unit, WeightUnitChoices.UNIT_KILOGRAM)
|
||||||
|
self.assertEqual(device_type.comments, 'Test comment')
|
||||||
|
|
||||||
# Verify all of the components were created
|
# Verify all of the components were created
|
||||||
self.assertEqual(device_type.consoleporttemplates.count(), 3)
|
self.assertEqual(device_type.consoleporttemplates.count(), 3)
|
||||||
@ -1019,6 +1031,8 @@ class ModuleTypeTestCase(
|
|||||||
IMPORT_DATA = """
|
IMPORT_DATA = """
|
||||||
manufacturer: Generic
|
manufacturer: Generic
|
||||||
model: TEST-1000
|
model: TEST-1000
|
||||||
|
weight: 10
|
||||||
|
weight_unit: lb
|
||||||
comments: Test comment
|
comments: Test comment
|
||||||
console-ports:
|
console-ports:
|
||||||
- name: Console Port 1
|
- name: Console Port 1
|
||||||
@ -1082,7 +1096,8 @@ front-ports:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Create the manufacturer
|
# Create the manufacturer
|
||||||
Manufacturer(name='Generic', slug='generic').save()
|
manufacturer = Manufacturer(name='Generic', slug='generic')
|
||||||
|
manufacturer.save()
|
||||||
|
|
||||||
# Add all required permissions to the test user
|
# Add all required permissions to the test user
|
||||||
self.add_permissions(
|
self.add_permissions(
|
||||||
@ -1105,6 +1120,9 @@ front-ports:
|
|||||||
self.assertHttpStatus(response, 200)
|
self.assertHttpStatus(response, 200)
|
||||||
|
|
||||||
module_type = ModuleType.objects.get(model='TEST-1000')
|
module_type = ModuleType.objects.get(model='TEST-1000')
|
||||||
|
self.assertEqual(module_type.manufacturer.pk, manufacturer.pk)
|
||||||
|
self.assertEqual(module_type.weight, 10)
|
||||||
|
self.assertEqual(module_type.weight_unit, WeightUnitChoices.UNIT_POUND)
|
||||||
self.assertEqual(module_type.comments, 'Test comment')
|
self.assertEqual(module_type.comments, 'Test comment')
|
||||||
|
|
||||||
# Verify all the components were created
|
# Verify all the components were created
|
||||||
|
Loading…
Reference in New Issue
Block a user