From b9b8652b952e27635f9712b2bd5bd7b11a5bec50 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Sun, 14 Jul 2024 15:27:15 -0400 Subject: [PATCH] Misc cleanup --- netbox/dcim/api/nested_serializers.py | 8 - netbox/dcim/api/serializers_/racks.py | 34 +++- netbox/dcim/api/urls.py | 2 +- netbox/dcim/forms/bulk_edit.py | 16 +- netbox/dcim/forms/bulk_import.py | 7 +- netbox/dcim/forms/filtersets.py | 19 ++- netbox/dcim/forms/model_forms.py | 7 +- netbox/dcim/models/racks.py | 10 +- netbox/dcim/search.py | 4 +- netbox/dcim/tables/racks.py | 20 +-- netbox/dcim/urls.py | 12 +- netbox/dcim/views.py | 6 +- netbox/netbox/navigation/menu.py | 7 +- netbox/templates/dcim/racktype.html | 204 ++++++++++++----------- netbox/templates/dcim/racktype_list.html | 5 - 15 files changed, 196 insertions(+), 165 deletions(-) delete mode 100644 netbox/templates/dcim/racktype_list.html diff --git a/netbox/dcim/api/nested_serializers.py b/netbox/dcim/api/nested_serializers.py index 155efc4bb..6aff1bdc9 100644 --- a/netbox/dcim/api/nested_serializers.py +++ b/netbox/dcim/api/nested_serializers.py @@ -39,7 +39,6 @@ __all__ = [ 'NestedRackReservationSerializer', 'NestedRackRoleSerializer', 'NestedRackSerializer', - 'NestedRackTypeSerializer', 'NestedRearPortSerializer', 'NestedRearPortTemplateSerializer', 'NestedRegionSerializer', @@ -112,13 +111,6 @@ class NestedRackRoleSerializer(WritableNestedSerializer): fields = ['id', 'url', 'display_url', 'display', 'name', 'slug', 'rack_count'] -class NestedRackTypeSerializer(WritableNestedSerializer): - - class Meta: - model = models.RackType - fields = ['id', 'url', 'display_url', 'display', 'name'] - - @extend_schema_serializer( exclude_fields=('device_count',), ) diff --git a/netbox/dcim/api/serializers_/racks.py b/netbox/dcim/api/serializers_/racks.py index 9dd6ddfcd..c66e8253d 100644 --- a/netbox/dcim/api/serializers_/racks.py +++ b/netbox/dcim/api/serializers_/racks.py @@ -35,18 +35,36 @@ class RackRoleSerializer(NetBoxModelSerializer): class RackTypeSerializer(NetBoxModelSerializer): - type = ChoiceField(choices=RackTypeChoices, allow_blank=True, required=False, allow_null=True) - width = ChoiceField(choices=RackWidthChoices, required=False) - outer_unit = ChoiceField(choices=RackDimensionUnitChoices, allow_blank=True, required=False, allow_null=True) - weight_unit = ChoiceField(choices=WeightUnitChoices, allow_blank=True, required=False, allow_null=True) + type = ChoiceField( + choices=RackTypeChoices, + allow_blank=True, + required=False, + allow_null=True + ) + width = ChoiceField( + choices=RackWidthChoices, + required=False + ) + outer_unit = ChoiceField( + choices=RackDimensionUnitChoices, + allow_blank=True, + required=False, + allow_null=True + ) + weight_unit = ChoiceField( + choices=WeightUnitChoices, + allow_blank=True, + required=False, + allow_null=True + ) class Meta: model = RackType fields = [ - 'id', 'url', 'display_url', 'display', 'name', 'slug', - 'type', 'width', 'u_height', 'starting_unit', 'weight', 'max_weight', - 'weight_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'description', - 'comments', 'tags', 'custom_fields', 'created', 'last_updated', + 'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'type', 'width', 'u_height', + 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'weight', 'max_weight', + 'weight_unit', 'mounting_depth', 'description', 'comments', 'tags', 'custom_fields', 'created', + 'last_updated', ] brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description') diff --git a/netbox/dcim/api/urls.py b/netbox/dcim/api/urls.py index 96f63390d..d099b392a 100644 --- a/netbox/dcim/api/urls.py +++ b/netbox/dcim/api/urls.py @@ -12,10 +12,10 @@ router.register('sites', views.SiteViewSet) # Racks router.register('locations', views.LocationViewSet) +router.register('rack-types', views.RackTypeViewSet) router.register('rack-roles', views.RackRoleViewSet) router.register('racks', views.RackViewSet) router.register('rack-reservations', views.RackReservationViewSet) -router.register('rack-types', views.RackTypeViewSet) # Device/module types router.register('manufacturers', views.ManufacturerViewSet) diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py index 0cdfd2454..787d0bfa9 100644 --- a/netbox/dcim/forms/bulk_edit.py +++ b/netbox/dcim/forms/bulk_edit.py @@ -13,7 +13,7 @@ from netbox.forms import NetBoxModelBulkEditForm from tenancy.models import Tenant from utilities.forms import BulkEditForm, add_blank_choice, form_from_model from utilities.forms.fields import ColorField, CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField -from utilities.forms.rendering import FieldSet +from utilities.forms.rendering import FieldSet, InlineFields from utilities.forms.widgets import BulkEditNullBooleanSelect, NumberWithOptions from wireless.models import WirelessLAN, WirelessLANGroup from wireless.choices import WirelessRoleChoices @@ -234,6 +234,10 @@ class RackTypeBulkEditForm(NetBoxModelBulkEditForm): required=False, label=_('Height (U)') ) + starting_unit = forms.IntegerField( + required=False, + min_value=1 + ) desc_units = forms.NullBooleanField( required=False, widget=BulkEditNullBooleanSelect, @@ -284,12 +288,14 @@ class RackTypeBulkEditForm(NetBoxModelBulkEditForm): model = RackType fieldsets = ( - FieldSet('description', name=_('Rack')), + FieldSet('description', 'type', name=_('Rack Type')), FieldSet( - 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', - name=_('Hardware') + 'width', 'u_height', + InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), + InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')), + 'mounting_depth', name=_('Dimensions') ), - FieldSet('weight', 'max_weight', 'weight_unit', name=_('Weight')), + FieldSet('starting_unit', 'desc_units', name=_('Numbering')), ) nullable_fields = ( 'outer_width', 'outer_depth', 'outer_unit', 'weight', diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index b98cc8bb3..71f0e2fde 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -184,6 +184,11 @@ class RackTypeImportForm(NetBoxModelImportForm): required=False, help_text=_('Rack type') ) + starting_unit = forms.IntegerField( + required=False, + min_value=1, + help_text=_('The lowest-numbered position in the rack') + ) width = forms.ChoiceField( label=_('Width'), choices=RackWidthChoices, @@ -205,7 +210,7 @@ class RackTypeImportForm(NetBoxModelImportForm): class Meta: model = RackType fields = ( - 'name', 'slug', 'type', 'width', 'u_height', 'desc_units', 'outer_width', + 'name', 'slug', 'type', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags', ) diff --git a/netbox/dcim/forms/filtersets.py b/netbox/dcim/forms/filtersets.py index fe228d447..9ea73e518 100644 --- a/netbox/dcim/forms/filtersets.py +++ b/netbox/dcim/forms/filtersets.py @@ -245,7 +245,7 @@ class RackTypeFilterForm(NetBoxModelFilterSetForm): model = RackType fieldsets = ( FieldSet('q', 'filter_id', 'tag'), - FieldSet('type', 'width', name=_('Hardware')), + FieldSet('type', 'width', 'u_height', 'starting_unit', name=_('Rack Type')), FieldSet('weight', 'max_weight', 'weight_unit', name=_('Weight')), ) selector_fields = ('filter_id', 'q',) @@ -259,7 +259,21 @@ class RackTypeFilterForm(NetBoxModelFilterSetForm): choices=RackWidthChoices, required=False ) - tag = TagFilterField(model) + u_height = forms.IntegerField( + required=False, + min_value=1 + ) + starting_unit = forms.IntegerField( + required=False, + min_value=1 + ) + desc_units = forms.NullBooleanField( + required=False, + label=_('Descending units'), + widget=forms.Select( + choices=BOOLEAN_WITH_BLANK_CHOICES + ) + ) weight = forms.DecimalField( label=_('Weight'), required=False, @@ -275,6 +289,7 @@ class RackTypeFilterForm(NetBoxModelFilterSetForm): choices=add_blank_choice(WeightUnitChoices), required=False ) + tag = TagFilterField(model) class RackFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilterSetForm): diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 0b3f8a314..f880c54bf 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -207,13 +207,14 @@ class RackTypeForm(NetBoxModelForm): slug = SlugField() fieldsets = ( - FieldSet('name', 'slug', 'description', 'tags', name=_('Rack')), + FieldSet('name', 'slug', 'description', 'type', 'tags', name=_('Rack')), FieldSet( - 'type', 'width', 'starting_unit', 'u_height', + 'width', 'u_height', InlineFields('outer_width', 'outer_depth', 'outer_unit', label=_('Outer Dimensions')), InlineFields('weight', 'max_weight', 'weight_unit', label=_('Weight')), - 'mounting_depth', 'desc_units', name=_('Dimensions') + 'mounting_depth', name=_('Dimensions') ), + FieldSet('starting_unit', 'desc_units', name=_('Numbering')), ) class Meta: diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index e2d48efa2..b3cbee8b5 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -37,7 +37,7 @@ __all__ = ( # Rack Types # -class RackType(PrimaryModel, WeightMixin): +class RackType(WeightMixin, PrimaryModel): """ Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face. Each Rack is assigned to a Site and (optionally) a Location. @@ -124,10 +124,10 @@ class RackType(PrimaryModel, WeightMixin): verbose_name=_('mounting depth'), blank=True, null=True, - help_text=( - _('Maximum depth of a mounted device, in millimeters. For four-post racks, this is the ' - 'distance between the front and rear rails.') - ) + help_text=(_( + 'Maximum depth of a mounted device, in millimeters. For four-post racks, this is the distance between the ' + 'front and rear rails.' + )) ) clone_fields = ( diff --git a/netbox/dcim/search.py b/netbox/dcim/search.py index 34a9e73ed..32add68d0 100644 --- a/netbox/dcim/search.py +++ b/netbox/dcim/search.py @@ -250,9 +250,7 @@ class RackTypeIndex(SearchIndex): ('description', 500), ('comments', 5000), ) - display_attrs = ( - 'site', 'description', - ) + display_attrs = ('type', 'description') @register_search diff --git a/netbox/dcim/tables/racks.py b/netbox/dcim/tables/racks.py index ef7d8779c..5d00636ed 100644 --- a/netbox/dcim/tables/racks.py +++ b/netbox/dcim/tables/racks.py @@ -59,12 +59,6 @@ class RackTypeTable(NetBoxTable): template_code="{{ value }}U", verbose_name=_('Height') ) - comments = columns.MarkdownColumn( - verbose_name=_('Comments'), - ) - tags = columns.TagColumn( - url_name='dcim:rack_list' - ) outer_width = tables.TemplateColumn( template_code="{{ record.outer_width }} {{ record.outer_unit }}", verbose_name=_('Outer Width') @@ -83,17 +77,21 @@ class RackTypeTable(NetBoxTable): template_code=WEIGHT, order_by=('_abs_max_weight', 'weight_unit') ) + comments = columns.MarkdownColumn( + verbose_name=_('Comments'), + ) + tags = columns.TagColumn( + url_name='dcim:rack_list' + ) class Meta(NetBoxTable.Meta): model = RackType fields = ( - 'pk', 'id', 'name', - 'type', 'u_height', 'starting_unit', 'width', 'outer_width', 'outer_depth', 'mounting_depth', - 'weight', 'max_weight', 'comments', - 'description', 'tags', 'created', 'last_updated', + 'pk', 'id', 'name', 'type', 'u_height', 'starting_unit', 'width', 'outer_width', 'outer_depth', + 'mounting_depth', 'weight', 'max_weight', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( - 'pk', 'name', 'u_height', + 'pk', 'name', 'type', 'u_height', 'description', ) diff --git a/netbox/dcim/urls.py b/netbox/dcim/urls.py index 1dff67ca3..627136bf9 100644 --- a/netbox/dcim/urls.py +++ b/netbox/dcim/urls.py @@ -64,12 +64,12 @@ urlpatterns = [ path('racks//', include(get_model_urls('dcim', 'rack'))), # Rack Types - path('racktypes/', views.RackTypeListView.as_view(), name='racktype_list'), - path('racktypes/add/', views.RackTypeEditView.as_view(), name='racktype_add'), - path('racktypes/import/', views.RackTypeBulkImportView.as_view(), name='racktype_import'), - path('racktypes/edit/', views.RackTypeBulkEditView.as_view(), name='racktype_bulk_edit'), - path('racktypes/delete/', views.RackTypeBulkDeleteView.as_view(), name='racktype_bulk_delete'), - path('racktypes//', include(get_model_urls('dcim', 'racktype'))), + path('rack-types/', views.RackTypeListView.as_view(), name='racktype_list'), + path('rack-types/add/', views.RackTypeEditView.as_view(), name='racktype_add'), + path('rack-types/import/', views.RackTypeBulkImportView.as_view(), name='racktype_import'), + path('rack-types/edit/', views.RackTypeBulkEditView.as_view(), name='racktype_bulk_edit'), + path('rack-types/delete/', views.RackTypeBulkDeleteView.as_view(), name='racktype_bulk_delete'), + path('rack-types//', include(get_model_urls('dcim', 'racktype'))), # Manufacturers path('manufacturers/', views.ManufacturerListView.as_view(), name='manufacturer_list'), diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index f39a1998d..5ff20f35e 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -588,13 +588,17 @@ class RackTypeListView(generic.ObjectListView): filterset = filtersets.RackTypeFilterSet filterset_form = forms.RackTypeFilterForm table = tables.RackTypeTable - template_name = 'dcim/racktype_list.html' @register_model_view(RackType) class RackTypeView(GetRelatedModelsMixin, generic.ObjectView): queryset = RackType.objects.all() + def get_extra_context(self, request, instance): + return { + 'related_models': self.get_related_models(request, instance), + } + @register_model_view(RackType, 'edit') class RackTypeEditView(generic.ObjectEditView): diff --git a/netbox/netbox/navigation/menu.py b/netbox/netbox/navigation/menu.py index 6c7984391..ab6c3b99c 100644 --- a/netbox/netbox/navigation/menu.py +++ b/netbox/netbox/navigation/menu.py @@ -24,6 +24,7 @@ ORGANIZATION_MENU = Menu( label=_('Racks'), items=( get_model_item('dcim', 'rack', _('Racks')), + get_model_item('dcim', 'racktype', _('Rack Types')), get_model_item('dcim', 'rackrole', _('Rack Roles')), get_model_item('dcim', 'rackreservation', _('Reservations')), MenuItem( @@ -33,12 +34,6 @@ ORGANIZATION_MENU = Menu( ), ), ), - MenuGroup( - label=_('Rack Types'), - items=( - get_model_item('dcim', 'racktype', _('Rack Types')), - ), - ), MenuGroup( label=_('Tenancy'), items=( diff --git a/netbox/templates/dcim/racktype.html b/netbox/templates/dcim/racktype.html index fd17b78e1..e8d50cac8 100644 --- a/netbox/templates/dcim/racktype.html +++ b/netbox/templates/dcim/racktype.html @@ -1,4 +1,4 @@ -{% extends 'dcim/rack/base.html' %} +{% extends 'generic/object.html' %} {% load buttons %} {% load helpers %} {% load static %} @@ -8,108 +8,112 @@ {% block content %}
-
-
-
{% trans "Rack Type" %}
- - - - - -
{% trans "Description" %}{{ object.description|placeholder }}
-
-
-
{% trans "Dimensions" %}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{% trans "Type" %} - {% if object.type %} - {{ object.get_type_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
{% trans "Width" %}{{ object.get_width_display }}
{% trans "Height" %}{{ object.u_height }}U ({% if object.desc_units %}{% trans "descending" %}{% else %}{% trans "ascending" %}{% endif %})
{% trans "Starting Unit" %} - {{ object.starting_unit }} -
{% trans "Outer Width" %} - {% if object.outer_width %} - {{ object.outer_width }} {{ object.get_outer_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
{% trans "Outer Depth" %} - {% if object.outer_depth %} - {{ object.outer_depth }} {{ object.get_outer_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
{% trans "Mounting Depth" %} - {% if object.mounting_depth %} - {{ object.mounting_depth }} {% trans "Millimeters" %} - {% else %} - {{ ''|placeholder }} - {% endif %} -
{% trans "Rack Weight" %} - {% if object.weight %} - {{ object.weight|floatformat }} {{ object.get_weight_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
{% trans "Maximum Weight" %} - {% if object.max_weight %} - {{ object.max_weight }} {{ object.get_weight_unit_display }} - {% else %} - {{ ''|placeholder }} - {% endif %} -
-
- {% include 'inc/panels/custom_fields.html' %} - {% include 'inc/panels/tags.html' %} - {% include 'inc/panels/comments.html' %} - {% plugin_left_page object %} +
+
+
{% trans "Rack Type" %}
+ + + + + + + + + + + + + +
{% trans "Name" %}{{ object.name }}
{% trans "Type" %} + {% if object.type %} + {{ object.get_type_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
{% trans "Description" %}{{ object.description|placeholder }}
+
+
+
{% trans "Dimensions" %}
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans "Width" %}{{ object.get_width_display }}
{% trans "Height" %}{{ object.u_height }}U ({% if object.desc_units %}{% trans "descending" %}{% else %}{% trans "ascending" %}{% endif %})
{% trans "Starting Unit" %} + {{ object.starting_unit }} +
{% trans "Outer Width" %} + {% if object.outer_width %} + {{ object.outer_width }} {{ object.get_outer_unit_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
{% trans "Outer Depth" %} + {% if object.outer_depth %} + {{ object.outer_depth }} {{ object.get_outer_unit_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
{% trans "Mounting Depth" %} + {% if object.mounting_depth %} + {{ object.mounting_depth }} {% trans "Millimeters" %} + {% else %} + {{ ''|placeholder }} + {% endif %} +
{% trans "Rack Weight" %} + {% if object.weight %} + {{ object.weight|floatformat }} {{ object.get_weight_unit_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
{% trans "Maximum Weight" %} + {% if object.max_weight %} + {{ object.max_weight }} {{ object.get_weight_unit_display }} + {% else %} + {{ ''|placeholder }} + {% endif %} +
+
+ {% include 'inc/panels/tags.html' %} + {% include 'inc/panels/comments.html' %} + {% plugin_left_page object %}
-
- {% include 'inc/panels/related_objects.html' %} - {% plugin_right_page object %} +
+ {% include 'inc/panels/custom_fields.html' %} + {% include 'inc/panels/related_objects.html' %} + {% plugin_right_page object %}
-
- {% plugin_full_width_page object %} -
+
+ {% plugin_full_width_page object %} +
{% endblock %} diff --git a/netbox/templates/dcim/racktype_list.html b/netbox/templates/dcim/racktype_list.html deleted file mode 100644 index 35fe74f02..000000000 --- a/netbox/templates/dcim/racktype_list.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'generic/object_list.html' %} -{% load helpers %} -{% load static %} -{% load i18n %} -