From e6b1f942cd02ecced6df62a8876e0f0978bf6887 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 26 Nov 2025 12:20:40 -0500 Subject: [PATCH] Misc cleanup --- netbox/dcim/forms/mixins.py | 11 +++-------- netbox/dcim/forms/model_forms.py | 3 +-- netbox/dcim/signals.py | 1 + netbox/dcim/tables/devices.py | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/netbox/dcim/forms/mixins.py b/netbox/dcim/forms/mixins.py index db9252b07..0497cd1ed 100644 --- a/netbox/dcim/forms/mixins.py +++ b/netbox/dcim/forms/mixins.py @@ -4,7 +4,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.utils.translation import gettext_lazy as _ from dcim.constants import LOCATION_SCOPE_TYPES -from dcim.models import PortTemplateMapping, Site +from dcim.models import PortMapping, Site from utilities.forms import get_field_value from utilities.forms.fields import ( ContentTypeChoiceField, CSVContentTypeField, DynamicModelChoiceField, @@ -138,17 +138,12 @@ class FrontPortFormMixin(forms.Form): widget=forms.SelectMultiple(attrs={'size': 8}) ) - port_mapping_model = PortTemplateMapping + port_mapping_model = PortMapping + parent_field = 'device' def clean(self): super().clean() - # FrontPort with no positions cannot be mapped to more than one RearPort - if not self.cleaned_data['positions'] and len(self.cleaned_data['rear_ports']) > 1: - raise forms.ValidationError({ - 'positions': _("A front port with no positions cannot be mapped to multiple rear ports.") - }) - # Count of selected rear port & position pairs much match the assigned number of positions if len(self.cleaned_data['rear_ports']) != self.cleaned_data['positions']: raise forms.ValidationError({ diff --git a/netbox/dcim/forms/model_forms.py b/netbox/dcim/forms/model_forms.py index 8471a7163..e21cad38e 100644 --- a/netbox/dcim/forms/model_forms.py +++ b/netbox/dcim/forms/model_forms.py @@ -1124,6 +1124,7 @@ class FrontPortTemplateForm(FrontPortFormMixin, ModularComponentTemplateForm): ), ) + # Override FrontPortFormMixin attrs port_mapping_model = PortTemplateMapping parent_field = 'device_type' @@ -1620,8 +1621,6 @@ class FrontPortForm(FrontPortFormMixin, ModularDeviceComponentForm): ), ) - port_mapping_model = PortMapping - class Meta: model = FrontPort fields = [ diff --git a/netbox/dcim/signals.py b/netbox/dcim/signals.py index d9edaaa98..81cb0ae6c 100644 --- a/netbox/dcim/signals.py +++ b/netbox/dcim/signals.py @@ -150,6 +150,7 @@ def nullify_connected_endpoints(instance, **kwargs): cablepath.retrace() +# TODO: Adapt signal handler to act on changes to port mappings @receiver(post_save, sender=FrontPort) def extend_rearport_cable_paths(instance, created, raw, **kwargs): """ diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 2b5a3eeff..d81718d78 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -840,7 +840,7 @@ class DeviceRearPortTable(RearPortTable): 'description', 'mark_connected', 'cable', 'cable_color', 'link_peer', 'tags', 'actions', ) default_columns = ( - 'pk', 'name', 'label', 'type', 'positions', 'mappings', 'description', 'cable', 'link_peer', + 'pk', 'name', 'label', 'type', 'color', 'positions', 'mappings', 'description', 'cable', 'link_peer', )