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

Support specification of image width when rendering cable traces as SVG

This commit is contained in:
jeremystretch
2021-07-16 17:06:27 -04:00
parent 2bfdaf08ee
commit 8cf9f0d5bc
2 changed files with 11 additions and 3 deletions

View File

@ -52,8 +52,13 @@ class PathEndpointMixin(object):
if request.GET.get('render', None) == 'svg': if request.GET.get('render', None) == 'svg':
# Render SVG # Render SVG
try:
width = min(int(request.GET.get('width')), 1600)
except ValueError:
width = None
drawing = obj.get_trace_svg( drawing = obj.get_trace_svg(
base_url=request.build_absolute_uri('/') base_url=request.build_absolute_uri('/'),
width=width
) )
return HttpResponse(drawing.tostring(), content_type='image/svg+xml') return HttpResponse(drawing.tostring(), content_type='image/svg+xml')

View File

@ -194,8 +194,11 @@ class PathEndpoint(models.Model):
# Return the path as a list of three-tuples (A termination, cable, B termination) # Return the path as a list of three-tuples (A termination, cable, B termination)
return list(zip(*[iter(path)] * 3)) return list(zip(*[iter(path)] * 3))
def get_trace_svg(self, base_url=None): def get_trace_svg(self, base_url=None, width=None):
trace = CableTraceSVG(self, base_url=base_url) if width is not None:
trace = CableTraceSVG(self, base_url=base_url, width=width)
else:
trace = CableTraceSVG(self, base_url=base_url)
return trace.render() return trace.render()
@property @property