Skip to content
Snippets Groups Projects

Add an API helper to link two elements

Merged Manon Blanco requested to merge create-element-parent into master
All threads resolved!
Files
2
@@ -270,6 +270,37 @@ class ElementMixin:
return created_ids
def create_element_parent(
self,
parent: Element,
child: Element,
) -> dict[str, str]:
"""
Link an element to a parent through the API.
:param parent: Parent element.
:param child: Child element.
:returns: A dict from the ``CreateElementParent`` API endpoint.
"""
assert parent and isinstance(
parent, Element
), "parent shouldn't be null and should be of type Element"
assert child and isinstance(
child, Element
), "child shouldn't be null and should be of type Element"
if self.is_read_only:
logger.warning("Cannot link elements as this worker is in read-only mode")
return
element_parent = self.request(
"CreateElementParent",
parent=parent.id,
child=child.id,
)
return element_parent
def partial_update_element(
self, element: Element | CachedElement, **kwargs
) -> dict:
@@ -288,7 +319,7 @@ class ElementMixin:
* *image* (``UUID``): Optional ID of the image of this element
:returns: A dict from the ``PartialUpdateElement`` API endpoint,
:returns: A dict from the ``PartialUpdateElement`` API endpoint.
"""
assert element and isinstance(
element, Element | CachedElement
Loading