def post(self): req_json = json.dumps(request.get_json()) try: load_data, errors = LoginSchema().loads(req_json) if errors: return errors, 400 new_user = Admin(phone_number=load_data['phone_number'], password=load_data['password'], role= 1 if load_data['user_type'] == 'wechat' else 2) new_user.add(new_user) except SQLAlchemyError as e: return e.message, 500 return AdminTestSchema().dump(new_user), 201
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")