Compare commits

...

8 Commits

Author SHA1 Message Date
Brian Tiemann
087a2adb3c Also include vminterface.html 2026-01-22 22:16:12 -05:00
Brian Tiemann
a145dbc44a Ensure "-" null placeholder still shows up on detail page 2026-01-22 22:13:12 -05:00
Brian Tiemann
9b1f033c73 Use mac_address_display in interface detail page 2026-01-22 22:08:30 -05:00
Brian Tiemann
60e37e868b Fix docstring 2026-01-22 22:02:40 -05:00
Brian Tiemann
c1287de970 Fix docstring 2026-01-22 22:00:42 -05:00
Brian Tiemann
3891b2a25f Richer display of MAC addresses in InterfaceTable when multiple MACs are present 2026-01-22 21:56:33 -05:00
bctiemann
4b4c542dce Add truncate_middle filter for middle-ellipsis on long filenames (#21253)
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CI / build (20.x, 3.13) (push) Has been cancelled
CI / build (20.x, 3.14) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
Close stale issues/PRs / stale (push) Has been cancelled
Close incomplete issues / stale (push) Has been cancelled
Update translation strings / makemessages (push) Has been cancelled
2026-01-22 09:40:48 -08:00
github-actions
077d9b1129 Update source translation strings
Some checks failed
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
2026-01-22 05:07:49 +00:00
7 changed files with 58 additions and 21 deletions

View File

@@ -732,6 +732,25 @@ 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,6 +616,7 @@ 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

@@ -43,7 +43,7 @@ IMAGEATTACHMENT_IMAGE = """
<a href="{{ record.image.url }}" target="_blank" class="image-preview" data-bs-placement="top"> <a href="{{ record.image.url }}" target="_blank" class="image-preview" data-bs-placement="top">
<i class="mdi mdi-image"></i></a> <i class="mdi mdi-image"></i></a>
{% endif %} {% endif %}
<a href="{{ record.get_absolute_url }}">{{ record }}</a> <a href="{{ record.get_absolute_url }}">{{ record.filename|truncate_middle:16 }}</a>
""" """
NOTIFICATION_ICON = """ NOTIFICATION_ICON = """

View File

@@ -143,9 +143,11 @@
<tr> <tr>
<th scope="row">{% trans "MAC Address" %}</th> <th scope="row">{% trans "MAC Address" %}</th>
<td> <td>
{% if object.mac_address_display %}
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
{% if object.primary_mac_address %} {% if object.primary_mac_address %}
<span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
<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,9 +78,11 @@
<tr> <tr>
<th scope="row">{% trans "MAC Address" %}</th> <th scope="row">{% trans "MAC Address" %}</th>
<td> <td>
{% if object.mac_address %} {% if object.mac_address_display %}
<span class="font-monospace">{{ object.mac_address }}</span> <span class="font-monospace">{{ object.mac_address_display|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

@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-01-21 05:07+0000\n" "POT-Creation-Date: 2026-01-22 05:07+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -12037,7 +12037,7 @@ msgstr ""
msgid "date synced" msgid "date synced"
msgstr "" msgstr ""
#: netbox/netbox/models/features.py:623 #: netbox/netbox/models/features.py:621
#, python-brace-format #, python-brace-format
msgid "{class_name} must implement a sync_data() method." msgid "{class_name} must implement a sync_data() method."
msgstr "" msgstr ""
@@ -13935,8 +13935,8 @@ msgid "No VLANs Assigned"
msgstr "" msgstr ""
#: netbox/templates/dcim/inc/interface_vlans_table.html:44 #: netbox/templates/dcim/inc/interface_vlans_table.html:44
#: netbox/templates/ipam/prefix_list.html:16 #: netbox/templates/ipam/inc/max_depth.html:11
#: netbox/templates/ipam/prefix_list.html:33 #: netbox/templates/ipam/inc/max_length.html:11
msgid "Clear" msgid "Clear"
msgstr "" msgstr ""
@@ -15053,8 +15053,8 @@ msgstr ""
msgid "Date Added" msgid "Date Added"
msgstr "" msgstr ""
#: netbox/templates/ipam/aggregate/prefixes.html:8 #: netbox/templates/ipam/aggregate/prefixes.html:10
#: netbox/templates/ipam/prefix/prefixes.html:8 #: netbox/templates/ipam/prefix/prefixes.html:10
#: netbox/templates/ipam/role.html:10 #: netbox/templates/ipam/role.html:10
msgid "Add Prefix" msgid "Add Prefix"
msgstr "" msgstr ""
@@ -15083,6 +15083,14 @@ msgstr ""
msgid "Bulk Create" msgid "Bulk Create"
msgstr "" msgstr ""
#: netbox/templates/ipam/inc/max_depth.html:6
msgid "Max Depth"
msgstr ""
#: netbox/templates/ipam/inc/max_length.html:6
msgid "Max Length"
msgstr ""
#: netbox/templates/ipam/inc/panels/fhrp_groups.html:10 #: netbox/templates/ipam/inc/panels/fhrp_groups.html:10
msgid "Create Group" msgid "Create Group"
msgstr "" msgstr ""
@@ -15184,14 +15192,6 @@ msgstr ""
msgid "Hide Depth Indicators" msgid "Hide Depth Indicators"
msgstr "" msgstr ""
#: netbox/templates/ipam/prefix_list.html:11
msgid "Max Depth"
msgstr ""
#: netbox/templates/ipam/prefix_list.html:28
msgid "Max Length"
msgstr ""
#: netbox/templates/ipam/rir.html:10 #: netbox/templates/ipam/rir.html:10
msgid "Add Aggregate" msgid "Add Aggregate"
msgstr "" msgstr ""

View File

@@ -252,3 +252,16 @@ def isodatetime(value, spec='seconds'):
else: else:
return '' return ''
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>') return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
@register.filter
def truncate_middle(value, length):
if len(value) <= length:
return value
# Calculate split points for the two parts
half_len = (length - 1) // 2 # 1 for the ellipsis
first_part = value[:half_len]
second_part = value[len(value) - (length - 1 - half_len):]
return mark_safe(f"{first_part}&hellip;{second_part}")