def post(self,postid): md = self.get_argument('markdown') time_now = int(time()) user = self.current_user postid = int(postid) content = md_convert(md,notice=True,time=time_now,user=user['username'],db=self.db,postid=postid) post = self.db.posts.find_one({'_id':postid}) source = self.parse_user_agent() comment_reversed = reversed(post['comments']) for _ in range(min(len(post['comments']),5)):#look up in the recently 5 comment comment = comment_reversed.next() if comment['author'] == user['username'] and comment['content'] == content:#Reply has already been posted. self.redirect('/topics/'+str(postid)) return post['comments'].append({'author':user['username'], 'content':content, 'posttime':time_now, }) post['changedtime'] = time_now if source: post['comments'][-1]['source'] = source self.db.posts.save(post) try: del self.mc['index'] except KeyError: pass try: cache = self.mc[str(postid)] except KeyError: pass else: for i in range(len(post['comments'])): post['comments'][i]['location'] = str(i+1) cache[2] = self.render_string('modules/comments.html',db=self.db,time_span=time_span,post=post) self.mc[str(postid)] = cache self.redirect('/topics/'+str(postid)) url = '%s/topics/%s#reply-%s' % (self.application.settings['forum_url'],postid,len(post['comments'])) if user['twitter_bind'] and self.get_argument('twitter-sync') == 'yes': for i in set(html_killer.findall(content)): content = content.replace(i,'')#不知道为什么,直接用sub返回的是空字符串。 for i in set(username_finder.findall(content)): u = self.db.users.find_one({'username':i}) if u and 'twitter' in u: content = content.replace(u'@'+i,u' @'+user['twitter']) self.twitter_request( '/statuses/update', post_args={'status': u'%s %s' % (content,url)}, access_token=user['access_token'],callback=self._on_post) ping(self.application.settings['forum_title_e'],self.application.settings['forum_url'],url)
def post(self): title = xhtml_escape(self.get_argument('title')) assert len(title)<51 user = self.current_user md = self.get_argument('markdown') posts = self.db.posts tags = [] for x in set(xhtml_escape(self.get_argument('tags').lower()).split(' ')): tags.append(x) post = self.db.posts.find_one({'title':title,'author':user['username'],'tags':tags}) if post:#Topic has already been posted. self.redirect('/topics/'+str(post['_id'])) return time_now = int(time()) tid = self.db.settings.find_and_modify(update={'$inc':{'post_id':1}}, new=True)['post_id'] posts.insert({'_id':tid, 'title':title, 'author':user['username'], 'content':md_convert(md,notice=True,time=time_now,user=user['username'],db=self.db,postid=tid), 'comments':[], 'posttime':int(time()), 'changedtime':int(time()), 'tags':tags, }) for tag in tags: self.db.tags.update({'name':tag}, {'$inc':{'count':1}}, True) try: del self.mc['index'] del self.mc['tagcloud:10'] del self.mc['tagcloud:False'] except KeyError: pass self.redirect('/topics/'+str(tid)) url = '%s/topics/%s' % (self.application.settings['forum_url'],tid) if user['twitter_bind'] and self.get_argument('twitter-sync') == 'yes': self.twitter_request( '/statuses/update', post_args={'status': u'%s %s' % (title,url)}, access_token=user['access_token'],callback=self._on_post) ping(self.application.settings['forum_title_e'],self.application.settings['forum_url'],url)
def post(self): self.write(md_convert(self.get_argument('md','')))