def api_node_tags_delete(nodeid,tag): status = "success" answ = {"data": {}} cloud_api_main.debug_log_print("Change tags", request.data) try: cloud_api_main.check_user_privilege_node(nodeid) if tag == cloud_api_main.tdata.usertag: cloud_api_main.add_to_user_problem_msg("you can't remove your own usertag") raise cloud_api_main.PrivilegeException("can't remove this tag") tags = set((tag,)) currtags = set(cloud_api_main.get_tags_node(nodeid)) to_remove = tags.intersection(currtags) cloud_api_main.remove_tag_node(to_remove, nodeid) answ["data"]["deleted"] = True except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException) as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() answ["status"] = status return make_response(jsonify(answ))
def api_node_tags_change(nodeid): status = "success" answ = {"data": {}} try: cloud_api_main.debug_log_print("Change tags", request.data) cloud_api_main.check_user_privilege_node(nodeid) reqdata = json.loads(request.data) tags = reqdata["tags"] if isinstance(tags, basestring): tags = [tags] tags = set(tags) tags.add(cloud_api_main.tdata.ownertag) alltags = cloud_api_main.get_tags() currtags = set(cloud_api_main.get_tags_node(nodeid)) to_remove = currtags.difference(tags).intersection(alltags) to_add = tags.difference(currtags) for t in to_add: if t not in alltags: cloud_api_main.create_tag(t) cloud_api_main.add_tag_node(t, nodeid) cloud_api_main.remove_tag_node(to_remove, nodeid) answ["data"]["tags"] = cloud_api_main.get_tags_node(nodeid) except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException) as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() answ["status"] = status return make_response(jsonify(answ))
def api_node_tags_delete(nodeid, tag): status = "success" answ = {"data": {}} cloud_api_main.debug_log_print("Change tags", request.data) try: cloud_api_main.check_user_privilege_node(nodeid) if tag == cloud_api_main.tdata.usertag: cloud_api_main.add_to_user_problem_msg( "you can't remove your own usertag") raise cloud_api_main.PrivilegeException("can't remove this tag") tags = set((tag, )) currtags = set(cloud_api_main.get_tags_node(nodeid)) to_remove = tags.intersection(currtags) cloud_api_main.remove_tag_node(to_remove, nodeid) answ["data"]["deleted"] = True except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException) as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() answ["status"] = status return make_response(jsonify(answ))