Exemple #1
0
def printerProfilesUpdate(identifier):
    if not "application/json" in request.headers["Content-Type"]:
        return None, None, make_response("Expected content-type JSON", 400)

    json_data = request.json
    if not "profile" in json_data:
        make_response("No profile included in request", 400)

    profile = printerProfileManager.get(identifier)
    if profile is None:
        profile = printerProfileManager.get_default()

    new_profile = json_data["profile"]
    new_profile = dict_merge(profile, new_profile)

    make_default = False
    if "default" in new_profile:
        make_default = True
        del new_profile["default"]

    new_profile["id"] = identifier
    if not _validate_profile(new_profile):
        make_response("Combined profile is invalid, missing obligatory values",
                      400)

    try:
        saved_profile = printerProfileManager.save(new_profile,
                                                   allow_overwrite=True,
                                                   make_default=make_default)
    except Exception as e:
        make_response("Could not save profile: %s" % e.message)

    return jsonify(dict(profile=_convert_profile(saved_profile)))
def printerProfilesUpdate(identifier):
	if not "application/json" in request.headers["Content-Type"]:
		return None, None, make_response("Expected content-type JSON", 400)

	json_data = request.json
	if not "profile" in json_data:
		make_response("No profile included in request", 400)

	profile = printerProfileManager.get(identifier)
	if profile is None:
		profile = printerProfileManager.get_default()

	new_profile = json_data["profile"]
	new_profile = dict_merge(profile, new_profile)

	make_default = False
	if "default" in new_profile:
		make_default = True
		del new_profile["default"]

	new_profile["id"] = identifier
	if not _validate_profile(new_profile):
		make_response("Combined profile is invalid, missing obligatory values", 400)

	try:
		saved_profile = printerProfileManager.save(new_profile, allow_overwrite=True, make_default=make_default)
	except Exception as e:
		make_response("Could not save profile: %s" % e.message)

	return jsonify(dict(profile=_convert_profile(saved_profile)))
Exemple #3
0
def printerProfilesAdd():
    if "application/json" not in request.headers["Content-Type"]:
        return make_response("Expected content-type JSON", 400)

    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)

    if "profile" not in json_data:
        return make_response("No profile included in request", 400)

    base_profile = printerProfileManager.get_default()
    if "basedOn" in json_data and isinstance(json_data["basedOn"], basestring):
        other_profile = printerProfileManager.get(json_data["basedOn"])
        if other_profile is not None:
            base_profile = other_profile

    if "id" in base_profile:
        del base_profile["id"]
    if "name" in base_profile:
        del base_profile["name"]
    if "default" in base_profile:
        del base_profile["default"]

    new_profile = json_data["profile"]
    make_default = False
    if "default" in new_profile:
        make_default = True
        del new_profile["default"]

    profile = dict_merge(base_profile, new_profile)

    if "id" not in profile:
        return make_response("Profile does not contain mandatory 'id' field", 400)
    if "name" not in profile:
        return make_response("Profile does not contain mandatory 'name' field", 400)

    try:
        saved_profile = printerProfileManager.save(
            profile, allow_overwrite=False, make_default=make_default, trigger_event=True
        )
    except InvalidProfileError:
        return make_response("Profile is invalid", 400)
    except CouldNotOverwriteError:
        return make_response(
            "Profile {} already exists and overwriting was not allowed".format(
                profile["id"]
            ),
            400,
        )
    except Exception as e:
        return make_response("Could not save profile: %s" % str(e), 500)
    else:
        return jsonify({"profile": _convert_profile(saved_profile)})
Exemple #4
0
def printerProfilesAdd():
    if "application/json" not in request.headers["Content-Type"]:
        abort(400, description="Expected content-type JSON")

    json_data = request.get_json()

    if json_data is None:
        abort(400, description="Malformed JSON body in request")

    if "profile" not in json_data:
        abort(400, description="profile is missing")

    base_profile = printerProfileManager.get_default()
    if "basedOn" in json_data and isinstance(json_data["basedOn"], str):
        other_profile = printerProfileManager.get(json_data["basedOn"])
        if other_profile is not None:
            base_profile = other_profile

    if "id" in base_profile:
        del base_profile["id"]
    if "name" in base_profile:
        del base_profile["name"]
    if "default" in base_profile:
        del base_profile["default"]

    new_profile = json_data["profile"]
    make_default = False
    if "default" in new_profile:
        make_default = True
        del new_profile["default"]

    profile = dict_merge(base_profile, new_profile)

    if "id" not in profile:
        abort(400, description="profile.id is missing")
    if "name" not in profile:
        abort(400, description="profile.name is missing")

    try:
        saved_profile = printerProfileManager.save(profile,
                                                   allow_overwrite=False,
                                                   make_default=make_default,
                                                   trigger_event=True)
    except InvalidProfileError:
        abort(400, description="profile is invalid")
    except CouldNotOverwriteError:
        abort(
            400,
            description="Profile already exists and overwriting was not allowed"
        )
    except Exception as e:
        abort(500, description="Could not save profile: %s" % str(e))
    else:
        return jsonify({"profile": _convert_profile(saved_profile)})
