def update_evaluation(project, evaluation, changes): """Updates the given evaluation by adding changes for the given changed parameters to the current record. """ collection = get_evaluation_collection(project) evaluation_id = evaluation['_id'] argument = mongo_utils.make_single_field_argument('_id', evaluation_id) updates = [] for change in changes: if '.' in change: nested_changes = change.split('.') nested_value_string = 'evaluation' for nested_change in nested_changes: nested_value_string += '["' "{0}" '"]'.format(nested_change) updates.append( mongo_utils.make_update_argument(change, eval(nested_value_string))) else: updates.append( mongo_utils.make_update_argument(change, evaluation[change])) update = mongo_utils.merge_update_args(updates) cursor = mongo_utils.mongo_update_one(collection, argument, update) if cursor.matched_count == 1: return get_evaluation_by_id(project, evaluation_id) return None
def update_template(database, template, changes): """Updates the given template by adding changes for the given changed parameters to the current record. """ collection = get_template_collection(database) template_id = mongo_utils.ensure_objectid(template['_id']) argument = mongo_utils.make_single_field_argument('_id', template_id) updates = [] for change in changes: if '.' in change: nested_changes = change.split('.') nested_value_string = 'template' for nested_change in nested_changes: nested_value_string += '["' "{0}" '"]'.format(nested_change) updates.append( mongo_utils.make_update_argument(change, eval(nested_value_string))) else: updates.append( mongo_utils.make_update_argument(change, template[change])) update = mongo_utils.merge_update_args(updates) cursor = mongo_utils.mongo_update_one(collection, argument, update) if cursor.matched_count == 1: return get_template_by_id(database, template_id) return None
def update_function(project, function, changes): """Updates the given parameter set by adding changes for the given changed parameters to the current record. """ collection = get_language_collection(project) if type(function) in [dict, OrderedDict]: function_id = function['_id'] else: function_id = function argument = mongo_utils.make_single_field_argument('_id', function_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( mongo_utils.make_update_argument(change, eval(nested_value_string))) else: updates.append( mongo_utils.make_update_argument(change, function[change])) update = mongo_utils.merge_update_args(updates) cursor = mongo_utils.mongo_update_one(collection, argument, update) if cursor.matched_count == 1: return get_function_by_id(project, function_id) return None
def update_evaluation_status_by_id(project, evaluation_id, status): """Updates the status of the evaluation with the given id to the given status. """ collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('_id', evaluation_id) update = mongo_utils.make_update_argument('status', status) cursor = mongo_utils.mongo_update_one(collection, argument, update) return cursor
def update_function_vcs_status_by_id(project, function_id, status): """Updates the vcs status of the given function with the specified status. """ collection = get_function_collection(project) argument = mongo_utils.make_single_field_argument('_id', function_id) update = mongo_utils.make_update_argument('vcs.status', status) cursor = mongo_utils.mongo_update_one(collection, argument, update) return cursor
def update_component_vcs_status_by_id(database, component_id, status): """Updates the vcs status of the given component with the specified status. """ collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('_id', component_id) update = mongo_utils.make_update_argument('vcs.status', status) cursor = mongo_utils.mongo_update_one(collection, argument, update) return cursor
def remove_evaluation_by_id(project, evaluation_id, timestamp): """Updates the evaluation with the given id to have a removal datetime of the given datetime and sets the evaluation status to removed. """ update_evaluation_status_by_id(project, evaluation_id, 'removed') collection = get_evaluation_collection(project) argument = mongo_utils.make_single_field_argument('_id', evaluation_id) update = mongo_utils.make_update_argument('remove_date', timestamp) cursor = mongo_utils.mongo_update_one(collection, argument, update) return cursor
def remove_component_by_id(database, component_id, timestamp): """Updates the component with the given id to have a removal datetime of the given datetime and sets the component status to removed. """ update_component_status_by_id(database, component_id, 'removed') collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('_id', component_id) update = mongo_utils.make_update_argument('remove_date', timestamp) cursor = mongo_utils.mongo_update_one(collection, argument, update) return cursor
def update_component_functions_by_id(database, component_id, functions): """Updates the status of the component with the given id to the given status. """ collection = get_component_collection(database) argument = mongo_utils.make_single_field_argument('_id', component_id) update = mongo_utils.make_update_argument('functions', functions) cursor = mongo_utils.mongo_update_one(collection, argument, update) updated_component = None if cursor.modified_count == 1: updated_component = get_component_by_id(database, component_id) return updated_component