mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Cleanup
This commit is contained in:
parent
a6ceaf8d96
commit
c19725506d
@ -1,15 +1,13 @@
|
|||||||
import graphviz
|
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import Q
|
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from circuits.models import Provider
|
from circuits.models import Provider
|
||||||
from dcim.models import Site, Device, Interface, InterfaceConnection
|
from dcim.models import Site, Interface
|
||||||
from extras import filters
|
from extras import filters
|
||||||
from extras.models import Graph, TopologyMap, GRAPH_TYPE_INTERFACE, GRAPH_TYPE_PROVIDER, GRAPH_TYPE_SITE
|
from extras.models import Graph, TopologyMap, GRAPH_TYPE_INTERFACE, GRAPH_TYPE_PROVIDER, GRAPH_TYPE_SITE
|
||||||
from utilities.api import WritableSerializerMixin
|
from utilities.api import WritableSerializerMixin
|
||||||
@ -83,17 +81,17 @@ class TopologyMapViewSet(WritableSerializerMixin, ModelViewSet):
|
|||||||
def render(self, request, pk):
|
def render(self, request, pk):
|
||||||
|
|
||||||
tmap = get_object_or_404(TopologyMap, pk=pk)
|
tmap = get_object_or_404(TopologyMap, pk=pk)
|
||||||
format = 'png'
|
img_format = 'png'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = tmap.render(format=format)
|
data = tmap.render(img_format=img_format)
|
||||||
except:
|
except:
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
"There was an error generating the requested graph. Ensure that the GraphViz executables have been "
|
"There was an error generating the requested graph. Ensure that the GraphViz executables have been "
|
||||||
"installed correctly."
|
"installed correctly."
|
||||||
)
|
)
|
||||||
|
|
||||||
response = HttpResponse(data, content_type='image/{}'.format(format))
|
response = HttpResponse(data, content_type='image/{}'.format(img_format))
|
||||||
response['Content-Disposition'] = 'inline; filename="{}.{}"'.format(tmap.slug, format)
|
response['Content-Disposition'] = 'inline; filename="{}.{}"'.format(tmap.slug, img_format)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -312,7 +312,7 @@ class TopologyMap(models.Model):
|
|||||||
return None
|
return None
|
||||||
return [line.strip() for line in self.device_patterns.split('\n')]
|
return [line.strip() for line in self.device_patterns.split('\n')]
|
||||||
|
|
||||||
def render(self, format='png'):
|
def render(self, img_format='png'):
|
||||||
|
|
||||||
from dcim.models import Device, InterfaceConnection
|
from dcim.models import Device, InterfaceConnection
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ class TopologyMap(models.Model):
|
|||||||
for c in connections:
|
for c in connections:
|
||||||
graph.edge(c.interface_a.device.name, c.interface_b.device.name)
|
graph.edge(c.interface_a.device.name, c.interface_b.device.name)
|
||||||
|
|
||||||
return graph.pipe(format=format)
|
return graph.pipe(format=img_format)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user