Пример #1
0
Файл: post.py Проект: henter/PBB
    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)
Пример #2
0
Файл: auth.py Проект: henter/PBB
 def post(self):
     user = self.current_user
     for x in ('location','twitter','github','css','words'):
         user[x] = xhtml_unescape(self.get_argument(x,''))
         for x in set(html_killer.findall(user[x])):
             user[x] = user[x].replace(x,'')
     website = self.get_argument('website','')
     w = urlparse(website)
     if w[0] and w[1]:
         user['website'] = website
     else:
         user['website'] = ''
     self.db.users.save(user)
     self.redirect('/user/%s' % user['username'] )