This commit is contained in:
Jeremy Stretch 2017-03-08 16:30:32 -05:00
parent a6ceaf8d96
commit c19725506d
2 changed files with 7 additions and 9 deletions

View File

@ -1,15 +1,13 @@
import graphviz
from rest_framework import generics
from rest_framework.decorators import detail_route
from rest_framework.viewsets import ModelViewSet
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
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.models import Graph, TopologyMap, GRAPH_TYPE_INTERFACE, GRAPH_TYPE_PROVIDER, GRAPH_TYPE_SITE
from utilities.api import WritableSerializerMixin
@ -83,17 +81,17 @@ class TopologyMapViewSet(WritableSerializerMixin, ModelViewSet):
def render(self, request, pk):
tmap = get_object_or_404(TopologyMap, pk=pk)
format = 'png'
img_format = 'png'
try:
data = tmap.render(format=format)
data = tmap.render(img_format=img_format)
except:
return HttpResponse(
"There was an error generating the requested graph. Ensure that the GraphViz executables have been "
"installed correctly."
)
response = HttpResponse(data, content_type='image/{}'.format(format))
response['Content-Disposition'] = 'inline; filename="{}.{}"'.format(tmap.slug, format)
response = HttpResponse(data, content_type='image/{}'.format(img_format))
response['Content-Disposition'] = 'inline; filename="{}.{}"'.format(tmap.slug, img_format)
return response

View File

@ -312,7 +312,7 @@ class TopologyMap(models.Model):
return None
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
@ -356,7 +356,7 @@ class TopologyMap(models.Model):
for c in connections:
graph.edge(c.interface_a.device.name, c.interface_b.device.name)
return graph.pipe(format=format)
return graph.pipe(format=img_format)
#