Skip to content
Snippets Groups Projects
Commit 4220fc87 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

API: assure_has_parent does now allow direct update

parent 782db460
No related branches found
No related tags found
No related merge requests found
......@@ -201,13 +201,14 @@ def assure_object_is_in_list(obj, containing_object, property_name,
to_be_updated.append(containing_object)
def assure_has_parent(entity, parent, to_be_updated, verbose=True):
def assure_has_parent(entity, parent, to_be_updated=None, verbose=True):
"""
Checks whether `entity` has a parent with name `parent`.
If this is the case this function returns. Otherwise the entity is assigned
a new parent and is added to the supplied list to_be_updated in order to
indicate, that the entity `entity` should be updated.
If this is the case this function ends. Otherwise the entity is assigned
a new parent. The list to_be_updated is supplied, the entity is added to
the list in order to indicate, that the entity `entity` should be updated.
Otherwise it is directly updated
"""
parents = entity.get_parents()
contained = False
......@@ -227,7 +228,11 @@ def assure_has_parent(entity, parent, to_be_updated, verbose=True):
if verbose:
print("Adding parent {} to entity {}".format(parent, entity.id))
entity.add_parent(parent)
to_be_updated.append(entity)
if to_be_updated is None:
entity.update(unique=False)
else:
to_be_updated.append(entity)
def insert_id_based_on_name(entity):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment