def post(self): username = self.get_argument('username') password = self.get_argument('password') grade = safe_str_to_int(self.get_argument('grade')) identifier = safe_str_to_int(self.get_argument('identifier')) nickname = self.get_argument('nickname') subject = self.get_argument('subject', None) serial_number = self.get_argument('serial_number', None) options = self.get_argument('options', None) # 拿到用户头像 files = self.request.files if files: key = 'avatar_file' if key in files: avatar_file = files[key][0] file_name = avatar_file['filename'] from tool.util import get_file_extension, save_file suffix = get_file_extension(file_name) from dbop.dbUser import get_latest_id index = get_latest_id(username, is_new=True) new_file_name = "{0}_{1}{2}".format("user", index, suffix) msg0 = "[in registerServer] new_file_name=" + new_file_name logging.info(msg0) file_content = avatar_file['body'] # 注入头像url字段信息 tmp_dict = dict() tmp_dict['avatar_url'] = save_file(new_file_name, file_content, 1) tmp_dict['avatar_url'] = "http://" + ConfigManager().get_config('host') + ":" + \ str(ConfigManager().get_config('port')) + tmp_dict['avatar_url'] if options: options = safe_str_to_dict(options) options.update(tmp_dict) else: options = tmp_dict.copy() else: # 注入系统默认的头像 from tool.util import get_system_default_avatar_url tmp_dict = dict() tmp_dict['avatar_url'] = get_system_default_avatar_url() if options: options = safe_str_to_dict(options) options.update(tmp_dict) else: options = tmp_dict.copy() if subject: subject = safe_str_to_int(subject) if options: options = safe_str_to_dict(options) logging.info(options) self.set_header("Content-Type", "application/json;charset=utf8") result = register(username, password, grade, identifier, nickname, subject, serial_number, options=options) self.write(result) self.finish()
def post(self): username = self.get_argument('username') answer_id = safe_str_to_int(self.get_argument('answer_id')) ask_content = self.get_argument('ask_content') original_question_id = safe_str_to_int(self.get_argument('original_question_id')) be_asked_username = self.get_argument('be_asked_username') options = None # 拿到问题相关的图片 files = self.request.files if files: keys = ['ask_pic_file', 'ask_sound_file'] for key in keys: if key in files: tmp_file = files[key][0] file_name = tmp_file['filename'] from tool.util import get_file_extension, save_file suffix = get_file_extension(file_name) from dbop.dbQuestion import get_latest_id index = get_latest_id("tb_ask") new_file_name = "{0}_{1}{2}".format("ask", index, suffix) msg0 = "[in postQuestionServer] new_file_name=" + new_file_name logging.info(msg0) file_content = tmp_file['body'] # 注入url字段信息 tmp_dict = dict() if key == 'ask_pic_file': tmp_dict['ask_pic_url'] = save_file(new_file_name, file_content, 2) tmp_dict['ask_pic_url'] = "http://" + ConfigManager().get_config('host') + ":" + \ str(ConfigManager().get_config('port')) + tmp_dict['ask_pic_url'] elif key == 'ask_sound_file': tmp_dict['ask_sound_url'] = save_file(new_file_name, file_content, 3) tmp_dict['ask_sound_url'] = "http://" + ConfigManager().get_config('host') + ":" + \ str(ConfigManager().get_config('port')) + tmp_dict['ask_sound_url'] if options is None: options = tmp_dict.copy() else: options.update(tmp_dict) self.set_header("Content-Type", "application/json;charset=utf8") result = ask_question(username, answer_id, ask_content, original_question_id, be_asked_username, options=options) self.write(result) self.finish()
def post(self): username = self.get_argument('username') nickname = self.get_argument('nickname', None) phone_number = self.get_argument('phone_number', None) name = self.get_argument('name', None) sex = safe_str_to_dict(self.get_argument('sex', None)) birthday = self.get_argument('birthday', None) address = self.get_argument('address', None) grade = safe_str_to_int(self.get_argument('grade', None)) subject = safe_str_to_int(self.get_argument('subject', None)) options = dict() if nickname: options['nickname'] = nickname if phone_number: options['phone_number'] = phone_number if name: options['name'] = name if sex: options['sex'] = sex if birthday: options['birthday'] = birthday if address: options['address'] = address if grade: options['grade'] = grade if subject: options['subject'] = subject # 拿到用户头像 props = None files = self.request.files logging.info("start!!!") logging.info(files) if files: key = 'avatar_file' if key in files: avatar_file = files[key][0] file_name = avatar_file['filename'] from tool.util import get_file_extension, save_file suffix = get_file_extension(file_name) from dbop.dbUser import get_latest_id index = get_latest_id(username) new_file_name = "{0}_{1}{2}".format("user", index, suffix) msg0 = "[in modifyPersonalInformationServer] new_file_name=" + new_file_name logging.info(msg0) file_content = avatar_file['body'] # 注入头像url字段信息 tmp_dict = dict() tmp_dict['avatar_url'] = save_file(new_file_name, file_content, 1) tmp_dict['avatar_url'] = "http://" + ConfigManager().get_config('host') + ":" + \ str(ConfigManager().get_config('port')) + tmp_dict['avatar_url'] if props: props = safe_str_to_dict(props) props.update(tmp_dict) else: props = tmp_dict.copy() logging.info("yes!!!") logging.info(props) self.set_header("Content-Type", "application/json;charset=utf8") result = modify_personal_information(username, props=options, options=props) self.write(result) self.finish()