Skip to content

Commit

Permalink
Closes #1180: Simplified the process of finding related devices when …
Browse files Browse the repository at this point in the history
…viewing a device
  • Loading branch information
jeremystretch committed Jun 9, 2017
1 parent 08883d8 commit cfff69a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
from copy import deepcopy
from difflib import SequenceMatcher
import re
from natsort import natsorted
from operator import attrgetter
Expand Down Expand Up @@ -776,20 +777,14 @@ def get(self, request, pk):
services = Service.objects.filter(device=device)
secrets = device.secrets.all()

# Find any related devices for convenient linking in the UI
related_devices = []
if device.name:
if re.match('.+[0-9]+$', device.name):
# Strip 1 or more trailing digits (e.g. core-switch1)
base_name = re.match('(.*?)[0-9]+$', device.name).group(1)
elif re.match('.+\d[a-z]$', device.name.lower()):
# Strip a trailing letter if preceded by a digit (e.g. dist-switch3a -> dist-switch3)
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]
# Find up to ten devices in the same site with the same functional role for quick reference.
related_devices = Device.objects.filter(
site=device.site, device_role=device.device_role
).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_graphs = Graph.objects.filter(type=GRAPH_TYPE_INTERFACE).exists()
Expand Down

0 comments on commit cfff69a

Please sign in to comment.