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 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)
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()
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()
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)
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.")
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.")
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.")
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.")
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.")
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")
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")