Use separate templates for front and rear port mappings

This commit is contained in:
Jeremy Stretch
2026-03-19 10:55:34 -04:00
parent d194c804a3
commit 0f9491a9a8
5 changed files with 60 additions and 71 deletions
-26
View File
@@ -416,32 +416,6 @@ class InventoryItemsPanel(panels.ObjectPanel):
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
class PortMappingsPanel(panels.ObjectPanel):
"""
A panel which displays port position mappings for front/rear ports.
"""
template_name = 'dcim/panels/port_mappings.html'
title = _('Port Mappings')
def __init__(self, context_key, label_column, position_field, port_field, port_position_field, **kwargs):
super().__init__(**kwargs)
self.context_key = context_key
self.label_column = label_column
self.position_field = position_field
self.port_field = port_field
self.port_position_field = port_position_field
def get_context(self, context):
return {
**super().get_context(context),
'mappings': context.get(self.context_key, []),
'label_column': self.label_column,
'position_field': self.position_field,
'port_field': self.port_field,
'port_position_field': self.port_position_field,
}
class VirtualChassisMembersPanel(panels.ObjectPanel):
"""
A panel which lists all members of a virtual chassis.
+2 -14
View File
@@ -3466,13 +3466,7 @@ class FrontPortView(generic.ObjectView):
},
],
),
panels.PortMappingsPanel(
context_key='rear_port_mappings',
label_column=_('Rear Port'),
position_field='front_port_position',
port_field='rear_port',
port_position_field='rear_port_position',
),
TemplatePanel('dcim/panels/front_port_mappings.html'),
],
)
@@ -3573,13 +3567,7 @@ class RearPortView(generic.ObjectView):
},
],
),
panels.PortMappingsPanel(
context_key='front_port_mappings',
label_column=_('Front Port'),
position_field='rear_port_position',
port_field='front_port',
port_position_field='front_port_position',
),
TemplatePanel('dcim/panels/rear_port_mappings.html'),
],
)
@@ -0,0 +1,29 @@
{% load i18n %}
<div class="card">
<h2 class="card-header">{% trans "Port Mappings" %}</h2>
<table class="table table-hover">
{% if rear_port_mappings %}
<thead>
<tr>
<th>{% trans "Position" %}</th>
<th>{% trans "Rear Port" %}</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for mapping in rear_port_mappings %}
<tr>
<td>{{ mapping.front_port_position }}</td>
<td>
<a href="{{ mapping.rear_port.get_absolute_url }}">{{ mapping.rear_port }}:{{ mapping.rear_port_position }}</a>
</td>
</tr>
{% empty %}
<tr>
<td class="text-muted">{% trans "No mappings defined" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
@@ -1,31 +0,0 @@
{% extends "ui/panels/_base.html" %}
{% load helpers i18n %}
{% block panel_content %}
<table class="table table-hover">
{% if mappings %}
<thead>
<tr>
<th>{% trans "Position" %}</th>
<th>{{ label_column }}</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for mapping in mappings %}
<tr>
{% with position=mapping|getattr:position_field port=mapping|getattr:port_field port_position=mapping|getattr:port_position_field %}
<td>{{ position }}</td>
<td>
<a href="{{ port.get_absolute_url }}">{{ port }}:{{ port_position }}</a>
</td>
{% endwith %}
</tr>
{% empty %}
<tr>
<td class="text-muted">{% trans "No mappings defined" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock panel_content %}
@@ -0,0 +1,29 @@
{% load i18n %}
<div class="card">
<h2 class="card-header">{% trans "Port Mappings" %}</h2>
<table class="table table-hover">
{% if front_port_mappings %}
<thead>
<tr>
<th>{% trans "Position" %}</th>
<th>{% trans "Front Port" %}</th>
</tr>
</thead>
{% endif %}
<tbody>
{% for mapping in front_port_mappings %}
<tr>
<td>{{ mapping.rear_port_position }}</td>
<td>
<a href="{{ mapping.front_port.get_absolute_url }}">{{ mapping.front_port }}:{{ mapping.front_port_position }}</a>
</td>
</tr>
{% empty %}
<tr>
<td class="text-muted">{% trans "No mappings defined" %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>