示例#1
0
def api_save_config():
    """ Save labeling config
    """
    label_config = None
    if 'label_config' in request.form:
        label_config = request.form['label_config']
    elif 'label_config' in request.json:
        label_config = request.json['label_config']

    # check config before save
    try:
        g.project.validate_label_config(label_config)
    except ValidationError as e:
        return make_response(jsonify({'label_config': e.msg_to_list()}),
                             status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return make_response(jsonify({'label_config': [str(e)]}),
                             status.HTTP_400_BAD_REQUEST)

    # update config states
    try:
        schema_before = g.project.input_data_scheme
        g.project.update_label_config(label_config)
        schema_after = g.project.input_data_scheme
        if not schema_before.issubset(schema_after):
            remove_tabs(g.project)
    except Exception as e:
        return make_response(jsonify({'label_config': [str(e)]}),
                             status.HTTP_400_BAD_REQUEST)

    return Response(status=status.HTTP_201_CREATED)
示例#2
0
文件: api.py 项目: wwwK/label-studio
def api_project_tabs():
    """ Project tabs for data manager
    """
    if request.method == 'GET':
        data = load_all_tabs(g.project)
        return make_response(jsonify(data), 200)

    if request.method == 'DELETE':
        remove_tabs(g.project)
        data = load_all_tabs(g.project)
        return make_response(jsonify(data), 204)