Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6000: SVG rendering for cable tracing #6755

Merged
merged 6 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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