HTML cleanup and add copy-to-clipboard button

This commit is contained in:
Brian Tiemann 2024-11-14 18:10:32 -05:00
parent b0663305b7
commit 4655372585
5 changed files with 25 additions and 46 deletions

View File

@ -43,6 +43,16 @@ MODULEBAY_STATUS = """
{% badge record.installed_module.get_status_display bg_color=record.installed_module.get_status_color %}
"""
MACADDRESS_LINK = """
{% if record.pk %}
<a href="{{ record.get_absolute_url }}" id="macaddress_{{ record.pk }}">{{ record.mac_address }}</a>
{% endif %}
"""
MACADDRESS_COPY_BUTTON = """
{% copy_content record.pk prefix="macaddress_" %}
"""
#
# Device roles
@ -599,9 +609,9 @@ class BaseInterfaceTable(NetBoxTable):
class MACAddressTable(NetBoxTable):
mac_address = tables.Column(
verbose_name=_('MAC Address'),
linkify=True
mac_address = tables.TemplateColumn(
template_code=MACADDRESS_LINK,
verbose_name=_('MAC Address')
)
assigned_object = tables.Column(
linkify=True,
@ -625,6 +635,9 @@ class MACAddressTable(NetBoxTable):
tags = columns.TagColumn(
url_name='dcim:macaddress_list'
)
actions = columns.ActionsColumn(
extra_buttons=MACADDRESS_COPY_BUTTON
)
class Meta(DeviceComponentTable.Meta):
model = models.MACAddress

View File

@ -2548,7 +2548,6 @@ class MACAddressListView(generic.ObjectListView):
filterset = filtersets.MACAddressFilterSet
filterset_form = forms.MACAddressFilterForm
table = tables.MACAddressTable
template_name = 'dcim/component_list.html'
@register_model_view(MACAddress)
@ -2632,13 +2631,6 @@ class InterfaceView(generic.ObjectView):
orderable=False
)
# Get MAC addresses
mac_addresses_table = tables.MACAddressTable(
data=instance.mac_addresses,
exclude=('assigned_object',),
orderable=False
)
# Get assigned VLANs and annotate whether each is tagged or untagged
vlans = []
if instance.untagged_vlan is not None:
@ -2665,7 +2657,6 @@ class InterfaceView(generic.ObjectView):
'vdc_table': vdc_table,
'bridge_interfaces_table': bridge_interfaces_table,
'child_interfaces_table': child_interfaces_table,
'mac_addresses_table': mac_addresses_table,
'vlan_table': vlan_table,
'vlan_translation_table': vlan_translation_table,
}

View File

@ -358,7 +358,7 @@
<div class="card">
<h2 class="card-header">
{% trans "MAC Addresses" %}
{% if perms.ipam.add_macaddress %}
{% if perms.dcim.add_macaddress %}
<div class="card-actions">
<a href="{% url 'dcim:macaddress_add' %}?device={{ object.device.pk }}&interface={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-ghost-primary btn-sm">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> {% trans "Add MAC Address" %}

View File

@ -10,6 +10,13 @@
<div class="card">
<h2 class="card-header">{% trans "MAC Address" %}</h2>
<table class="table table-hover attr-table">
<tr>
<th scope="row">{% trans "MAC Address" %}</th>
<td>
<span id="macaddress_{{ object.pk }}">{{ object.mac_address|placeholder }}</span>
{% copy_content object.pk prefix="macaddress_" %}
</td>
</tr>
<tr>
<th scope="row">{% trans "Description" %}</th>
<td>{{ object.description|placeholder }}</td>
@ -18,9 +25,7 @@
<th scope="row">{% trans "Assignment" %}</th>
<td>
{% if object.assigned_object %}
{% if object.assigned_object.parent_object %}
{{ object.assigned_object.parent_object|linkify }} /
{% endif %}
{{ object.assigned_object.parent_object|linkify }} /
{{ object.assigned_object|linkify }}
{% else %}
{{ ''|placeholder }}

View File

@ -1,30 +0,0 @@
{% extends 'generic/object_edit.html' %}
{% load static %}
{% load form_helpers %}
{% load i18n %}
{% block title %}{% trans "Bulk Add MAC Addresses" %}{% endblock %}
{% block tabs %}
{% include 'ipam/inc/ipaddress_edit_header.html' with active_tab='bulk_add' %}
{% endblock %}
{% block form %}
<div class="field-group my-5">
<div class="row">
<h2 class="col-9 offset-3">{% trans "MAC Addresses" %}</h2>
</div>
{% render_field form.pattern %}
{% render_field model_form.description %}
{% render_field model_form.tags %}
</div>
{% if model_form.custom_fields %}
<div class="field-group my-5">
<div class="row">
<h2 class="col-9 offset-3">{% trans "Custom Fields" %}</h2>
</div>
{% render_custom_fields model_form %}
</div>
{% endif %}
{% endblock %}