Skip to content
Snippets Groups Projects

Add an API helper to update an element

Merged Manon Blanco requested to merge partial-update-element-helper into master
All threads resolved!
2 files
+ 44
19
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -277,7 +277,7 @@ class ElementMixin(object):
def update_element(
self,
element: Element,
element: Union[Element, CachedElement],
type: Optional[str] = None,
name: Optional[str] = None,
polygon: Optional[List[List[Union[int, float]]]] = None,
@@ -286,7 +286,7 @@ class ElementMixin(object):
"""
Partially update an element through the API.
:param Element element: The element to update.
:param element: The element to update.
:param type: Optional new slug type of the element.
:param name: Optional new name of the element.
:param polygon: Optional new polygon of the element.
@@ -294,8 +294,8 @@ class ElementMixin(object):
:returns: A dict from the ``PartialUpdateElement`` API endpoint,
"""
assert element and isinstance(
element, Element
), "element shouldn't be null and should be of type Element"
element, (Element, CachedElement)
), "element shouldn't be null and should be an Element or CachedElement"
assert type is None or isinstance(type, str), "type should be None or a str"
assert name is None or isinstance(name, str), "name should be None or a str"
assert polygon is None or isinstance(
@@ -317,7 +317,7 @@ class ElementMixin(object):
logger.warning("Cannot update element as this worker is in read-only mode")
return
return self.request(
updated_element = self.request(
"PartialUpdateElement",
id=element.id,
body={
@@ -328,6 +328,17 @@ class ElementMixin(object):
},
)
if self.use_cache:
CachedElement.update(
{
CachedElement.type: type,
CachedElement.polygon: str(polygon),
CachedElement.confidence: confidence,
}
).where(CachedElement.id == element.id).execute()
return updated_element
def list_element_children(
self,
element: Union[Element, CachedElement],
Loading