From d8d439b7fa8b3a6360a4356b3198407866b33bd2 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 30 Sep 2022 16:02:14 -0400 Subject: [PATCH] Misc cleanup --- netbox/dcim/api/serializers.py | 20 +++++++------- netbox/dcim/forms/bulk_edit.py | 6 ++--- netbox/dcim/forms/models.py | 4 +-- netbox/dcim/models/devices.py | 13 ++++++--- netbox/dcim/models/racks.py | 16 ++++++++--- netbox/dcim/tables/devicetypes.py | 2 +- netbox/dcim/tables/modules.py | 2 +- netbox/dcim/tables/racks.py | 6 ++--- netbox/templates/dcim/device.html | 25 ------------------ netbox/templates/dcim/rack.html | 44 +++++++++++-------------------- 10 files changed, 56 insertions(+), 82 deletions(-) diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 2b2d85e3b..22d56565e 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -201,17 +201,17 @@ class RackSerializer(NetBoxModelSerializer): default=None) width = ChoiceField(choices=RackWidthChoices, required=False) outer_unit = ChoiceField(choices=RackDimensionUnitChoices, allow_blank=True, required=False) + weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False) device_count = serializers.IntegerField(read_only=True) powerfeed_count = serializers.IntegerField(read_only=True) - weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False) class Meta: model = Rack fields = [ 'id', 'url', 'display', 'name', 'facility_id', 'site', 'location', 'tenant', 'status', 'role', 'serial', - 'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', - 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count', 'powerfeed_count', - 'weight', 'weight_unit', + 'asset_tag', 'type', 'width', 'u_height', 'weight', 'weight_unit', 'desc_units', 'outer_width', + 'outer_depth', 'outer_unit', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count', + 'powerfeed_count', ] @@ -317,29 +317,29 @@ class DeviceTypeSerializer(NetBoxModelSerializer): ) subdevice_role = ChoiceField(choices=SubdeviceRoleChoices, allow_blank=True, required=False) airflow = ChoiceField(choices=DeviceAirflowChoices, allow_blank=True, required=False) - device_count = serializers.IntegerField(read_only=True) weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False) + device_count = serializers.IntegerField(read_only=True) class Meta: model = DeviceType fields = [ 'id', 'url', 'display', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'airflow', 'front_image', 'rear_image', 'comments', 'tags', 'custom_fields', 'created', - 'last_updated', 'device_count', 'weight', 'weight_unit' + 'subdevice_role', 'airflow', 'weight', 'weight_unit', 'front_image', 'rear_image', 'comments', 'tags', + 'custom_fields', 'created', 'last_updated', 'device_count', ] class ModuleTypeSerializer(NetBoxModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='dcim-api:moduletype-detail') manufacturer = NestedManufacturerSerializer() - # module_count = serializers.IntegerField(read_only=True) weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False) + # module_count = serializers.IntegerField(read_only=True) class Meta: model = ModuleType fields = [ - 'id', 'url', 'display', 'manufacturer', 'model', 'part_number', 'comments', 'tags', 'custom_fields', - 'created', 'last_updated', 'weight', 'weight_unit' + 'id', 'url', 'display', 'manufacturer', 'model', 'part_number', 'weight', 'weight_unit', 'comments', 'tags', + 'custom_fields', 'created', 'last_updated', ] diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py index c07db9557..d033d3a67 100644 --- a/netbox/dcim/forms/bulk_edit.py +++ b/netbox/dcim/forms/bulk_edit.py @@ -379,7 +379,7 @@ class DeviceTypeBulkEditForm(NetBoxModelBulkEditForm): model = DeviceType fieldsets = ( - (None, ('manufacturer', 'part_number', 'u_height', 'is_full_depth', 'airflow')), + ('Device Type', ('manufacturer', 'part_number', 'u_height', 'is_full_depth', 'airflow')), ('Weight', ('weight', 'weight_unit')), ) nullable_fields = ('part_number', 'airflow', 'weight', 'weight_unit') @@ -406,8 +406,8 @@ class ModuleTypeBulkEditForm(NetBoxModelBulkEditForm): model = ModuleType fieldsets = ( - (None, ('manufacturer', 'part_number')), - ('Attributes', ('weight', 'weight_unit')), + ('Module Type', ('manufacturer', 'part_number')), + ('Weight', ('weight', 'weight_unit')), ) nullable_fields = ('part_number', 'weight', 'weight_unit') diff --git a/netbox/dcim/forms/models.py b/netbox/dcim/forms/models.py index 23baa7675..4faefb623 100644 --- a/netbox/dcim/forms/models.py +++ b/netbox/dcim/forms/models.py @@ -260,7 +260,7 @@ class RackForm(TenancyForm, NetBoxModelForm): fields = [ 'region', 'site_group', 'site', 'location', 'name', 'facility_id', 'tenant_group', 'tenant', 'status', 'role', 'serial', 'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', - 'outer_unit', 'comments', 'tags', 'weight', 'weight_unit' + 'outer_unit', 'weight', 'weight_unit', 'comments', 'tags', ] help_texts = { 'site': "The site at which the rack exists", @@ -402,7 +402,7 @@ class ModuleTypeForm(NetBoxModelForm): class Meta: model = ModuleType fields = [ - 'manufacturer', 'model', 'part_number', 'comments', 'tags', 'weight', 'weight_unit' + 'manufacturer', 'model', 'part_number', 'weight', 'weight_unit', 'comments', 'tags', ] widgets = { diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 9526d8a7b..b7c4abd32 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -141,7 +141,7 @@ class DeviceType(NetBoxModel, WeightMixin): ) clone_fields = ( - 'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', + 'manufacturer', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow', 'weight', 'weight_unit', ) class Meta: @@ -346,7 +346,7 @@ class ModuleType(NetBoxModel, WeightMixin): to='extras.ImageAttachment' ) - clone_fields = ('manufacturer',) + clone_fields = ('manufacturer', 'weight', 'weight_unit',) class Meta: ordering = ('manufacturer', 'model') @@ -949,8 +949,13 @@ class Device(NetBoxModel, ConfigContextModel): return DeviceStatusChoices.colors.get(self.status) @cached_property - def get_total_weight(self): - total_weight = sum(module.module_type._abs_weight for module in Module.objects.filter(device=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type')) + def total_weight(self): + total_weight = sum( + module.module_type._abs_weight + for module in Module.objects.filter(device=self) + .exclude(module_type___abs_weight__isnull=True) + .prefetch_related('module_type') + ) if self.device_type._abs_weight: total_weight += self.device_type._abs_weight return round(total_weight / 1000, 2) diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index b196141d7..6da48b65c 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -187,7 +187,7 @@ class Rack(NetBoxModel, WeightMixin): clone_fields = ( 'site', 'location', 'tenant', 'status', 'role', 'type', 'width', 'u_height', 'desc_units', 'outer_width', - 'outer_depth', 'outer_unit', + 'outer_depth', 'outer_unit', 'weight', 'weight_unit', ) class Meta: @@ -457,9 +457,17 @@ class Rack(NetBoxModel, WeightMixin): return int(allocated_draw / available_power_total * 100) @cached_property - def get_total_weight(self): - total_weight = sum(device.device_type._abs_weight for device in self.devices.exclude(device_type___abs_weight__isnull=True).prefetch_related('device_type')) - total_weight += sum(module.module_type._abs_weight for module in Module.objects.filter(device__rack=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type')) + def total_weight(self): + total_weight = sum( + device.device_type._abs_weight + for device in self.devices.exclude(device_type___abs_weight__isnull=True).prefetch_related('device_type') + ) + total_weight += sum( + module.module_type._abs_weight + for module in Module.objects.filter(device__rack=self) + .exclude(module_type___abs_weight__isnull=True) + .prefetch_related('module_type') + ) if self._abs_weight: total_weight += self._abs_weight return round(total_weight / 1000, 2) diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index 79e795748..8f371ef1a 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -94,7 +94,7 @@ class DeviceTypeTable(NetBoxTable): model = DeviceType fields = ( 'pk', 'id', 'model', 'manufacturer', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', - 'airflow', 'comments', 'instance_count', 'tags', 'created', 'last_updated', 'weight' + 'airflow', 'weight', 'comments', 'instance_count', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count', diff --git a/netbox/dcim/tables/modules.py b/netbox/dcim/tables/modules.py index 43ca53063..b644e6ba6 100644 --- a/netbox/dcim/tables/modules.py +++ b/netbox/dcim/tables/modules.py @@ -35,7 +35,7 @@ class ModuleTypeTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = ModuleType fields = ( - 'pk', 'id', 'model', 'manufacturer', 'part_number', 'comments', 'tags', 'weight' + 'pk', 'id', 'model', 'manufacturer', 'part_number', 'weight', 'comments', 'tags', ) default_columns = ( 'pk', 'model', 'manufacturer', 'part_number', diff --git a/netbox/dcim/tables/racks.py b/netbox/dcim/tables/racks.py index 2cb0fa17a..ffca07145 100644 --- a/netbox/dcim/tables/racks.py +++ b/netbox/dcim/tables/racks.py @@ -91,9 +91,9 @@ class RackTable(TenancyColumnsMixin, NetBoxTable): class Meta(NetBoxTable.Meta): model = Rack fields = ( - 'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'tenant_group', 'role', 'serial', 'asset_tag', - 'type', 'width', 'outer_width', 'outer_depth', 'u_height', 'comments', 'device_count', 'get_utilization', - 'get_power_utilization', 'contacts', 'tags', 'created', 'last_updated', 'weight' + 'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'tenant_group', 'role', 'serial', + 'asset_tag', 'type', 'width', 'outer_width', 'outer_depth', 'u_height', 'weight', 'comments', + 'device_count', 'get_utilization', 'get_power_utilization', 'contacts', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count', diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 217592fb1..6cc859749 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -110,31 +110,6 @@ - {% if object.get_total_weight %} -
-
- Weight -
-
- - - - - - - - - -
Device Weight - {% if object.device_type.weight %} - {{ object.device_type.weight|floatformat }} {{ object.device_type.get_weight_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
Total Weight{{ object.get_total_weight|floatformat }} Kilograms
-
-
- {% endif %} {% if vc_members %}
diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 887f7b734..e30ce7a62 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -104,9 +104,7 @@
-
- Dimensions -
+
Dimensions
@@ -147,6 +145,20 @@ {% endif %} + + + + + + + +
Rack Weight + {% if object.weight %} + {{ object.weight|floatformat }} {{ object.get_weight_unit_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
Total Weight{{ object.total_weight|floatformat }} Kilograms
@@ -187,32 +199,6 @@ {% endif %} - {% if object.get_total_weight %} -
-
- Weight -
-
- - - - - - - - - -
Rack Weight - {% if object.weight %} - {{ object.weight|floatformat }} {{ object.get_weight_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
Total Weight{{ object.get_total_weight|floatformat }} Kilograms
-
-
- {% endif %} - {% include 'inc/panels/image_attachments.html' %}