Misc cleanup & reordering of form fields

This commit is contained in:
Jeremy Stretch 2024-07-25 14:49:48 -04:00
parent 660344b16b
commit a2eba9df93
8 changed files with 50 additions and 42 deletions

View File

@ -149,7 +149,7 @@ class ModuleSerializer(NetBoxModelSerializer):
class Meta: class Meta:
model = Module model = Module
fields = [ fields = [
'id', 'url', 'display_url', 'display', 'device', 'module_bay', 'module_type', 'status', 'id', 'url', 'display_url', 'display', 'device', 'module_bay', 'module_type', 'status', 'serial',
'serial', 'asset_tag', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'asset_tag', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
] ]
brief_fields = ('id', 'url', 'display', 'device', 'module_bay', 'module_type', 'description') brief_fields = ('id', 'url', 'display', 'device', 'module_bay', 'module_type', 'description')

View File

@ -62,9 +62,21 @@ class DeviceTypeSerializer(NetBoxModelSerializer):
class ModuleTypeSerializer(NetBoxModelSerializer): class ModuleTypeSerializer(NetBoxModelSerializer):
manufacturer = ManufacturerSerializer(nested=True) manufacturer = ManufacturerSerializer(
weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False, allow_null=True) nested=True
airflow = ChoiceField(choices=ModuleAirflowChoices, allow_blank=True, required=False, allow_null=True) )
weight_unit = ChoiceField(
choices=WeightUnitChoices,
allow_blank=True,
required=False,
allow_null=True
)
airflow = ChoiceField(
choices=ModuleAirflowChoices,
allow_blank=True,
required=False,
allow_null=True
)
class Meta: class Meta:
model = ModuleType model = ModuleType

View File

@ -75,8 +75,8 @@ class RackTypeSerializer(RackBaseSerializer):
fields = [ fields = [
'id', 'url', 'display_url', 'display', 'manufacturer', 'name', 'slug', 'description', 'form_factor', 'id', 'url', 'display_url', 'display', 'manufacturer', 'name', 'slug', 'description', 'form_factor',
'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'weight', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'weight',
'max_weight', 'weight_unit', 'mounting_depth', 'airflow', 'description', 'comments', 'tags', 'custom_fields', 'max_weight', 'weight_unit', 'mounting_depth', 'airflow', 'description', 'comments', 'tags',
'created', 'last_updated', 'custom_fields', 'created', 'last_updated',
] ]
brief_fields = ('id', 'url', 'display', 'manufacturer', 'name', 'slug', 'description') brief_fields = ('id', 'url', 'display', 'manufacturer', 'name', 'slug', 'description')

View File

