def post(self, *args, **kwargs): f = AccountForm(self.request.arguments) if not f.validate(): errors = f.errors error = "".join(errors.values()[0][0]) r = {"r": 0, "error": error} self.write(r) return url = "" try: if self.request.files["avatar"]: file_body = self.request.files["avatar"][0]["body"] url = upload(file_body, Image.FOLDER_AVATAR) except KeyError: url = "" aid = key_util.generate_hexdigits_lower(8) token = key_util.generate_hexdigits_lower(8) account = self.account_manager.get_account_by_aid(aid) while account: aid = key_util.generate_hexdigits_lower(8) account = self.account_manager.get_account_by_aid(aid) self.account_manager.create_account( f.data["wei_id"], f.data["wei_name"], f.data["wei_account"], token, aid, url, self.current_user.id ) r = {"r": 1, "aid": aid} self.write(r)
def post(self, *args, **kwargs): result = {'r': 1} title = self.get_argument('title', '') content = self.get_argument('content', '') slug = key_util.generate_hexdigits_lower(8) while self.article_manager.exists_article(slug): slug = key_util.generate_hexdigits_lower(8) self.article_manager.save_article(slug, title, content, self.account.aid) result['aid'] = self.account.aid self.write(result) self.finish() return
def post(self, *args, **kwargs): """提交会员卡创建信息""" card = self.card_manager.get_card_by_aid(self.account.aid) register = self.get_argument('register', 0) name = self.get_argument('name', 0) mobile = self.get_argument('mobile', 0) address = self.get_argument('address', 0) sex = self.get_argument('sex', 0) birthday = self.get_argument('birthday', 0) phone = self.get_argument('phone', None) about = self.get_argument('about', None) thumb = self.get_argument('thumb', None) cover = self.get_argument('cover', None) if not card: # 如果还没创建,则创建 cid = key_util.generate_hexdigits_lower(8) self.card_manager.save_card(self.account.aid, cid, register, name, mobile, address, phone, about, cover, int(sex), int(birthday)) card = self.card_manager.get_card_by_aid(self.account.aid) self.image_article_manager.save_single_image_article('会员卡', '点击查看会员卡', 'http://www.wsmt.cn/card/' + card.cid, thumb, self.account.aid) else: # 如果已经存在,则更新信息 self.card_manager.update_card(card.cid, register, name, mobile, address, phone, about, cover, int(sex), int(birthday)) result = {'r': 1} self.write(result) self.finish()
def upload(file_content, prefix): """ 上传图片到七牛云存储 返回图片完整地址 """ key = str(prefix) + "_" + key_util.generate_hexdigits_lower(16) ret, err = qiniu.io.put(policy.token(), key, file_content, extra) if err is None: return Image.URL_PREFIX % ret["key"] else: return None
def post(self, *args, **kwargs): """创建表单""" result = {'r': 0} name = self.get_argument('name', None) params = self.get_argument('params', None) if not name or not params: result['error'] = '参数不正确' self.write(result) self.finish() self.form_manager.save_form(name, key_util.generate_hexdigits_lower(8), self.account.aid, params) result['r'] = 1 result['aid'] = self.account.aid self.write(result) self.finish()
def post(self, *args, **kwargs): aid = self.account.aid params = self.get_argument('params', None) if not params: result = {'r': 0, 'e': u'参数不正确'} self.write(result) self.finish() return ps = simplejson.loads(params, encoding='utf-8') _type = int(ps['type']) title = ps['title'] if 'title' in ps else '' thumb = ps['thumb'] if 'thumb' in ps else '' lists = ps['lists'] if 'lists' in ps else '' slug = key_util.generate_hexdigits_lower(8) self.template_manager.save_template(aid, title, slug, _type, thumb) for i, l in enumerate(lists): l_title = l['title'] if 'title' in l else '' l_link = l['link'] if 'link' in l else '' l_thumb = l['thumb'] if 'thumb' in l else '' self.template_manager.save_template_list(slug, l_title, l_link, l_thumb, i) self.write({'r': 1}) self.finish() return
def post(self, *args, **kwargs): """设置自定义菜单""" aid = self.account.aid params = self.get_argument('params', None) result = {'r': 1} button = [] if not params: result['r'] = 0 result['error'] = u'自定义菜单不能为空' self.write(result) self.finish() return params = simplejson.loads(params, encoding='utf-8') # 先清空已保存的菜单记录 self.menu_manager.truncate_account_menu(aid) # 清空菜单相关的自动回复 self.auto_manager.truncate_account_menu_auto(aid) for param in params: name = param['name'] _type = param['type'] if _type == 'button': _id = self.menu_manager.save_main_menu_item(aid, name) menu = {'name': name} sub_buttons = [] for sub_button in param['sub_buttons']: mkey = key_util.generate_hexdigits_lower(8) sub_name = sub_button['name'] sub_type = sub_button['type'] sub_value = sub_button['value'] if sub_type == 'text': auto_id = self.auto_manager.save_text_auto_response(aid=aid, content=sub_value, mkey=mkey, re_type='text') self.menu_manager.save_sub_menu_item(aid=aid, name=sub_name, t='click', url=None, auto_id=auto_id, parent_id=_id, mkey=mkey) sub_menu = {'type': 'click', 'name': sub_name, 'key': mkey} elif sub_type == 'single': auto_id = self.auto_manager.save_image_article_auto_response(aid=aid, re_type='single', re_img_art_id=sub_value, mkey=mkey) self.menu_manager.save_sub_menu_item(aid=aid, name=sub_name, t='click', url=None, auto_id=auto_id, parent_id=_id, mkey=mkey) sub_menu = {'type': 'click', 'name': sub_name, 'key': mkey} elif sub_type == 'multi': auto_id = self.auto_manager.save_image_article_auto_response(aid=aid, re_type='multi', re_img_art_id=sub_value, mkey=mkey) self.menu_manager.save_sub_menu_item(aid=aid, name=sub_name, t='click', url=None, auto_id=auto_id, parent_id=_id, mkey=mkey) sub_menu = {'type': 'click', 'name': sub_name, 'key': mkey} elif sub_type == 'link': self.menu_manager.save_sub_menu_item(aid=aid, name=sub_name, t='view', url=sub_value, auto_id=0, parent_id=_id, mkey=None) sub_menu = {'type': 'view', 'name': sub_name, 'url': sub_value} sub_buttons.append(sub_menu) menu['sub_button'] = sub_buttons elif _type == 'text': value = param['value'] mkey = key_util.generate_hexdigits_lower(8) auto_id = self.auto_manager.save_text_auto_response(aid=aid, content=value, mkey=mkey, re_type='text') self.menu_manager.save_main_menu_item_response(aid=aid, name=name, t='click', url=None, auto_id=auto_id, mkey=mkey) menu = {'type': 'click', 'name': name, 'key': mkey} elif _type == 'single': value = param['value'] mkey = key_util.generate_hexdigits_lower(8) auto_id = self.auto_manager.save_image_article_auto_response(aid=aid, re_type='single', re_img_art_id=value, mkey=mkey) self.menu_manager.save_main_menu_item_response(aid=aid, name=name, t='click', url=None, auto_id=auto_id, mkey=mkey) menu = {'type': 'click', 'name': name, 'key': mkey} elif _type == 'multi': value = param['value'] mkey = key_util.generate_hexdigits_lower(8) auto_id = self.auto_manager.save_image_article_auto_response(aid=aid, re_type='multi', re_img_art_id=value, mkey=mkey) self.menu_manager.save_main_menu_item_response(aid=aid, name=name, t='click', url=None, auto_id=auto_id, mkey=mkey) menu = {'type': 'click', 'name': name, 'key': mkey} elif _type == 'link': value = param['value'] self.menu_manager.save_main_menu_item_response(aid=aid, name=name, t='view', url=value, auto_id=0, mkey=None) menu = {'type': 'view', 'name': name, 'url': value} button.append(menu) button = {'button': button} wei_api.set_menu(self.account, button) self.write(result) self.finish() return