Beispiel #1
0
	def DEL(cls, node):
		try:
			db.session.delete(node)
			db.session.commit()
		except SQLAlchemyError as e:
			return RetStatus(False, e.message)
		return RetStatus(True, "delete success.")
Beispiel #2
0
 def find_by_uuid(cls, uuid):
     user = None
     try:
         user = cls.query.filter(cls.uuid == uuid).first()
     except SQLAlchemyError as e:
         return RetStatus(False, e.message)
     return RetStatus(True, data=user)
Beispiel #3
0
 def find_by_username(cls, username):
     user = None
     try:
         user = cls.query.filter(cls.username == username).first()
     except SQLAlchemyError as e:
         return RetStatus(False, e.message)
     return RetStatus(status=True, data=user)
Beispiel #4
0
	def ADD(cls, node):
		try:
			db.session.add(node)
			db.session.commit()
		except SQLAlchemyError as e:
			return RetStatus(False, e.message)
		return RetStatus(True, "add success.")
Beispiel #5
0
 def find_by_uuid(cls, uuid):
     ret = RetStatus(True)
     try:
         ret.data = cls.query.filter(cls.uuid == uuid).first()
     except SQLAlchemyError as e:
         return RetStatus(False, e.message)
     return ret
Beispiel #6
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")
Beispiel #7
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.")
Beispiel #8
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.")
Beispiel #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()
     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.")
Beispiel #10
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.")
Beispiel #11
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.")
Beispiel #12
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()
Beispiel #13
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.")
Beispiel #14
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()
Beispiel #15
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()
Beispiel #16
0
 def post(self):
     req_json = json.dumps(request.get_json())
     load_data, errors = BasicSchema().loads(req_json)
     if errors:
         return RetStatus(False, "parse request data failed.").dumps_json()
     ret = Admin.find_by_username(load_data['username'])
     if ret.check() is False:
         return RetStatus(False,
                          "check user's availability failed.").dumps_json()
     elif ret.data is None:
         return RetStatus(False, "username had be used.").dumps_json()
     user = Admin(uuid=uuid.uuid1(),
                  username=load_data['username'],
                  password=load_data['password'],
                  login_type=load_data['login_type'])
     add_ret = Admin.ADD(user)
     if add_ret.check() is False:
         return add_ret.dumps_json()
     return RetStatus(True, "register success.",
                      data=user.uuid).dumps_json()
Beispiel #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")
Beispiel #18
0
	def UPDATE(cls):
		try:
			db.session.commit()
		except SQLAlchemyError as e:
			return RetStatus(False, e.message)
		return RetStatus(True, "update success.")
Beispiel #19
0
	def ROLL_BACK(cls):
		try:
			db.session.rollback()
		except SQLAlchemyError as e:
			return RetStatus(False, e.message)
		return RetStatus(True, "roll back success.")