mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-14 06:17:03 +01:00
Consolidate wireless link interface templates into ObjectPanel subclass
Replace duplicate wirelesslink_interface_{a,b}.html templates with a
single shared template and WirelessLinkInterfacePanel(ObjectPanel)
subclass that injects the correct interface via get_context().
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
{% extends "ui/panels/_base.html" %}
|
||||
{% load helpers %}
|
||||
{% load i18n %}
|
||||
|
||||
<div class="card">
|
||||
<h2 class="card-header">{% trans "Interface" %} A</h2>
|
||||
{% block panel_content %}
|
||||
<table class="table table-hover attr-table">
|
||||
<tr>
|
||||
<th scope="row">{% trans "Device" %}</th>
|
||||
<td>{{ object.interface_a.device|linkify }}</td>
|
||||
<td>{{ interface.device|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Interface" %}</th>
|
||||
<td>{{ object.interface_a|linkify }}</td>
|
||||
<td>{{ interface|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Type" %}</th>
|
||||
<td>{{ object.interface_a.get_type_display }}</td>
|
||||
<td>{{ interface.get_type_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Role" %}</th>
|
||||
<td>{{ object.interface_a.get_rf_role_display|placeholder }}</td>
|
||||
<td>{{ interface.get_rf_role_display|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel" %}</th>
|
||||
<td>{{ object.interface_a.get_rf_channel_display|placeholder }}</td>
|
||||
<td>{{ interface.get_rf_channel_display|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel Frequency" %}</th>
|
||||
<td>
|
||||
{% if object.interface_a.rf_channel_frequency %}
|
||||
{{ object.interface_a.rf_channel_frequency|floatformat:"-2" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% if interface.rf_channel_frequency %}
|
||||
{{ interface.rf_channel_frequency|floatformat:"-2" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
@@ -37,12 +37,12 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel Width" %}</th>
|
||||
<td>
|
||||
{% if object.interface_a.rf_channel_width %}
|
||||
{{ object.interface_a.rf_channel_width|floatformat:"-3" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% if interface.rf_channel_width %}
|
||||
{{ interface.rf_channel_width|floatformat:"-3" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock panel_content %}
|
||||
@@ -1,48 +0,0 @@
|
||||
{% load helpers %}
|
||||
{% load i18n %}
|
||||
|
||||
<div class="card">
|
||||
<h2 class="card-header">{% trans "Interface" %} B</h2>
|
||||
<table class="table table-hover attr-table">
|
||||
<tr>
|
||||
<th scope="row">{% trans "Device" %}</th>
|
||||
<td>{{ object.interface_b.device|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Interface" %}</th>
|
||||
<td>{{ object.interface_b|linkify }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Type" %}</th>
|
||||
<td>{{ object.interface_b.get_type_display }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Role" %}</th>
|
||||
<td>{{ object.interface_b.get_rf_role_display|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel" %}</th>
|
||||
<td>{{ object.interface_b.get_rf_channel_display|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel Frequency" %}</th>
|
||||
<td>
|
||||
{% if object.interface_b.rf_channel_frequency %}
|
||||
{{ object.interface_b.rf_channel_frequency|floatformat:"-2" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Channel Width" %}</th>
|
||||
<td>
|
||||
{% if object.interface_b.rf_channel_width %}
|
||||
{{ object.interface_b.rf_channel_width|floatformat:"-3" }} {% trans "MHz" context "Abbreviation for megahertz" %}
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -25,6 +25,22 @@ class WirelessLANAuthenticationPanel(panels.ObjectAttributesPanel):
|
||||
auth_psk = attrs.TemplatedAttr('auth_psk', label=_('PSK'), template_name='wireless/attrs/auth_psk.html')
|
||||
|
||||
|
||||
class WirelessLinkInterfacePanel(panels.ObjectPanel):
|
||||
template_name = 'wireless/panels/wirelesslink_interface.html'
|
||||
|
||||
def __init__(self, accessor, title, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.accessor = accessor
|
||||
self.title = title
|
||||
|
||||
def get_context(self, context):
|
||||
obj = context['object']
|
||||
return {
|
||||
**super().get_context(context),
|
||||
'interface': getattr(obj, self.accessor),
|
||||
}
|
||||
|
||||
|
||||
class WirelessLinkPropertiesPanel(panels.ObjectAttributesPanel):
|
||||
title = _('Link Properties')
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ from netbox.ui.panels import (
|
||||
ObjectsTablePanel,
|
||||
PluginContentPanel,
|
||||
RelatedObjectsPanel,
|
||||
TemplatePanel,
|
||||
)
|
||||
from netbox.views import generic
|
||||
from utilities.query import count_related
|
||||
@@ -223,14 +222,14 @@ class WirelessLinkView(generic.ObjectView):
|
||||
layout = layout.Layout(
|
||||
Row(
|
||||
Column(
|
||||
TemplatePanel('wireless/panels/wirelesslink_interface_a.html'),
|
||||
panels.WirelessLinkInterfacePanel('interface_a', title=_('Interface A')),
|
||||
panels.WirelessLinkPropertiesPanel(),
|
||||
TagsPanel(),
|
||||
CommentsPanel(),
|
||||
PluginContentPanel('left_page'),
|
||||
),
|
||||
Column(
|
||||
TemplatePanel('wireless/panels/wirelesslink_interface_b.html'),
|
||||
panels.WirelessLinkInterfacePanel('interface_b', title=_('Interface B')),
|
||||
panels.WirelessLANAuthenticationPanel(),
|
||||
CustomFieldsPanel(),
|
||||
PluginContentPanel('right_page'),
|
||||
|
||||
Reference in New Issue
Block a user