def post(self): json_data = json.dumps(request.get_json()) load_data, errors = InNodeSchema().loads(json_data) if errors: return errors, 400 user_data = NodeTree(title=load_data['title'],is_student=load_data['is_student']) tm = TreeManager(NodeTree, db.session) try: if load_data['node_uuid']: tm.add_node(load_data['node_uuid'], user_data) else: tm.add_node(node=user_data) except SQLAlchemyError as e: return e.message, 500 return user_data.node_id
def post(self, node_uuid): tm = TreeManager(NodeTree, db.session) if tm is None: return ret_msg(status=False, msg="get manager handle failed.") status, basic_node = tm.find_node(node_uuid=node_uuid) if status is False: return ret_msg(status=False, msg=basic_node) req_json = json.dumps(request.get_json()) load_data, errors = InNodeSchema().loads(req_json) if errors: return ret_msg(status=False, msg="parse request data failed.") new_node = NodeTree(title=load_data['title'], is_student=load_data['is_student']) if load_data['is_student']: user_set = [] patriarch_list = json.loads(json.dumps(load_data['patriarch'])) for ite in patriarch_list: user_set.append( Admin(phone_number=ite, password=ite[-4:], uuid=uuid.uuid1(), nodes=[ new_node, ])) new_node.users = user_set status, error = tm.add_node(node_uuid=node_uuid, node=new_node) if status is False: return ret_msg(status=False, msg=error) return ret_msg(status=True, msg="add success")
def post(self, node_uuid): tm = TreeManager(NodeTree, db.session) if tm is None: return RetStatus(False, "get manager handle failed. ").dumps_json() req_json = json.dumps(request.get_json()) load_data, error = ReqNodeSchema().loads(req_json) if error: return RetStatus(False, "parse request data failed.") new_node = NodeTree(title=load_data['title'], is_student=load_data['is_student'], identity_coding=load_data['identity_coding']) ret = tm.add_node(node_uuid=node_uuid, node=new_node) if ret.check() is False: return ret.dumps_json() return RetStatus(True, "add node success.")
def post(self): tm = TreeManager(NodeTree, db.session) if tm is None: return ret_msg(status=False, msg="create manager tree failed.") else: req_json = json.dumps(request.get_json()) load_data, errors = InNodeSchema( exclude=('patriarch')).loads(req_json) if errors: return ret_msg(status=False, msg="parse request data failed.") root = NodeTree(title=load_data['title'], is_student=load_data['is_student']) status, error = tm.add_node(node=root) if status: return ret_msg(status=True, msg="add root node success.") else: return ret_msg(status=False, msg=error)
age = db.Column(db.Integer, default=0) address = db.Column(db.String(120), default='') identify_card = db.Column(db.String(20), default=0) campus_id = db.Column(db.String(30), default='') cantact = db.Column(db.String(20), default='') app = Flask(__name__) app.config[ 'SQLALCHEMY_DATABASE_URI'] = "mysql://*****:*****@192.168.74.128:16868/SmartCampus" db.init_app(app) app.app_context().push() db.create_all() tm = TreeManager(MenuList, db.session) test1 = MenuList(age=1, name="pc") tm.add_node(node=test1) test2 = MenuList(age=2, name="pc") tm.add_node(test1.node_uuid, test2) test3 = MenuList(age=3, name="pc") tm.add_node(test1.node_uuid, test3) test4 = MenuList(age=4, name="pc") tm.add_node(test2.node_uuid, test4) #tm.delete_node(test2.node_uuid) #node=tm.find_node(test3.node_uuid) #if node is None: # print "None" #else: # print node.node_uuid #node.age=666666 #tm.update_node(node)