def update_widget_config(id_):
    """Updates a single widget config

    :param id: ID of widget to update
    :type id: int
    :param body: Result
    :type body: dict

    :rtype: Result
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    widget_config = connexion.request.get_json()
    if widget_config.get(
            "widget") and widget_config["widget"] not in WIDGET_TYPES.keys():
        return "Bad request, widget type does not exist", 400
    # Look up the project id
    if widget_config.get("project"):
        widget_config["project"] = get_project_id(widget_config["project"])
    existing_widget_config = mongo.widget_config.find_one(
        {"_id": ObjectId(id_)})
    # add default weight of 10
    if not existing_widget_config.get("weight"):
        existing_widget_config["weight"] = 10
    # default to make views navigable
    if widget_config.get(
            "type") == "view" and not widget_config.get("navigable"):
        widget_config["navigable"] = "true"
    merge_dicts(existing_widget_config, widget_config)
    mongo.widget_config.replace_one({"_id": ObjectId(id_)}, widget_config)
    return serialize(widget_config)
Ejemplo n.º 2
0
 def update(self, record_dict):
     if "id" in record_dict:
         record_dict.pop("id")
     group_dict = self.to_dict()
     merge_dicts(group_dict, record_dict)
     if group_dict.get("metadata"):
         group_dict["data"] = group_dict.pop("metadata")
     if record_dict.get("metadata"):
         record_dict["data"] = record_dict.get("metadata")
     for key, value in record_dict.items():
         setattr(self, key, value)
Ejemplo n.º 3
0
def bulk_update(filter_=None, page_size=1, token_info=None, user=None):
    """Updates multiple runs with common metadata

    Note: can only be used to update metadata on runs, limited to 25 runs

    :param filter_: A list of filters to apply
    :param page_size: Limit the number of runs updated, defaults to 1

    :rtype: List[Run]
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400

    run_dict = connexion.request.get_json()

    if not run_dict.get("metadata"):
        return "Bad request, can only update metadata", 401

    # ensure only metadata is updated
    run_dict = {"metadata": run_dict.pop("metadata")}

    if page_size > 25:
        return "Bad request, cannot update more than 25 runs at a time", 405

    if run_dict.get("metadata", {}).get("project"):
        project = get_project(run_dict["metadata"]["project"])
        if not project_has_user(project, user):
            return "Forbidden", 403
        run_dict["project_id"] = project.id

    runs = get_run_list(filter_=filter_, page_size=page_size,
                        estimate=True).get("runs")

    if not runs:
        return f"No runs found with {filter_}", 404

    model_runs = []
    for run_json in runs:
        run = Run.query.get(run_json.get("id"))
        # update the json dict of the run with the new metadata
        merge_dicts(run_dict, run_json)
        run.update(run_json)
        session.add(run)
        model_runs.append(run)
    session.commit()

    return [run.to_dict() for run in model_runs]
Ejemplo n.º 4
0
def update_result(id_, result=None):
    """Updates a single result

    :param id: ID of result to update
    :type id: int
    :param body: Result
    :type body: dict

    :rtype: Result
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    result = connexion.request.get_json()
    if result.get("metadata", {}).get("project"):
        result["metadata"]["project"] = get_project_id(result["metadata"]["project"])
    existing_result = mongo.results.find_one({"_id": ObjectId(id_)})
    merge_dicts(existing_result, result)
    mongo.results.replace_one({"_id": ObjectId(id_)}, result)
    return serialize(result)
Ejemplo n.º 5
0
def update_project(id_, project=None):
    """Update a project



    :param id: ID of test project
    :type id: str
    :param body: Project
    :type body: dict | bytes

    :rtype: Project
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    body = Project.from_dict(connexion.request.get_json())
    project = body.to_dict()
    existing_project = mongo.projects.find_one({"_id": ObjectId(id_)})
    merge_dicts(existing_project, project)
    mongo.projects.replace_one({"_id": ObjectId(id_)}, project)
    return serialize(project)
Ejemplo n.º 6
0
def update_run(id_, run=None):
    """Updates a single run

    :param id: ID of run to update
    :type id: int
    :param body: Run
    :type body: dict

    :rtype: Run
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    run = connexion.request.get_json()
    if run.get("metadata") and run.get("metadata", {}).get("project"):
        run["metadata"]["project"] = get_project_id(run["metadata"]["project"])
    existing_run = mongo.runs.find_one({"_id": ObjectId(id_)})
    merge_dicts(existing_run, run)
    mongo.runs.replace_one({"_id": ObjectId(id_)}, run)
    update_run_task.delay(id_)
    return serialize(run)
Ejemplo n.º 7
0
def update_group(id_, group=None):
    """Update a group



    :param id: The ID of the group
    :type id: str
    :param body: The updated group
    :type body: dict | bytes

    :rtype: Group
    """
    if not connexion.request.is_json:
        return "Bad request, JSON required", 400
    body = Group.from_dict(connexion.request.get_json())
    group = body.to_dict()
    existing_group = mongo.groups.find_one({"_id": ObjectId(id_)})
    merge_dicts(existing_group, group)
    mongo.groups.replace_one({"_id": ObjectId(id_)}, group)
    return serialize(group)