mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 10:16:42 -06:00
Fix CablePath serialization for pass-through port paths
This commit is contained in:
parent
ac4a87de13
commit
f386ec82ae
@ -27,6 +27,8 @@
|
|||||||
| `connected_endpoint_type` | string | `connected_endpoints_type` | string |
|
| `connected_endpoint_type` | string | `connected_endpoints_type` | string |
|
||||||
| `connected_endpoint_reachable` | boolean | `connected_endpoints_reachable` | boolean |
|
| `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
|
### New Features
|
||||||
|
|
||||||
#### Half-Height Rack Units ([#51](https://github.com/netbox-community/netbox/issues/51))
|
#### Half-Height Rack Units ([#51](https://github.com/netbox-community/netbox/issues/51))
|
||||||
|
@ -1081,45 +1081,19 @@ class CableTerminationSerializer(NetBoxModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CablePathSerializer(serializers.ModelSerializer):
|
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)
|
path = serializers.SerializerMethodField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CablePath
|
model = CablePath
|
||||||
fields = [
|
fields = ['id', 'path', 'is_active', 'is_complete', 'is_split']
|
||||||
'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
|
|
||||||
|
|
||||||
@swagger_serializer_method(serializer_or_field=serializers.ListField)
|
@swagger_serializer_method(serializer_or_field=serializers.ListField)
|
||||||
def get_path(self, obj):
|
def get_path(self, obj):
|
||||||
ret = []
|
ret = []
|
||||||
for node in obj.path_objects():
|
for nodes in obj.path_objects:
|
||||||
serializer = get_serializer_for_model(node, prefix='Nested')
|
serializer = get_serializer_for_model(nodes[0], prefix='Nested')
|
||||||
context = {'request': self.context['request']}
|
context = {'request': self.context['request']}
|
||||||
ret.append(serializer(node, context=context).data)
|
ret.append(serializer(nodes, context=context, many=True).data)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user