mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 03:27:21 -06:00
Closes #1180: Simplified the process of finding related devices when viewing a device
This commit is contained in:
parent
08883d86ef
commit
cfff69a715
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from difflib import SequenceMatcher
|
||||||
import re
|
import re
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
@ -776,20 +777,14 @@ class DeviceView(View):
|
|||||||
services = Service.objects.filter(device=device)
|
services = Service.objects.filter(device=device)
|
||||||
secrets = device.secrets.all()
|
secrets = device.secrets.all()
|
||||||
|
|
||||||
# Find any related devices for convenient linking in the UI
|
# Find up to ten devices in the same site with the same functional role for quick reference.
|
||||||
related_devices = []
|
related_devices = Device.objects.filter(
|
||||||
if device.name:
|
site=device.site, device_role=device.device_role
|
||||||
if re.match('.+[0-9]+$', device.name):
|
).exclude(
|
||||||
# Strip 1 or more trailing digits (e.g. core-switch1)
|
pk=device.pk
|
||||||
base_name = re.match('(.*?)[0-9]+$', device.name).group(1)
|
).select_related(
|
||||||
elif re.match('.+\d[a-z]$', device.name.lower()):
|
'rack', 'device_type__manufacturer'
|
||||||
# Strip a trailing letter if preceded by a digit (e.g. dist-switch3a -> dist-switch3)
|
)[:10]
|
||||||
base_name = re.match('(.*\d+)[a-z]$', device.name.lower()).group(1)
|
|
||||||
else:
|
|
||||||
base_name = None
|
|
||||||
if base_name:
|
|
||||||
related_devices = Device.objects.filter(name__istartswith=base_name).exclude(pk=device.pk)\
|
|
||||||
.select_related('rack', 'device_type__manufacturer')[:10]
|
|
||||||
|
|
||||||
# Show graph button on interfaces only if at least one graph has been created.
|
# Show graph button on interfaces only if at least one graph has been created.
|
||||||
show_graphs = Graph.objects.filter(type=GRAPH_TYPE_INTERFACE).exists()
|
show_graphs = Graph.objects.filter(type=GRAPH_TYPE_INTERFACE).exists()
|
||||||
|
Loading…
Reference in New Issue
Block a user