From c7b68664f9e48c0d70b18f4da8ae2c59b0c26e99 Mon Sep 17 00:00:00 2001 From: Jonathan Ramstedt Date: Fri, 1 Aug 2025 19:51:00 +0300 Subject: [PATCH] Closes #18843: use color name in cable export (#19983) --- netbox/dcim/models/cables.py | 10 ++++++++++ netbox/dcim/tables/cables.py | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 0a28d5acb..26bb0fed7 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -11,6 +11,7 @@ from dcim.choices import * from dcim.constants import * from dcim.fields import PathField from dcim.utils import decompile_path_node, object_to_path_node +from netbox.choices import ColorChoices from netbox.models import ChangeLoggedModel, PrimaryModel from utilities.conversion import to_meters from utilities.exceptions import AbortRequest @@ -155,6 +156,15 @@ class Cable(PrimaryModel): self._terminations_modified = True self._b_terminations = value + @property + def color_name(self): + color_name = "" + for hex_code, label in ColorChoices.CHOICES: + if hex_code.lower() == self.color.lower(): + color_name = str(label) + + return color_name + def clean(self): super().clean() diff --git a/netbox/dcim/tables/cables.py b/netbox/dcim/tables/cables.py index e12545fd2..321eb79f5 100644 --- a/netbox/dcim/tables/cables.py +++ b/netbox/dcim/tables/cables.py @@ -113,6 +113,10 @@ class CableTable(TenancyColumnsMixin, NetBoxTable): order_by=('_abs_length') ) color = columns.ColorColumn() + color_name = tables.Column( + verbose_name=_('Color Name'), + orderable=False + ) comments = columns.MarkdownColumn() tags = columns.TagColumn( url_name='dcim:cable_list' @@ -123,7 +127,7 @@ class CableTable(TenancyColumnsMixin, NetBoxTable): fields = ( 'pk', 'id', 'label', 'a_terminations', 'b_terminations', 'device_a', 'device_b', 'rack_a', 'rack_b', 'location_a', 'location_b', 'site_a', 'site_b', 'status', 'type', 'tenant', 'tenant_group', 'color', - 'length', 'description', 'comments', 'tags', 'created', 'last_updated', + 'color_name', 'length', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'id', 'label', 'a_terminations', 'b_terminations', 'status', 'type',