def post(self, *args, **kwargs): try: # 获取入参 image_metas = self.request.files['image'] except: # 获取入参失败时,抛出错误码及错误信息 logger.info("UploadFileHandle: request argument incorrect") http_params_error_response(self) return image_url = "" image_path_list = [] if image_metas: # 获取当前的路径 pwd = os.getcwd() save_image_path = os.path.join(pwd, "static/image/") logger.debug("UploadFileHandle: save image path: %s" % save_image_path) # 调用save_file方法将图片数据流保存在硬盘中 file_name_list = save_files(image_metas, save_image_path) image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list] ret_data = {"imageUrl": image_path_list} # 返回图片下载地址给客户端 http_simple_response(self, OK_CODE, "图片上传成功!", ret_data) else: # 如果图片为空,返回图片为空错误信息 logger.info("UploadFileHandle: image stream is e...")
def get(self): try: page = self.get_argument('page') except: http_params_error_response(self) return books = search_all_book(page) http_simple_response(self, OK_CODE, '查询成功!', books) logger.debug("Search: searchAll")
def get(self): try: key = self.get_argument('key') page = self.get_argument('page') except: http_params_error_response(self) return books = search_book_by_name(key, page) http_simple_response(self, OK_CODE, '查询成功!', books) logger.debug("Search: search key = %s", key)
def get(self): if not self.get_current_user(): http_error_simple_response(self, '权限不足!') return try: book_id = self.get_argument('bookId') except: http_params_error_response(self) return books = search_book_by_book_id(book_id) http_simple_response(self, OK_CODE, '查询成功!', books)
def get(self, *args, **kwargs): if not self.get_current_user(): http_error_simple_response(self, '请登录!') return try: book_id = self.get_argument('bookId') except: http_params_error_response(self) return delete_book(book_id) http_ok_simple_response(self,'删除成功!')
def get(self): if self.get_current_user() is None: return http_error_simple_response(self, '权限不足!') try: page = self.get_argument('page') except: http_params_error_response(self) return flag, users = search_all_user(page) if flag: http_simple_response(self, OK_CODE, '搜索成功!', users) else: http_error_simple_response(self, '搜索读者失败!')
def get(self): if self.get_current_user() is None: return http_error_simple_response(self, '权限不足!') try: user_id = self.get_argument('userId') except: http_params_error_response(self) return flag, user = search_user(user_id) if flag: http_simple_response(self, OK_CODE, '搜索成功!', user) else: http_error_simple_response(self, '搜索读者失败!')
def get(self): if self.get_current_user() is None: return http_error_simple_response(self, '权限不足!') try: user_id = self.get_argument('userId') except: http_params_error_response(self) return if delete_user(user_id): http_ok_simple_response(self, '删除读者成功!') logging.debug('删除读者成功!') else: http_error_simple_response(self, '删除读者失败!')
def get(self, *args, **kwargs): try: key = self.get_argument('key') page = self.get_argument('page') type = self.get_argument('type') except: http_params_error_response(self) return type = int(type) books = search_book_by_key(key, type, page) if books: http_simple_response(self, OK_CODE, '查询成功!', books) else: http_simple_response(self, OK_CODE, '无结果!', books) logger.debug("Search: search key = %s", key)
def post(self): if not self.get_current_user(): http_error_simple_response(self, '请登录!') return try: book = { 'bookId': self.get_argument('bookId'), 'name': self.get_argument('name'), 'isbn': self.get_argument('isbn'), 'location': self.get_argument('location'), 'publishingHouse': self.get_argument('publishingHouse'), 'author': self.get_argument('author'), 'coverUrl': self.get_argument('coverUrl'), 'intro': self.get_argument('intro') } except: http_params_error_response(self) return try: # 获取入参 image_metas = self.request.files['file'] except: logger.info('获取图片出错!') image_metas = [] if image_metas: # 存储图片 pwd = os.getcwd() save_image_path = os.path.join(pwd, "static/image/") logger.debug("UploadFileHandle: save image path: %s" % save_image_path) # 调用save_file方法将图片数据流保存在硬盘中 file_name_list = save_files(image_metas, save_image_path) image_path_list = [SERVER_HEADER + "/static/image/" + i for i in file_name_list] book['coverUrl'] = image_path_list[0] result = update_book(book) print(result) if result[0]: http_simple_response(self, OK_CODE, '更新书籍信息成功!', result[1]) else: http_error_simple_response(self, result[1]) logger.debug("Search: update bookId="+book['bookId'])
def post(self): if self.get_current_user() is None: return http_error_simple_response(self, '权限不足!') try: user_id = self.get_argument('userId') name = self.get_argument('name') sex = self.get_argument('sex') major = self.get_argument('major') password = self.get_argument('password') except: http_params_error_response(self) return user = { 'user_id': user_id, 'name': name, 'sex': sex, 'major': major, 'password': password, } result = insert_user(user) if result[0]: http_ok_simple_response(self, result[1]) else: http_error_simple_response(self, result[1])
def post(self): try: user_id = self.get_argument('userId') name = self.get_argument('name') sex = self.get_argument('sex') major = self.get_argument('major') password = self.get_argument('password') except: return http_params_error_response(self) user = { 'name': name, 'userId': user_id, 'sex': sex, 'major': major, 'password': password } user = save_info(user) if user: http_simple_response(self, OK_CODE, '个人信息更新成功!', user) else: http_error_simple_response(self, '个人信息更新失败!')