mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
change render_format to render for svg elevations
This commit is contained in:
parent
77a5f6ef81
commit
645383509b
@ -109,7 +109,7 @@ deprecated and will be removed in v2.8 (see [#3753](https://github.com/netbox-co
|
|||||||
/api/dcim/racks/<id>/units/
|
/api/dcim/racks/<id>/units/
|
||||||
```
|
```
|
||||||
|
|
||||||
In order to render the elevation as an SVG, include the `render_format=svg` query parameter in the request. You may also
|
In order to render the elevation as an SVG, include the `render=svg` query parameter in the request. You may also
|
||||||
control the width of the elevation drawing in pixels with `unit_width=<width in pixels>` and the height of each rack
|
control the width of the elevation drawing in pixels with `unit_width=<width in pixels>` and the height of each rack
|
||||||
unit with `unit_height=<height in pixels>`. The `unit_width` defaults to `230` and the `unit_height` default to `20`
|
unit with `unit_height=<height in pixels>`. The `unit_width` defaults to `230` and the `unit_height` default to `20`
|
||||||
which produces elevations the same size as those that appear in the NetBox Web UI. The query parameter `face` is used to
|
which produces elevations the same size as those that appear in the NetBox Web UI. The query parameter `face` is used to
|
||||||
@ -119,14 +119,14 @@ Here is an example of the request url for an SVG rendering using the default par
|
|||||||
elevation:
|
elevation:
|
||||||
|
|
||||||
```
|
```
|
||||||
/api/dcim/racks/<id>/elevation/?render_format=svg
|
/api/dcim/racks/<id>/elevation/?render=svg
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is an example of the request url for an SVG rendering of the rear of the elevation having a width of 300 pixels and
|
Here is an example of the request url for an SVG rendering of the rear of the elevation having a width of 300 pixels and
|
||||||
per unit height of 35 pixels:
|
per unit height of 35 pixels:
|
||||||
|
|
||||||
```
|
```
|
||||||
/api/dcim/racks/<id>/elevation/?render_format=svg&face=rear&unit_width=300&unit_height=35
|
/api/dcim/racks/<id>/elevation/?render=svg&face=rear&unit_width=300&unit_height=35
|
||||||
```
|
```
|
||||||
|
|
||||||
Thanks to [@hellerve](https://github.com/hellerve) for doing the heavy lifting on this!
|
Thanks to [@hellerve](https://github.com/hellerve) for doing the heavy lifting on this!
|
||||||
|
@ -176,9 +176,9 @@ class RackElevationDetailFilterSerializer(serializers.Serializer):
|
|||||||
choices=DeviceFaceChoices,
|
choices=DeviceFaceChoices,
|
||||||
default=DeviceFaceChoices.FACE_FRONT
|
default=DeviceFaceChoices.FACE_FRONT
|
||||||
)
|
)
|
||||||
render_format = serializers.ChoiceField(
|
render = serializers.ChoiceField(
|
||||||
choices=RackElevationDetailRenderFormatChoices,
|
choices=RackElevationDetailRenderChoices,
|
||||||
default=RackElevationDetailRenderFormatChoices.RENDER_FORMAT_JSON
|
default=RackElevationDetailRenderChoices.RENDER_JSON
|
||||||
)
|
)
|
||||||
unit_width = serializers.IntegerField(
|
unit_width = serializers.IntegerField(
|
||||||
default=RACK_ELEVATION_UNIT_WIDTH_DEFAULT
|
default=RACK_ELEVATION_UNIT_WIDTH_DEFAULT
|
||||||
|
@ -218,7 +218,7 @@ class RackViewSet(CustomFieldModelViewSet):
|
|||||||
return Response(serializer.errors, 400)
|
return Response(serializer.errors, 400)
|
||||||
data = serializer.validated_data
|
data = serializer.validated_data
|
||||||
|
|
||||||
if data['render_format'] == 'svg':
|
if data['render'] == 'svg':
|
||||||
# Render and return the elevation as an SVG drawing with the correct content type
|
# Render and return the elevation as an SVG drawing with the correct content type
|
||||||
drawing = rack.get_elevation_svg(data['face'], data['unit_width'], data['unit_height'])
|
drawing = rack.get_elevation_svg(data['face'], data['unit_width'], data['unit_height'])
|
||||||
return HttpResponse(drawing.tostring(), content_type='image/svg+xml')
|
return HttpResponse(drawing.tostring(), content_type='image/svg+xml')
|
||||||
|
@ -105,14 +105,14 @@ class RackDimensionUnitChoices(ChoiceSet):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RackElevationDetailRenderFormatChoices(ChoiceSet):
|
class RackElevationDetailRenderChoices(ChoiceSet):
|
||||||
|
|
||||||
RENDER_FORMAT_JSON = 'json'
|
RENDER_JSON = 'json'
|
||||||
RENDER_FORMAT_SVG = 'svg'
|
RENDER_SVG = 'svg'
|
||||||
|
|
||||||
CHOICES = (
|
CHOICES = (
|
||||||
(RENDER_FORMAT_JSON, 'json'),
|
(RENDER_JSON, 'json'),
|
||||||
(RENDER_FORMAT_SVG, 'svg')
|
(RENDER_SVG, 'svg')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user