Compare commits

..

1 Commits

Author SHA1 Message Date
Martin Hauser
6ca82a0901 fix(dcim): Avoid clearing scope on clone
ScopedForm._set_scoped_values() cleared initial['scope'] whenever the
scope_type differed from the instance value. During cloning (unsaved
instance), this runs on the initial GET and wipes the pre-filled scope,
forcing the user to re-select it.

Only clear the scope when editing an existing object (instance.pk set)
and the scope type has actually changed.

Fixes #21202
2026-01-22 22:34:47 +01:00
5 changed files with 7 additions and 31 deletions

View File

@@ -75,7 +75,7 @@ class ScopedForm(forms.Form):
except ObjectDoesNotExist: except ObjectDoesNotExist:
pass pass
if self.instance and scope_type_id != self.instance.scope_type_id: if self.instance and self.instance.pk and scope_type_id != self.instance.scope_type_id:
self.initial['scope'] = None self.initial['scope'] = None
else: else:

View File

@@ -732,25 +732,6 @@ class BaseInterface(models.Model):
if self.primary_mac_address: if self.primary_mac_address:
return self.primary_mac_address.mac_address return self.primary_mac_address.mac_address
@property
def mac_address_display(self):
"""
Rich representation of MAC addresses for use in table columns (e.g. InterfaceTable).
Handles various configurations of MAC addresses for an interface:
11:22:33:44:55:66 <-- Single MAC address on interface, assigned as primary
11:22:33:44:55:66 (2) <-- Multiple MAC addresses on interface, one assigned as primary
2 available <-- 1 or more MAC addresses on interface, none assigned as primary
- <-- No MAC addresses on interface
"""
available_mac_count = self.mac_addresses.count()
if self.primary_mac_address:
if available_mac_count > 1:
return f"{self.primary_mac_address} ({available_mac_count})"
return self.primary_mac_address
if available_mac_count:
return f"{available_mac_count} available"
return None
class Interface( class Interface(
InterfaceValidationMixin, InterfaceValidationMixin,

View File

@@ -616,7 +616,6 @@ class BaseInterfaceTable(NetBoxTable):
) )
primary_mac_address = tables.Column( primary_mac_address = tables.Column(
verbose_name=_('MAC Address'), verbose_name=_('MAC Address'),
accessor=Accessor('mac_address_display'),
linkify=True linkify=True
) )

View File

@@ -143,11 +143,9 @@
<tr> <tr>
<th scope="row">{% trans "MAC Address" %}</th> <th scope="row">{% trans "MAC Address" %}</th>
<td> <td>
{% if object.mac_address_display %} {% if object.primary_mac_address %}
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span> <span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
{% if object.primary_mac_address %} <span class="badge text-bg-primary">{% trans "Primary" %}</span>
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
{% endif %}
{% else %} {% else %}
{{ ''|placeholder }} {{ ''|placeholder }}
{% endif %} {% endif %}

View File

@@ -78,11 +78,9 @@
<tr> <tr>
<th scope="row">{% trans "MAC Address" %}</th> <th scope="row">{% trans "MAC Address" %}</th>
<td> <td>
{% if object.mac_address_display %} {% if object.mac_address %}
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span> <span class="font-monospace">{{ object.mac_address }}</span>
{% if object.primary_mac_address %} <span class="badge text-bg-primary">{% trans "Primary" %}</span>
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
{% endif %}
{% else %} {% else %}
{{ ''|placeholder }} {{ ''|placeholder }}
{% endif %} {% endif %}