コード例 #1
0
ファイル: slicing.py プロジェクト: gauthama93/OctoPrint
def slicingPatchSlicerProfile(slicer, name):
    if "application/json" not in request.headers["Content-Type"]:
        return make_response("Expected content-type JSON", 400)

    try:
        profile = slicingManager.load_profile(slicer,
                                              name,
                                              require_configured=False)
    except UnknownSlicer:
        return make_response("Unknown slicer {slicer}".format(**locals()), 404)
    except UnknownProfile:
        return make_response(
            "Profile {name} for slicer {slicer} not found".format(**locals()),
            404)

    try:
        json_data = request.get_json()
    except BadRequest:
        return make_response("Malformed JSON body in request", 400)

    if json_data is None:
        return make_response("Malformed JSON body in request", 400)

    data = {}
    display_name = None
    description = None
    if "data" in json_data:
        data = json_data["data"]
    if "displayName" in json_data:
        display_name = json_data["displayName"]
    if "description" in json_data:
        description = json_data["description"]

    saved_profile = slicingManager.save_profile(
        slicer,
        name,
        profile,
        allow_overwrite=True,
        overrides=data,
        display_name=display_name,
        description=description,
    )

    from octoprint.server.api import valid_boolean_trues

    if "default" in json_data and json_data["default"] in valid_boolean_trues:
        slicingManager.set_default_profile(slicer, name, require_exists=False)

    return jsonify(_getSlicingProfileData(slicer, name, saved_profile))
コード例 #2
0
ファイル: slicing.py プロジェクト: foosel/OctoPrint
def slicingPatchSlicerProfile(slicer, name):
	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content-type JSON", 400)

	try:
		profile = slicingManager.load_profile(slicer, name, require_configured=False)
	except UnknownSlicer:
		return make_response("Unknown slicer {slicer}".format(**locals()), 404)
	except UnknownProfile:
		return make_response("Profile {name} for slicer {slicer} not found".format(**locals()), 404)

	try:
		json_data = request.json
	except BadRequest:
		return make_response("Malformed JSON body in request", 400)

	data = dict()
	display_name = None
	description = None
	if "data" in json_data:
		data = json_data["data"]
	if "displayName" in json_data:
		display_name = json_data["displayName"]
	if "description" in json_data:
		description = json_data["description"]

	saved_profile = slicingManager.save_profile(slicer, name, profile,
	                                            allow_overwrite=True,
	                                            overrides=data,
	                                            display_name=display_name,
	                                            description=description)

	from octoprint.server.api import valid_boolean_trues
	if "default" in json_data and json_data["default"] in valid_boolean_trues:
		slicingManager.set_default_profile(slicer, name, require_exists=False)

	return jsonify(_getSlicingProfileData(slicer, name, saved_profile))