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

Fix CablePath serialization for pass-through port paths

This commit is contained in:
jeremystretch
2022-07-08 13:55:13 -04:00
parent ac4a87de13
commit f386ec82ae
2 changed files with 6 additions and 30 deletions

View File

@@ -27,6 +27,8 @@
| `connected_endpoint_type` | string | `connected_endpoints_type` | string |
| `connected_endpoint_reachable` | boolean | `connected_endpoints_reachable` | boolean |
* The cable path serialization returned by the `/paths/` endpoint for pass-through ports has been simplified, and the following fields removed: `origin_type`, `origin`, `destination_type`, `destination`. (Additionally, `is_complete` has been added.)
### New Features
#### Half-Height Rack Units ([#51](https://github.com/netbox-community/netbox/issues/51))

View File

@@ -1081,45 +1081,19 @@ class CableTerminationSerializer(NetBoxModelSerializer):
class CablePathSerializer(serializers.ModelSerializer):
origin_type = ContentTypeField(read_only=True)
origin = serializers.SerializerMethodField(read_only=True)
destination_type = ContentTypeField(read_only=True)
destination = serializers.SerializerMethodField(read_only=True)
path = serializers.SerializerMethodField(read_only=True)
class Meta:
model = CablePath
fields = [
'id', 'origin_type', 'origin', 'destination_type', 'destination', 'path', 'is_active', 'is_split',
]
@swagger_serializer_method(serializer_or_field=serializers.DictField)
def get_origin(self, obj):
"""
Return the appropriate serializer for the origin.
"""
serializer = get_serializer_for_model(obj.origin, prefix='Nested')
context = {'request': self.context['request']}
return serializer(obj.origin, context=context).data
@swagger_serializer_method(serializer_or_field=serializers.DictField)
def get_destination(self, obj):
"""
Return the appropriate serializer for the destination, if any.
"""
if obj.destination_id is not None:
serializer = get_serializer_for_model(obj.destination, prefix='Nested')
context = {'request': self.context['request']}
return serializer(obj.destination, context=context).data
return None
fields = ['id', 'path', 'is_active', 'is_complete', 'is_split']
@swagger_serializer_method(serializer_or_field=serializers.ListField)
def get_path(self, obj):
ret = []
for node in obj.path_objects():
serializer = get_serializer_for_model(node, prefix='Nested')
for nodes in obj.path_objects:
serializer = get_serializer_for_model(nodes[0], prefix='Nested')
context = {'request': self.context['request']}
ret.append(serializer(node, context=context).data)
ret.append(serializer(nodes, context=context, many=True).data)
return ret