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): 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, *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): 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, '个人信息更新失败!')
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, *args, **kwargs): if not self.get_current_user(): http_error_simple_response(self, '请登录!') return try: book = { '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'), 'state': 0 } except BaseException as e: http_error_simple_response(self, str(e)) 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 = add_book(book) http_simple_response(self, OK_CODE if result[0] else ERROR_CODE, result[1]) logger.debug("Search: add book")
def get(self): user_id = self.get_current_user() if not user_id: http_simple_response(self, ERROR_CODE, "请登陆!") return try: page = self.get_argument('page') except: http_simple_response(self, ERROR_CODE, "获取参数失败!") return records = search_record_by_user_id(user_id, page) http_simple_response(self, OK_CODE, "获取数据成功!", records)
def get(self): if not self.get_current_user(): http_simple_response(self, ERROR_CODE, "请登陆!") return try: key = self.get_argument('key') key_type = self.get_argument('type') except: http_simple_response(self, ERROR_CODE, "获取参数失败!") return result = search_all_record_by_user_id(key) if int(key_type) == 0 else search_all_record_by_book_id(key) http_simple_response(self, OK_CODE, "", result)
def get(self): user_id = self.get_current_user() if not user_id: http_simple_response(self, ERROR_CODE, "请登陆!") return try: page = self.get_argument('page') except: http_simple_response(self, ERROR_CODE, "获取参数失败!") return http_simple_response(self, OK_CODE, "", search_all_record(page))
def get(self): user_id = self.get_current_user() if not user_id: http_simple_response(self, ERROR_CODE, "请登陆!") return try: user_id = self.get_argument('userId') book_id = self.get_argument('bookId') except: http_simple_response(self, ERROR_CODE, "获取参数失败!") return result = insert_record(user_id, book_id) http_simple_response(self, OK_CODE if result[0] else ERROR_CODE, result[1])
def post(self): try: # 获取入参 user_id = self.get_argument('userId') password = self.get_argument('password') type = self.get_argument('type') except: # 获取入参失败时,抛出错误码及错误信息 logger.info("LoginHandle: request argument incorrect") http_simple_response(self, ERROR_CODE, "获取参数失败!") return self.set_secure_cookie('userId', user_id) ex_user = login(user_id, password) if ex_user: self.set_secure_cookie('userId', user_id) http_simple_response(self, OK_CODE, '登陆成功!', ex_user) return else: # 帐号或密码错误 logger.debug( "LoginHandle: account or password is error, user: %s" % user_id) http_simple_response(self, ERROR_CODE, "账号或密码错误!")