From 4220fc876d7c49b4c39bb9a9f8d958cfdef350f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Sun, 11 Aug 2019 12:52:02 +0200 Subject: [PATCH] API: assure_has_parent does now allow direct update --- src/caosadvancedtools/cfood.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index 58cae5d0..a6e44294 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -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): -- GitLab