示例#1
0
 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")
示例#2
0
 def delete(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     del_ret = tm.delete_node(node_uuid=node_uuid)
     if del_ret.check() is False:
         return del_ret.dumps_json()
     return RetStatus(True, "delete node success")
示例#3
0
 def get(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.find_node(node_uuid=node_uuid)
     if node.check() is False:
         return node.dumps_json()
     node.data = OutInfoSchema().dump(node.data).data
     return node.dumps_json()
示例#4
0
 def get(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return ret_msg(status=False, msg="get manager handle failed.")
     status, node = tm.find_node(node_uuid=node_uuid)
     if status is False:
         return ret_msg(status=False, msg=node)
     return ret_msg(status=True,
                    msg="find node success",
                    data=OutNodeSchema().dump(node).data)
示例#5
0
 def get(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     ret = tm.find_node(node_uuid=node_uuid)
     if ret.check() is False:
         return ret.dumps_json()
     else:
         ret.data = RspNodeSchema().dump(ret.data).data
         return ret.dumps_json()
示例#6
0
 def get(self):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     ret = tm.get_root_node(many=True)
     if ret.check() is False:
         return ret.dumps_json()
     else:
         ret.data = RspNodeSchema(many=True).dump(ret.data).data
         return ret.dumps_json()
示例#7
0
 def get(self):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return ret_msg(status=False, msg="create manager tree failed.")
     else:
         root = tm.get_root_node()
         if root is None:
             return ret_msg(status=False, msg="can't find root node.")
         else:
             return ret_msg(status=True,
                            msg="find root success",
                            data=ListSchema().dump(root).data)
示例#8
0
 def delete(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.find_node(node_uuid=node_uuid)
     if node.check() is False:
         return node.dumps_json()
     if node.data.infos is None:
         return RetStatus(False, "nothing will be deleted.")
     del_ret = NodeInfo.DEL(node.data.infos)
     if del_ret.check() is False:
         return del_ret.dumps_json()
     return RetStatus(True, "delete success.")
示例#9
0
 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.")
示例#10
0
 def delete(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return ret_msg(status=False, msg="get manager handle failed.")
     status, node = tm.find_node(node_uuid=node_uuid)
     if status is False:
         return ret_msg(status=False, msg=node)
     if node.is_student:
         users = node.users
         for ite in users:
             ite.delete()
     status, error = tm.delete_node(node_uuid=node_uuid)
     if status is False:
         return ret_msg(status=False, msg=error)
     return ret_msg(status=True, msg="delete node success.")
示例#11
0
 def post(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.find_node(node_uuid=node_uuid)
     if node.check() is False:
         return node.dumps_json()
     req_json = json.dumps(request.get_json())
     load_data, error = NodeMsgEdit(exclude=('uuid')).loads(req_json)
     if error:
         return RetStatus(False, "parse request data failed.")
     new_msg = NodeMsg(load_data['title'], load_data['msg'], nodes=[node,])
     add_ret = NodeMsg.ADD(new_msg)
     if add_ret.check() is False:
         return add_ret.dumps_json()
     return RetStatus(True, "add success.")
示例#12
0
 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)
示例#13
0
 def get(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return ret_msg(status=False, msg="get manager handle failed.")
     status, data = tm.find_node(node_uuid=node_uuid)
     if status is False:
         return ret_msg(status=False, msg=data)
     status, nodes = tm.find_node(node_uuid=data.node_uuid, many=True)
     if status is False:
         return ret_msg(status=False, msg=nodes)
     ret_data = {
         "title": data.title,
         "node_uuid": data.node_uuid,
         "children": ""
     }
     ret_data['children'] = OutNodeSchema(many=True).dump(nodes).data
     return ret_msg(status=True, msg="find success", data=ret_data)
示例#14
0
 def put(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.check(node_uuid=node_uuid)
     if node.check() is False:
         return node.dumps_json()
     if node.data is False:
         return RetStatus(False, "invalid node uuid.")
     req_json = json.dumps(request.get_json())
     load_data, error = OutMsgSchema().loads(req_json)
     node.data.msgs['title'] = load_data['title']
     node.data.msgs['msg']   = load_data['msg']
     update_ret = NodeMsg.UPDATE()
     if update_ret.check() is False:
         return update_ret.dumps_json()
     return RetStatus(True, "update success.")
示例#15
0
 def put(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.find_node(node_uuid)
     if node.check() is False:
         return node.dumps_json()
     req_json = json.dumps(request.get_json())
     load_data, error = OutInfoSchema().loads(req_json)
     if error:
         return RetStatus(False, "parse request data failed.")
     node.data.msg['age'] = load_data['age']
     node.data.msg['sex'] = load_data['sex']
     node.data.msg['campus_id'] = load_data['campus_id']
     update_ret = NodeInfo.UPDATE()
     if update_ret.check() is False:
         return update_ret.dumps_json()
     return RetStatus(True, "update success.")
示例#16
0
 def put(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     target_node = tm.find_node(node_uuid=node_uuid)
     if target_node.check() is False:
         return target_node.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.")
     target_node.data['title'] = load_data['title']
     target_node.data['is_student'] = load_data['is_student']
     target_node.data['identity_coding'] = load_data['identity_coding']
     update_ret = tm.update_node(target_node.data)
     if update_ret.check() is False:
         return update_ret.dumps_json()
     return RetStatus(True, "update node success.")
示例#17
0
 def post(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return RetStatus(False, "get manager handle failed. ").dumps_json()
     node = tm.find_node(node_uuid=node_uuid)
     if node.check() is False:
         return node.dumps_json()
     req_json = json.dumps(request.get_json())
     load_data, error = OutInfoSchema(exclude=('uuid')).loads(req_json)
     if error:
         return RetStatus(False, "parse request data failed.")
     node_info = NodeInfo(uuid=uuid.uuid1(),
                          age=load_data['age'],
                          sex=load_data['sex'],
                          campus_id=load_data['campus_id'],
                          nodes=[
                              node,
                          ])
     add_ret = NodeInfo.ADD(node_info)
     if add_ret.check() is False:
         return add_ret.dumps_json()
     return RetStatus(True, "add success")
示例#18
0
 def put(self, node_uuid):
     tm = TreeManager(NodeTree, db.session)
     if tm is None:
         return ret_msg(status=False, msg="get manager handle failed.")
     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.")
     status, node = tm.find_node(node_uuid=node_uuid)
     if status is False:
         return ret_msg(status=False, msg=node)
     node.title = load_data['title']
     if load_data['is_student']:
         status, nodes = Admin().find_node_by_uuid(node.node_uuid)
         if status is False:
             return ret_msg(status=False, msg=nodes)
         elif nodes is None:
             return ret_msg(status=False, msg="invalid node uuid.")
         else:
             user_error = []
             for ite in nodes:
                 if ite.phone_number in load_data['patriarch']:
                     ite.delete()
                 else:
                     new_admin = Admin(phone_number=ite, password=ite[-4:])
                     new_admin.students = [
                         node,
                     ]
                     try:
                         new_admin.add(new_admin)
                     except SQLAlchemyError as e:
                         user_error.append(ite)
             if user_error is False:
                 return ret_msg(status=False,
                                msg="update some patriarches failed.",
                                data=json.dumps(user_error))
     return ret_msg(status=True, msg="update success")
示例#19
0
 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
示例#20
0
    name = db.Column(db.String(80), nullable=False)
    sex = db.Column(db.Integer, default=0)
    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