Skip to content

Commit

Permalink
Merge pull request #6755 from netbox-community/6000-cable-trace-svg
Browse files Browse the repository at this point in the history
Closes #6000: SVG rendering for cable tracing
  • Loading branch information
jeremystretch authored Jul 16, 2021
2 parents 337f95e + 145be09 commit 2bfdaf0
Show file tree
Hide file tree
Showing 17 changed files with 620 additions and 368 deletions.
12 changes: 8 additions & 4 deletions netbox/dcim/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
from collections import OrderedDict

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import F
from django.http import HttpResponseForbidden, HttpResponse
from django.shortcuts import get_object_or_404
from drf_yasg import openapi
from drf_yasg.openapi import Parameter
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.mixins import ListModelMixin
from rest_framework.response import Response
from rest_framework.routers import APIRootView
from rest_framework.viewsets import GenericViewSet, ViewSet
from rest_framework.viewsets import ViewSet

from circuits.models import Circuit
from dcim import filtersets
Expand Down Expand Up @@ -53,6 +50,13 @@ def trace(self, request, pk):
# Initialize the path array
path = []

if request.GET.get('render', None) == 'svg':
# Render SVG
drawing = obj.get_trace_svg(
base_url=request.build_absolute_uri('/')
)
return HttpResponse(drawing.tostring(), content_type='image/svg+xml')

for near_end, cable, far_end in obj.trace():
if near_end is None:
# Split paths
Expand Down
233 changes: 0 additions & 233 deletions netbox/dcim/elevations.py

This file was deleted.

5 changes: 5 additions & 0 deletions netbox/dcim/models/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dcim.choices import *
from dcim.constants import *
from dcim.fields import MACAddressField
from dcim.svg import CableTraceSVG
from extras.utils import extras_features
from netbox.models import PrimaryModel
from utilities.fields import ColorField, NaturalOrderingField
Expand Down Expand Up @@ -193,6 +194,10 @@ def trace(self):
# Return the path as a list of three-tuples (A termination, cable, B termination)
return list(zip(*[iter(path)] * 3))

def get_trace_svg(self, base_url=None):
trace = CableTraceSVG(self, base_url=base_url)
return trace.render()

@property
def path(self):
return self._path
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/models/racks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from dcim.choices import *
from dcim.constants import *
from dcim.elevations import RackElevationSVG
from dcim.svg import RackElevationSVG
from extras.utils import extras_features
from netbox.models import OrganizationalModel, PrimaryModel
from utilities.choices import ColorChoices
Expand Down
Loading

0 comments on commit 2bfdaf0

Please sign in to comment.