Exemple #5
0
def printerProfilesAdd():
	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content-type JSON", 400)

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

	if not "profile" in json_data:
		return make_response("No profile included in request", 400)

	base_profile = printerProfileManager.get_default()
	if "basedOn" in json_data and isinstance(json_data["basedOn"], basestring):
		other_profile = printerProfileManager.get(json_data["basedOn"])
		if other_profile is not None:
			base_profile = other_profile

	if "id" in base_profile:
		del base_profile["id"]
	if "name" in base_profile:
		del base_profile["name"]
	if "default" in base_profile:
		del base_profile["default"]

	new_profile = json_data["profile"]
	make_default = False
	if "default" in new_profile:
		make_default = True
		del new_profile["default"]

	profile = dict_merge(base_profile, new_profile)

	if not "id" in profile:
		return make_response("Profile does not contain mandatory 'id' field", 400)
	if not "name" in profile:
		return make_response("Profile does not contain mandatory 'name' field", 400)

	try:
		saved_profile = printerProfileManager.save(profile, allow_overwrite=False, make_default=make_default)
	except InvalidProfileError:
		return make_response("Profile is invalid", 400)
	except CouldNotOverwriteError:
		return make_response("Profile {} already exists and overwriting was not allowed".format(profile["id"]), 400)
	except Exception as e:
		return make_response("Could not save profile: %s" % str(e), 500)
	else:
		return jsonify(dict(profile=_convert_profile(saved_profile)))
Exemple #6
0
def printerProfilesUpdate(identifier):
    if "application/json" not in request.headers["Content-Type"]:
        return make_response("Expected content-type JSON", 400)

    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)

    if "profile" not in json_data:
        return make_response("No profile included in request", 400)

    profile = printerProfileManager.get(identifier)
    if profile is None:
        profile = printerProfileManager.get_default()

    new_profile = json_data["profile"]
    merged_profile = dict_merge(profile, new_profile)

    make_default = False
    if "default" in merged_profile:
        make_default = True
        del new_profile["default"]

        merged_profile["id"] = identifier

    try:
        saved_profile = printerProfileManager.save(
            merged_profile,
            allow_overwrite=True,
            make_default=make_default,
            trigger_event=True,
        )
    except InvalidProfileError:
        return make_response("Profile is invalid", 400)
    except CouldNotOverwriteError:
        return make_response(
            "Profile already exists and overwriting was not allowed", 400
        )
    except Exception as e:
        return make_response("Could not save profile: %s" % str(e), 500)
    else:
        return jsonify({"profile": _convert_profile(saved_profile)})
def printerProfilesAdd():
	if not "application/json" in request.headers["Content-Type"]:
		return None, None, make_response("Expected content-type JSON", 400)

	json_data = request.json
	if not "profile" in json_data:
		return None, None, make_response("No profile included in request", 400)

	base_profile = printerProfileManager.get_default()
	if "basedOn" in json_data and isinstance(json_data["basedOn"], basestring):
		other_profile = printerProfileManager.get(json_data["basedOn"])
		if other_profile is not None:
			base_profile = other_profile

	if "id" in base_profile:
		del base_profile["id"]
	if "name" in base_profile:
		del base_profile["name"]
	profile = dict_merge(base_profile, json_data["profile"])
	if not _validate_profile(profile):
		return None, None, make_response("Profile is invalid, missing obligatory values", 400)

	return _overwrite_profile(profile)
Exemple #8
0
def printerProfilesUpdate(identifier):
	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content-type JSON", 400)

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

	if not "profile" in json_data:
		return make_response("No profile included in request", 400)

	profile = printerProfileManager.get(identifier)
	if profile is None:
		profile = printerProfileManager.get_default()

	new_profile = json_data["profile"]
	new_profile = dict_merge(profile, new_profile)

	make_default = False
	if "default" in new_profile:
		make_default = True
		del new_profile["default"]

	new_profile["id"] = identifier

	try:
		saved_profile = printerProfileManager.save(new_profile, allow_overwrite=True, make_default=make_default)
	except InvalidProfileError:
		return make_response("Profile is invalid", 400)
	except CouldNotOverwriteError:
		return make_response("Profile already exists and overwriting was not allowed", 400)
	except Exception as e:
		return make_response("Could not save profile: %s" % e.message, 500)
	else:
		return jsonify(dict(profile=_convert_profile(saved_profile)))
Exemple #9
0
def printerProfilesAdd():
    if not "application/json" in request.headers["Content-Type"]:
        return None, None, make_response("Expected content-type JSON", 400)

    json_data = request.json
    if not "profile" in json_data:
        return None, None, make_response("No profile included in request", 400)

    base_profile = printerProfileManager.get_default()
    if "basedOn" in json_data and isinstance(json_data["basedOn"], basestring):
        other_profile = printerProfileManager.get(json_data["basedOn"])
        if other_profile is not None:
            base_profile = other_profile

    if "id" in base_profile:
        del base_profile["id"]
    if "name" in base_profile:
        del base_profile["name"]
    profile = dict_merge(base_profile, json_data["profile"])
    if not _validate_profile(profile):
        return None, None, make_response(
            "Profile is invalid, missing obligatory values", 400)

    return _overwrite_profile(profile)
Exemple #10
0
def printerProfilesGet(identifier):
	profile = printerProfileManager.get(identifier)
	if profile is None:
		return make_response("Unknown profile: %s" % identifier, 404)
	else:
		return jsonify(_convert_profile(profile))
Exemple #11
0
def printerProfilesGet(identifier):
    profile = printerProfileManager.get(identifier)
    if profile is None:
        return make_response("Unknown profile: %s" % identifier, 404)
    else:
        return jsonify(_convert_profile(profile))
Exemple #12
0
def printerProfilesGet(identifier):
    profile = printerProfileManager.get(identifier)
    if profile is None:
        abort(404)
    else:
        return jsonify(_convert_profile(profile))