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

Restore total length count on trace view

This commit is contained in:
Jeremy Stretch
2020-10-06 16:58:11 -04:00
parent 2c9ae60dec
commit 44b842592a
4 changed files with 30 additions and 11 deletions

View File

@@ -4,20 +4,29 @@ from .choices import CableStatusChoices
from .exceptions import CableTraceSplit
def compile_path_node(ct_id, object_id):
return f'{ct_id}:{object_id}'
def decompile_path_node(repr):
ct_id, object_id = repr.split(':')
return int(ct_id), int(object_id)
def object_to_path_node(obj):
"""
Return a representation of an object suitable for inclusion in a CablePath path. Node representation is in the
form <ContentType ID>:<Object ID>.
"""
ct = ContentType.objects.get_for_model(obj)
return f'{ct.pk}:{obj.pk}'
return compile_path_node(ct.pk, obj.pk)
def path_node_to_object(repr):
"""
Given a path node representation, return the corresponding object.
"""
ct_id, object_id = repr.split(':')
ct_id, object_id = decompile_path_node(repr)
model_class = ContentType.objects.get(pk=ct_id).model_class()
return model_class.objects.get(pk=int(object_id))