def _reply_list_dump(reply_list, can_admin, current_user_id): result = [] career_bind(reply_list, "user_id") ico_url_bind_with_default(tuple(i.user for i in reply_list)) pre_user_id = None for reply in reply_list: user = reply.user career = reply.career career = " , ".join(filter(bool,career)) if not career: career = 0 user_id = user.id reply_tuple = ( reply.htm, reply.id, can_admin or reply.can_admin(current_user_id) ) if user_id == pre_user_id: result[-1][-1].append(reply_tuple) else: result.append( (url_or_id(user_id), user.name , career, user.ico, [reply_tuple]) ) pre_user_id = user_id return result
def vps_new(vps): username = USERNAME%vps.id_in_group if exists("/home/%s"%username): print username, "exist" return if not vps.passwd: vps.passwd = passwd() vps.state = STATE_VPS_OPENED vps.save() user_mail = mail_by_user_id(vps.user_id) with open(TEMPLATE_VPS_SH_PATH) as template: cmd = Template(template.read()).render( username=username, passwd=vps.passwd, prefix=PREFIX, user_mail=user_mail, user_url=url_or_id(vps.user_id) , ) tmp_sh = '%s/tmp_sh.sh'%PREFIX with open(tmp_sh, 'w') as tmp: tmp.write(cmd) sh = 'sudo sh %s'%tmp_sh r = envoy.run(sh) print r.std_out print r.std_err os.remove(tmp_sh) vps_open_mail(user_mail, vps.group, username, vps.passwd)
def vps_new(vps): username = USERNAME % vps.id_in_group if exists("/home/%s" % username): print username, "exist" return if not vps.passwd: vps.passwd = passwd() vps.state = STATE_VPS_OPENED vps.save() user_mail = mail_by_user_id(vps.user_id) with open(TEMPLATE_VPS_SH_PATH) as template: cmd = Template(template.read()).render( username=username, passwd=vps.passwd, prefix=PREFIX, user_mail=user_mail, user_url=url_or_id(vps.user_id), ) tmp_sh = '%s/tmp_sh.sh' % PREFIX with open(tmp_sh, 'w') as tmp: tmp.write(cmd) sh = 'sudo sh %s' % tmp_sh r = envoy.run(sh) print r.std_out print r.std_err os.remove(tmp_sh) vps_open_mail(user_mail, vps.group, username, vps.passwd)
def _reply_list_dump(reply_list, can_admin, current_user_id): result = [] career_bind(reply_list, "user_id") ico_url_bind_with_default(tuple(i.user for i in reply_list)) pre_user_id = None for reply in reply_list: user = reply.user career = reply.career career = " , ".join(filter(bool, career)) if not career: career = 0 user_id = user.id reply_tuple = (reply.htm, reply.id, can_admin or reply.can_admin(current_user_id)) if user_id == pre_user_id: result[-1][-1].append(reply_tuple) else: result.append((url_or_id(user_id), user.name, career, user.ico, [reply_tuple])) pre_user_id = user_id return result
def get(self, id): po = Po.mc_get(id) user_id = self.current_user_id result = [] if po and po.can_view(user_id): for reply in po.reply_list(): user = reply.user result.append((url_or_id(user.id), reply.htm, user.name)) return self.finish(dumps(result))
def get(self, id): po = Po.mc_get(id) user_id = self.current_user_id result = [] if po and po.can_view(user_id): for reply in po.reply_list(): user = reply.user result.append( (url_or_id(user.id), reply.htm, user.name) ) return self.finish(dumps(result))
def _get(self, func): key = self.get_argument('q', None) user_id = self.current_user_id result = [] if user_id: name_dict, url_dict = func(user_id) id_list = zsite_by_key(key, name_dict, url_dict, 7) zsite_list = Zsite.mc_get_list(id_list) ico_url_bind_with_default(zsite_list) career_bind(zsite_list) for i in zsite_list: li = (i.name, ','.join(i.career), url_or_id(i.id), i.ico) result.append(li) #print result self.finish(jsonp(self, dumps(result)))