Пример #1
0
def _data_tool_save():
    circle_name = request.json["circle"]
    circle = Circle.find_by_name(circle_name)

    if not circle:
        raise P2k16UserException("No such circle: {}".format(circle_name))

    _id = request.json.get("id", None)

    if _id:
        tool = ToolDescription.find_by_id(_id)

        if tool is None:
            abort(404)

        logger.info("Updating tool: {}".format(tool))
        tool.name = request.json["name"]
        tool.circle = circle
        tool.description = request.json["description"]
    else:
        logger.info("Creating new tooldescription: {}".format(
            request.json["name"]))
        tool = ToolDescription(request.json["name"],
                               request.json["description"], circle)

    db.session.add(tool)
    db.session.commit()
    db.session.flush()
    logger.info("Update tool: {}".format(tool.name))

    return jsonify(tool_to_json(tool))
Пример #2
0
def data_tool(tool_id: int):
    tool = ToolDescription.find_by_id(tool_id)

    if tool is None:
        abort(404)

    return jsonify(tool_to_json(tool))
Пример #3
0
def checkin_tool():
    account = flask_login.current_user.account
    client = flask.current_app.config.tool_client  # type: DoorClient
    tool = ToolDescription.find_by_id(request.json["tool"])
    client.checkin_tool(account, tool)
    db.session.commit()
    return data_tool_list()