@ -298,12 +298,10 @@ class RackTypeBulkEditForm(NetBoxModelBulkEditForm):
model = RackType model = RackType
fieldsets = ( fieldsets = (
FieldSet('manufacturer', 'description', 'form_factor', name=_('Rack Type')), FieldSet('manufacturer', 'description', 'form_factor', 'width', 'u_height', 'airflow', name=_('Rack Type')),
FieldSet( FieldSet(
'width',
'u_height',
InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')),
InlineFields('airflow', 'weight', 'max_weight', 'weight_unit', label=_('Chassis')), InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
'mounting_depth', 'mounting_depth',
name=_('Dimensions') name=_('Dimensions')
), ),
@ -447,10 +445,10 @@ class RackBulkEditForm(NetBoxModelBulkEditForm):
FieldSet('status', 'role', 'tenant', 'serial', 'asset_tag', 'description', name=_('Rack')), FieldSet('status', 'role', 'tenant', 'serial', 'asset_tag', 'description', name=_('Rack')),
FieldSet('region', 'site_group', 'site', 'location', name=_('Location')), FieldSet('region', 'site_group', 'site', 'location', name=_('Location')),
FieldSet( FieldSet(
'form_factor', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'form_factor', 'width', 'u_height', 'desc_units', 'airflow', 'outer_width', 'outer_depth', 'outer_unit',
'mounting_depth', name=_('Hardware') 'mounting_depth', name=_('Hardware')
), ),
FieldSet('airflow', 'weight', 'max_weight', 'weight_unit', name=_('Chassis')), FieldSet('weight', 'max_weight', 'weight_unit', name=_('Weight')),
) )
nullable_fields = ( nullable_fields = (
'location', 'tenant', 'role', 'serial', 'asset_tag', 'outer_width', 'outer_depth', 'outer_unit', 'weight', 'location', 'tenant', 'role', 'serial', 'asset_tag', 'outer_width', 'outer_depth', 'outer_unit', 'weight',
@ -599,7 +597,11 @@ class ModuleTypeBulkEditForm(NetBoxModelBulkEditForm):
model = ModuleType model = ModuleType
fieldsets = ( fieldsets = (
FieldSet('manufacturer', 'part_number', 'description', name=_('Module Type')), FieldSet('manufacturer', 'part_number', 'description', name=_('Module Type')),
FieldSet('airflow', 'weight', 'weight_unit', name=_('Chassis')), FieldSet(
'airflow',
InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
name=_('Chassis')
),
) )
nullable_fields = ('part_number', 'weight', 'weight_unit', 'description', 'comments') nullable_fields = ('part_number', 'weight', 'weight_unit', 'description', 'comments')

View File

@ -211,11 +211,11 @@ class RackTypeForm(NetBoxModelForm):
slug = SlugField() slug = SlugField()
fieldsets = ( fieldsets = (
FieldSet('manufacturer', 'name', 'slug', 'description', 'form_factor', 'tags', name=_('Rack Type')), FieldSet('manufacturer', 'name', 'slug', 'description', 'form_factor', 'airflow', 'tags', name=_('Rack Type')),
FieldSet( FieldSet(
'width', 'u_height', 'width', 'u_height',
InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')),
InlineFields('airflow', 'weight', 'max_weight', 'weight_unit', label=_('Chassis')), InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
'mounting_depth', name=_('Dimensions') 'mounting_depth', name=_('Dimensions')
), ),
FieldSet('starting_unit', 'desc_units', name=_('Numbering')), FieldSet('starting_unit', 'desc_units', name=_('Numbering')),
@ -290,9 +290,9 @@ class RackForm(TenancyForm, NetBoxModelForm):
self.fieldsets = ( self.fieldsets = (
*self.fieldsets, *self.fieldsets,
FieldSet( FieldSet(
'form_factor', 'width', 'starting_unit', 'u_height', 'form_factor', 'width', 'starting_unit', 'u_height', 'airflow',
InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')),
InlineFields('airflow', 'weight', 'max_weight', 'weight_unit', label=_('Chassis')), InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')),
'mounting_depth', 'desc_units', name=_('Dimensions') 'mounting_depth', 'desc_units', name=_('Dimensions')
), ),
) )

View File

@ -53,6 +53,12 @@ class RackBase(WeightMixin, PrimaryModel):
verbose_name=_('width'), verbose_name=_('width'),
help_text=_('Rail-to-rail width') help_text=_('Rail-to-rail width')
) )
airflow = models.CharField(
verbose_name=_('airflow'),
max_length=50,
choices=RackAirflowChoices,
blank=True
)
# Numbering # Numbering
u_height = models.PositiveSmallIntegerField( u_height = models.PositiveSmallIntegerField(
@ -116,14 +122,6 @@ class RackBase(WeightMixin, PrimaryModel):
null=True null=True
) )
# Airflow
airflow = models.CharField(
verbose_name=_('airflow'),
max_length=50,
choices=RackAirflowChoices,
blank=True
)
class Meta: class Meta:
abstract = True abstract = True
@ -240,10 +238,10 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase):
Each Rack is assigned to a Site and (optionally) a Location. Each Rack is assigned to a Site and (optionally) a Location.
""" """
# Fields which cannot be set locally if a RackType is assigned # Fields which cannot be set locally if a RackType is assigned
RACKTYPE_FIELDS = [ RACKTYPE_FIELDS = (
'form_factor', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'form_factor', 'width', 'airflow', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth',
'mounting_depth', 'weight', 'weight_unit', 'max_weight', 'airflow' 'outer_unit', 'mounting_depth', 'weight', 'weight_unit', 'max_weight',
] )
rack_type = models.ForeignKey( rack_type = models.ForeignKey(
to='dcim.RackType', to='dcim.RackType',
@ -324,8 +322,8 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase):
) )
clone_fields = ( clone_fields = (
'site', 'location', 'tenant', 'status', 'role', 'form_factor', 'width', 'u_height', 'desc_units', 'outer_width', 'site', 'location', 'tenant', 'status', 'role', 'form_factor', 'width', 'airflow', 'u_height', 'desc_units',
'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'airflow', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit',
) )
prerequisite_models = ( prerequisite_models = (
'dcim.Site', 'dcim.Site',

View File

@ -61,6 +61,10 @@
<th scope="row">{% trans "Asset Tag" %}</th> <th scope="row">{% trans "Asset Tag" %}</th>
<td class="font-monospace">{{ object.asset_tag|placeholder }}</td> <td class="font-monospace">{{ object.asset_tag|placeholder }}</td>
</tr> </tr>
<tr>
<th scope="row">{% trans "Airflow" %}</th>
<td>{{ object.get_airflow_display|placeholder }}</td>
</tr>
<tr> <tr>
<th scope="row">{% trans "Space Utilization" %}</th> <th scope="row">{% trans "Space Utilization" %}</th>
<td>{% utilization_graph object.get_utilization %}</td> <td>{% utilization_graph object.get_utilization %}</td>
@ -69,12 +73,6 @@
<th scope="row">{% trans "Power Utilization" %}</th> <th scope="row">{% trans "Power Utilization" %}</th>
<td>{% utilization_graph object.get_power_utilization %}</td> <td>{% utilization_graph object.get_power_utilization %}</td>
</tr> </tr>
<tr>
<th scope="row">{% trans "Airflow" %}</th>
<td>
{{ object.get_airflow_display|placeholder }}
</td>
</tr>
</table> </table>
</div> </div>
{% include 'dcim/inc/panels/racktype_dimensions.html' %} {% include 'dcim/inc/panels/racktype_dimensions.html' %}

View File

@ -25,10 +25,8 @@
<td>{{ object.description|placeholder }}</td> <td>{{ object.description|placeholder }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Airflow" %}</th> <th scope="row">{% trans "Airflow" %}</th>
<td> <td>{{ object.get_airflow_display|placeholder }}</td>
{{ object.get_airflow_display|placeholder }}
</td>
</tr> </tr>
</table> </table>
</div> </div>