1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Merge pull request #1598 from candlerb/candlerb/1498

Avoid creating repeated graph nodes where device matches multiple regexps
This commit is contained in:
Jeremy Stretch
2017-10-16 17:16:46 -04:00
committed by GitHub

View File

@ -274,6 +274,7 @@ class TopologyMap(models.Model):
# Construct the graph # Construct the graph
graph = graphviz.Graph() graph = graphviz.Graph()
graph.graph_attr['ranksep'] = '1' graph.graph_attr['ranksep'] = '1'
seen = set()
for i, device_set in enumerate(self.device_sets): for i, device_set in enumerate(self.device_sets):
subgraph = graphviz.Graph(name='sg{}'.format(i)) subgraph = graphviz.Graph(name='sg{}'.format(i))
@ -288,6 +289,9 @@ class TopologyMap(models.Model):
devices = [] devices = []
for query in device_set.strip(';').split(';'): # Split regexes on semicolons for query in device_set.strip(';').split(';'): # Split regexes on semicolons
devices += Device.objects.filter(name__regex=query).select_related('device_role') devices += Device.objects.filter(name__regex=query).select_related('device_role')
# Remove duplicate devices
devices = [d for d in devices if d.id not in seen]
seen.update([d.id for d in devices])
for d in devices: for d in devices:
bg_color = '#{}'.format(d.device_role.color) bg_color = '#{}'.format(d.device_role.color)
fg_color = '#{}'.format(foreground_color(d.device_role.color)) fg_color = '#{}'.format(foreground_color(d.device_role.color))