def update_workflow(harness, workflow, changes): """Updates the given workflow by adding changes for the given changed parameters to the current record. """ collection = get_workflow_collection(harness) workflow_id = workflow['_id'] argument = db_utils.make_single_field_argument('_id', workflow_id) updates = [] for change in changes: if '.' in change: nested_changes = change.split('.') nested_value_string = 'workflow' for nested_change in nested_changes: nested_value_string += '["'"{0}"'"]'.format(nested_change) updates.append(db_utils.make_update_argument(change, eval(nested_value_string))) else: updates.append(db_utils.make_update_argument(change, workflow[change])) update = db_utils.merge_update_args(updates) cursor = db_utils.mongo_update_one(collection, argument, update) if cursor.matched_count == 1: return get_workflow_by_id(harness, workflow_id) return None
def update_structure(database, structure, changes): """Updates the given structure by adding changes for the given changed parameters to the current record. """ collection = get_structure_collection(database) structure_id = structure['_id'] argument = db_utils.make_single_field_argument('_id', structure_id) updates = [] for change in changes: if '.' in change: nested_changes = change.split('.') nested_value_string = 'structure' for nested_change in nested_changes: nested_value_string += '["'"{0}"'"]'.format(nested_change) updates.append(db_utils.make_update_argument(change, eval(nested_value_string))) else: updates.append(db_utils.make_update_argument(change, structure[change])) update = db_utils.merge_update_args(updates) cursor = db_utils.mongo_update_one(collection, argument, update) if cursor.matched_count == 1: return get_structure_by_id(database, structure_id) return None