This commit is contained in:
jeremystretch 2021-10-15 12:24:07 -04:00
parent 075f4907ef
commit 717fd760df
7 changed files with 124 additions and 36 deletions

View File

@ -16,7 +16,7 @@ from utilities.forms import (
SlugField, StaticSelect,
)
from virtualization.models import Cluster, ClusterGroup
from wireless.models import WirelessLAN
from wireless.models import WirelessLAN, WirelessLANGroup
from .common import InterfaceCommonForm
__all__ = (
@ -1073,10 +1073,18 @@ class InterfaceForm(BootstrapMixin, InterfaceCommonForm, CustomFieldModelForm):
'type': 'lag',
}
)
wireless_lan_group = DynamicModelChoiceField(
queryset=WirelessLANGroup.objects.all(),
required=False,
label='Wireless LAN group'
)
wireless_lans = DynamicModelMultipleChoiceField(
queryset=WirelessLAN.objects.all(),
required=False,
label='Wireless LANs'
label='Wireless LANs',
query_params={
'group_id': '$wireless_lan_group',
}
)
vlan_group = DynamicModelChoiceField(
queryset=VLANGroup.objects.all(),

View File

@ -505,8 +505,8 @@ class InterfaceTable(DeviceComponentTable, BaseInterfaceTable, PathEndpointTable
class DeviceInterfaceTable(InterfaceTable):
name = tables.TemplateColumn(
template_code='<i class="mdi mdi-{% if iface.mgmt_only %}wrench{% elif iface.is_lag %}drag-horizontal-variant'
'{% elif iface.is_virtual %}circle{% elif iface.is_wireless %}wifi{% else %}ethernet'
template_code='<i class="mdi mdi-{% if record.mgmt_only %}wrench{% elif record.is_lag %}drag-horizontal-variant'
'{% elif record.is_virtual %}circle{% elif record.is_wireless %}wifi{% else %}ethernet'
'{% endif %}"></i> <a href="{{ record.get_absolute_url }}">{{ value }}</a>',
order_by=Accessor('_name'),
attrs={'td': {'class': 'text-nowrap'}}

View File

@ -205,6 +205,12 @@ INTERFACE_BUTTONS = """
<i class="mdi mdi-ethernet-cable-off" aria-hidden="true"></i>
</a>
{% endif %}
{% elif record.wireless_link %}
{% if perms.wireless.delete_wirelesslink %}
<a href="{% url 'wireless:wirelesslink_delete' pk=record.wireless_link.pk %}?return_url={% url 'dcim:device_interfaces' pk=object.pk %}" title="Delete wireless link" class="btn btn-danger btn-sm">
<i class="mdi mdi-wifi-off" aria-hidden="true"></i>
</a>
{% endif %}
{% elif record.is_wired and perms.dcim.add_cable %}
<a href="#" class="btn btn-outline-dark btn-sm disabled"><i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i></a>
<a href="#" class="btn btn-outline-dark btn-sm disabled"><i class="mdi mdi-lan-connect" aria-hidden="true"></i></a>
@ -223,6 +229,10 @@ INTERFACE_BUTTONS = """
{% else %}
<a href="#" class="btn btn-outline-dark btn-sm disabled"><i class="mdi mdi-ethernet-cable" aria-hidden="true"></i></a>
{% endif %}
{% elif record.is_wireless and perms.wireless.add_wirelesslink %}
<a href="{% url 'wireless:wirelesslink_add' %}?interface_a={{ record.pk }}" class="btn btn-success btn-sm">
<span class="mdi mdi-wifi" aria-hidden="true"></span>
</a>
{% endif %}
"""

View File

@ -217,8 +217,29 @@
<th scope="row">Wireless Link</th>
<td>
<a href="{{ object.wireless_link.get_absolute_url }}">{{ object.wireless_link }}</a>
<a href="{% url 'dcim:interface_trace' pk=object.pk %}" class="btn btn-primary btn-sm lh-1" title="Trace">
<i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
</a>
</td>
</tr>
{% with peer_interface=object.connected_endpoint %}
<tr>
<th scope="row">Device</th>
<td>
<a href="{{ peer_interface.device.get_absolute_url }}">{{ peer_interface.device }}</a>
</td>
</tr>
<tr>
<th scope="row">Name</th>
<td>
<a href="{{ peer_interface.get_absolute_url }}">{{ peer_interface }}</a>
</td>
</tr>
<tr>
<th scope="row">Type</th>
<td>{{ peer_interface.get_type_display }}</td>
</tr>
{% endwith %}
</table>
{% else %}
<div class="text-muted">
@ -267,36 +288,73 @@
<div class="card">
<h5 class="card-header">Wireless</h5>
<div class="card-body">
<table class="table table-hover">
<tr>
<th scope="row">Role</th>
<td>{{ object.get_rf_role_display|placeholder }}</td>
</tr>
<tr>
<th scope="row">Channel</th>
<td>{{ object.get_rf_channel_display|placeholder }}</td>
</tr>
<tr>
<th scope="row">Channel Frequency</th>
<td>
{% if object.rf_channel_frequency %}
{{ object.rf_channel_frequency|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
</tr>
<tr>
<th scope="row">Channel Width</th>
<td>
{% if object.rf_channel_width %}
{{ object.rf_channel_width|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
</tr>
</table>
{% with peer=object.connected_endpoint %}
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>Local</th>
{% if peer %}
<th>Peer</th>
{% endif %}
</tr>
</thead>
<tr>
<th scope="row">Role</th>
<td>{{ object.get_rf_role_display|placeholder }}</td>
{% if peer %}
<td>{{ peer.get_rf_role_display|placeholder }}</td>
{% endif %}
</tr>
<tr>
<th scope="row">Channel</th>
<td>{{ object.get_rf_channel_display|placeholder }}</td>
{% if peer %}
<td{% if peer.rf_channel != object.rf_channel %} class="text-danger"{% endif %}>
{{ peer.get_rf_channel_display|placeholder }}
</td>
{% endif %}
</tr>
<tr>
<th scope="row">Channel Frequency</th>
<td>
{% if object.rf_channel_frequency %}
{{ object.rf_channel_frequency|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
{% if peer %}
<td{% if peer.rf_channel_frequency != object.rf_channel_frequency %} class="text-danger"{% endif %}>
{% if peer.rf_channel_frequency %}
{{ peer.rf_channel_frequency|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
{% endif %}
</tr>
<tr>
<th scope="row">Channel Width</th>
<td>
{% if object.rf_channel_width %}
{{ object.rf_channel_width|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
{% if peer %}
<td{% if peer.rf_channel_width != object.rf_channel_width %} class="text-danger"{% endif %}>
{% if peer.rf_channel_width %}
{{ peer.rf_channel_width|simplify_decimal }} MHz
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
{% endif %}
</tr>
</table>
{% endwith %}
</div>
</div>
<div class="card">
@ -305,12 +363,20 @@
<table class="table table-hover table-headings">
<thead>
<tr>
<th>Group</th>
<th>SSID</th>
</tr>
</thead>
<tbody>
{% for wlan in object.wlans.all %}
{% for wlan in object.wireless_lans.all %}
<tr>
<td>
{% if wlan.group %}
<a href="{{ wlan.group.get_absolute_url }}">{{ wlan.group }}</a>
{% else %}
&mdash;
{% endif %}
</td>
<td>
<a href="{{ wlan.get_absolute_url }}">{{ wlan.ssid }}</a>
</td>

View File

@ -38,6 +38,7 @@
{% render_field form.rf_channel %}
{% render_field form.rf_channel_frequency %}
{% render_field form.rf_channel_width %}
{% render_field form.wireless_lan_group %}
{% render_field form.wireless_lans %}
</div>
{% endif %}

View File

@ -157,7 +157,7 @@ def simplify_decimal(value):
"""
if type(value) is not decimal.Decimal:
return value
return str(value).rstrip('0.')
return str(value).rstrip('0').rstrip('.')
@register.filter()

View File

@ -33,6 +33,9 @@ class WirelessLANFilterSet(PrimaryModelFilterSet):
method='search',
label='Search',
)
group_id = django_filters.ModelMultipleChoiceFilter(
queryset=WirelessLANGroup.objects.all()
)
tag = TagFilter()
class Meta: