def to_html(self, result): """ Takes a result, converts it to Unicode (assumes result is MARC8), escapes characters for HTML, and adds linebreak tags where newlines occur. """ result = result.replace('\n', '<br/>\n') sanitized = htmlquote(result) return sanitized.replace('<br/>', '<br/>\n')
def POST(slef): iflogin() data = web.input() column_name = data.get('column_name', '') if column_name: key = hashlib.md5(column_name+str(time.time())).hexdigest() value_dict = {'key':key, 'name':htmlquote(column_name)} update_column(key, value_dict) raise web.seeother('/%s/columns'%ADMIN)
def test_central_corridor_dodge(): testApp, form, resp = start_central_corridor() # test dodge death form['action'] = 'dodge' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(central_corridor_dodge.description)) testApp.get('/logout') testApp.reset()
def test_the_bridge_death(): testApp, form, resp = enter_the_bridge() # test the_bridge death form['action'] = 'throw the bomb' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge_death.description)) testApp.get('/logout') testApp.reset()
def newPost(postImage, postTitle, postCaption, postArticle, postAuthor, postTemp, nodeId): if postImage != '': postImage = postImage.split('_')[0] + "_" + postImage.split('_')[1] + "_" + postImage.split('_')[2]; postArticle = htmlquote(postArticle).strip() # postArticle = postArticle.replace("\r\n", "<br/>") db.insert('_post', postImage=postImage, postTitle=postTitle, postCaption=postCaption, postArticle=postArticle, postAuthor=postAuthor, postTemp=postTemp, nodeId= nodeId) db.query("UPDATE _node set postMount=postMount+1 WHERE id=$id", vars=dict(id=nodeId))
def POST(self, pid): data = web.input() uid = user.id aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来 p = postModel.getPostByPostId(pid) #得到目标post reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' comment = data.postComment comment = htmlquote(comment).strip().replace("\r\n", "<br/>") usernames = re.findall(reg_regchar, comment) nicknames = [] nickname_list = [] mid_list = [] # @提醒 for i in xrange(len(usernames)): if not users.is_username_available(usernames[i]): nicknames += users.get_user_by_username(usernames[i]).nickname.replace(' ', ' ').split() comment = comment.replace('@'+ usernames[i], '@<a href="/member/'+ usernames[i] +'">' + nicknames[i] + '</a>') #得到@的用户id 以|分割组成字符串 mid_list += str(users.get_user_by_username(usernames[i]).id).split() #去重 mid_list = sorted(set(mid_list),key=mid_list.index) #以字符串形势保存@到的uid,以|分割 # mention_id_list = '|'.join(mid_list) else: nicknames += usernames[i].split() comment = comment.replace('@'+ usernames[i], '@' + nicknames[i]) # @提醒 for mid in mid_list: if int(mid) != int(aid): notification.new_mention_notification(pid, p.nodeId, aid, uid,mid) print '=======notification send=====' # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人 #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int if int(aid) != int(uid): notification.new_notification(aid, uid, pid, p.nodeId, tp=1) #如果开启了邮件提醒,给作者发送邮件 author = users.get_user_by_id(aid) person = users.get_profile_by_user_id(aid) p = postModel.getPostByPostId(pid) #得到目标post if person.has_key('email_subscribe') and person.email_subscribe == 1 and author.email: email_templates.someone_comment_ur_post(user, author, p) print '=== email send ==' postModel.add_post_comment(comment, uid, pid) #得到刚刚添加的comment的id,返回ajax给li添加id 供删除用 last_comment = postModel.get_just_added_comment(uid, pid).id return '{"status": "y", "comment_id": "'+ str(last_comment) +'"}'
def POST(self): iflogin() data = web.input() title = data.get('title', '') content = data.get('content', '') column = data.get('column', '') tag = data.get('tag', '') c_time = datetime.datetime.now() key = data.get('key', '') if not key: key = hashlib.md5(title+str(time.time())).hexdigest() value_dict = { 'key':key, 'title':htmlquote(title), 'content':content, 'c_time':c_time, 'column':htmlquote(column), 'tag':[htmlquote(t) for t in tag.split(',')] } update_article(key, value_dict) raise web.seeother('/%s/article'%ADMIN)
def POST(self,arg): data = web.input() #note : 需要判断user的身份,是不是作者 postCaption = data.post_Caption postArticle = data.post_Article # postArticle = htmlquote(postArticle).strip().replace("\r\n", "<br/>") postArticle = htmlquote(postArticle).strip() id = arg #youku postArticle = misc.youku(postArticle) postModel.post_update(id, postCaption = postCaption, postArticle=postArticle) return '{"status": "y", "info": "更新成功"}'
def GET(self): iflogin() data = web.input() new_name = data.get('new_name', '') key = data.get('key', '') if new_name and key: value_dict = {'key':key, 'name':htmlquote(new_name)} update_column(key, value_dict) raise web.seeother('/%s/columns'%ADMIN) else: cs = get_columns() content = {'columns':cs} return template_render('admin_columns.html', PATH, content)
def test_central_corridor(): testApp, form, resp = start_central_corridor() # test try again form['action'] = 'iadsjklds' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(central_corridor.try_again)) # test help form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(central_corridor.help)) # test path to Laser Weapon Armory form['action'] = 'tell a joke' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(laser_weapon_armory.description)) testApp.get('/logout') testApp.reset()
def test_the_bridge(): testApp, form, resp = enter_the_bridge() # test try again form['action'] = 'iadsjklds' form.method = 'POST' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.try_again)) # test help form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.help)) # test path to Escape Pod form['action'] = 'slowly place the bomb' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(escape_pod.description)) testApp.get('/logout') testApp.reset()
def test_escape_pod_death(): testApp, form, resp = enter_escape_pod() #test path to the_end_loser if escape_pod.secret == '1': test_input = '2' else: test_input = '1' form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_end_loser.description)) testApp.get('/logout') testApp.reset()
def test_escape_pod(): testApp, form, resp = enter_escape_pod() # test invalid input # Case 1: digit not 1-5 form['action'] = '9' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(escape_pod.try_again)) # test invalid input # Case 2: input not in lexicon form['action'] = 'f**k you' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(escape_pod.try_again)) # test invalid input # Case 3: input in lexicon, but does not match room.filter form['action'] = 'tell a joke' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(escape_pod.try_again)) # test help form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(escape_pod.help)) # test path to the_end_winner form['action'] = escape_pod.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_end_winner.description)) testApp.get('/logout') testApp.reset()
def GET(self, key): if key: key = htmlquote(key) article = get_article(key) if article: column_key = article.get('column', '') columns = get_columns(column_key) if columns: article['column_name'] = columns[0].get('name', '') content = {'article':article} return template_render('article.html', PATH, content) else: raise web.seeother('/') else: raise web.seeother('/')
def GET(self): data = web.input() page = data.get('page', 1) column_key = htmlquote(data.get('coumn_key', '')) try: int(page) except: page = 1 articles = get_articles(column_key = column_key,page = page) arts = {'articles':{}} for c in articles: key = str(c.get('key','')) title = str(c.get('title','')) if key and title: arts['articles'][key] = {'key':key, 'title':title} return json.dumps(arts,cls=JSONDateTimeEncoder)
def html_quote(text): return net.htmlquote(text)
def test_laser_weapon_armory_guesses(): testApp, form, resp = enter_laser_weapon_armory() # test help form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(laser_weapon_armory.help)) # test invalid input form['action'] = '1' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) form['action'] = 'tell a joke' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) form['action'] = 'f**k you' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) # test 10 wrong guesses if laser_weapon_armory.secret == '999': test_input = '998' else: test_input = '999' resp.mustcontain('You have 10 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 9 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 8 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 7 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 6 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 5 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 4 tries left') # Test help in between lock code attempts. This should not # alter number of guesses used or remaining. form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(laser_weapon_armory.help)) # continue checking remaining guesses form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 3 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 2 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 1 try left') #last guess, a wrong entry here should equal death form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(laser_weapon_armory_death.description)) testApp.get('/logout') testApp.reset()
def POST(self, pid): data = web.input() uid = user.id aid = data.aid #note : 需要改成在后端通过pid得到aid,不能从前端传过来 p = postModel.getPostByPostId(pid) #得到目标post reg_regchar = '@([a-zA-Z0-9][\w\-\.\_]+)' comment = data.postComment comment = htmlquote(comment).strip().replace("\r\n", "<br/>") usernames = re.findall(reg_regchar, comment) nicknames = [] nickname_list = [] mid_list = [] # @提醒 for i in xrange(len(usernames)): if not users.is_username_available(usernames[i]): nicknames += users.get_user_by_username( usernames[i]).nickname.replace(' ', ' ').split() comment = comment.replace( '@' + usernames[i], '@<a href="/member/' + usernames[i] + '">' + nicknames[i] + '</a>') #得到@的用户id 以|分割组成字符串 mid_list += str(users.get_user_by_username( usernames[i]).id).split() #去重 mid_list = sorted(set(mid_list), key=mid_list.index) #以字符串形势保存@到的uid,以|分割 # mention_id_list = '|'.join(mid_list) else: nicknames += usernames[i].split() comment = comment.replace('@' + usernames[i], '@' + nicknames[i]) # @提醒 for mid in mid_list: if int(mid) != int(aid): notification.new_mention_notification(pid, p.nodeId, aid, uid, mid) print '=======notification send=====' # 评论提醒 tp=1 表示是评论类型的提醒 同时判断是不是本人评论本人 #这里很奇怪,不能直接判断aid 和 uid 是否相等,必须转成int if int(aid) != int(uid): notification.new_notification(aid, uid, pid, p.nodeId, tp=1) #如果开启了邮件提醒,给作者发送邮件 author = users.get_user_by_id(aid) person = users.get_profile_by_user_id(aid) p = postModel.getPostByPostId(pid) #得到目标post if person.has_key( 'email_subscribe' ) and person.email_subscribe == 1 and author.email: email_templates.someone_comment_ur_post(user, author, p) print '=== email send ==' postModel.add_post_comment(comment, uid, pid) #得到刚刚添加的comment的id,返回ajax给li添加id 供删除用 last_comment = postModel.get_just_added_comment(uid, pid).id return '{"status": "y", "comment_id": "' + str(last_comment) + '"}'
def test_laser_weapon_armory_lock(): # test lock code on first guess testApp, form, resp = enter_laser_weapon_armory() form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset() # test lock code after displaying help testApp, form, resp = enter_laser_weapon_armory() form['action'] = 'help' form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(laser_weapon_armory.help)) form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset() # test lock code after wrong guesses if laser_weapon_armory.secret == '999': test_input = '998' else: test_input = '999' testApp, form, resp = enter_laser_weapon_armory() form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 9 tries left') form['action'] = test_input form.submit() resp = testApp.get('/game') resp.mustcontain('You have 8 tries left') form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset() # test lock code after invalid input # Case 1: input not recognized by lexicon testApp, form, resp = enter_laser_weapon_armory() form['action'] = 'f**k you' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset() # test lock code after invalid input # Case 2: input recognized by lexicon, but does not match room.filter testApp, form, resp = enter_laser_weapon_armory() form['action'] = 'tell a joke' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset() # test lock code after invalid input # Case 3: Not enough digits. (does not match room.filter) testApp, form, resp = enter_laser_weapon_armory() form['action'] = '1' form.submit() resp = testApp.get('/game') resp.mustcontain('You have 10 tries left') resp.mustcontain(net.htmlquote(laser_weapon_armory.try_again)) form['action'] = laser_weapon_armory.secret form.submit() resp = testApp.get('/game') resp.mustcontain(net.htmlquote(the_bridge.description)) testApp.get('/logout') testApp.reset()