Exemple #1
0
 def new_message_compat(self, msg):
     user = yield self.get_auth_user()
     if user and ['user', msg['user']] in user.get('blacklist', []):
         return
     msg = msg.copy()
     replace_banned(self.regions(), msg)
     self.write_message(json.dumps(msg))
Exemple #2
0
    def respond(self, username, tag=None):
        _ = yield self.get_auth_user()
        f = [("date", -1)]
        user = (yield objs.User.find_one({'name': username}))
        page = get_page(self)
        qdict = {'recommendations': username}
        if tag:
            tag = tornado.escape.url_unescape(tag)
            qdict['tags'] = tag
        messages = list((yield objs.Message.find_sort(qdict,
                                                      sort=f,
                                                      limit=20,
                                                      skip=20 * page)))
        for message in messages:
            replace_banned(self.regions(), message)
        hasmes = yield is_hasmes(qdict, page)

        self.set_header("Cache-Control", "max-age=1")
        defer.returnValue({
            'username': username,
            'user': user,
            'messages': messages,
            'page': page,
            'tag': tag,
            'hasmes': hasmes,
        })
Exemple #3
0
 def new_message_compat(self, msg):
     user = yield self.get_auth_user()
     if user and ['user', msg['user']] in user.get('blacklist', []):
         return
     msg = msg.copy()
     replace_banned(self.regions(), msg)
     self.write_message(json.dumps(msg))
Exemple #4
0
 def new_comment(self, comment):
     user = yield self.get_auth_user()
     if user and ['user', comment['user']] in user.get('blacklist', []):
         return
     html = uimodules.Comment(self).render(comment)
     comment = comment.copy()
     replace_banned(self.regions(), comment, 'comment')
     comment.update(dict(type='new_comment', html=html))
     self.write_message(json.dumps(comment))
Exemple #5
0
 def new_comment(self, comment):
     user = yield self.get_auth_user()
     if user and ['user', comment['user']] in user.get('blacklist', []):
         return
     html = uimodules.Comment(self).render(comment)
     comment = comment.copy()
     replace_banned(self.regions(), comment, 'comment')
     comment.update(dict(type='new_comment', html=html))
     self.write_message(json.dumps(comment))
Exemple #6
0
 def new_message(self, msg):
     user = yield self.get_auth_user()
     if user and ['user', msg['user']] in user.get('blacklist', []):
         return
     html = uimodules.Message(self).render(msg)
     msg = msg.copy()
     replace_banned(self.regions(), msg)
     if user:
         msg['subscribed'] = user['name'] == msg['user']
     msg.update(dict(type='new_message', html=html))
     self.write_message(json.dumps(msg))
Exemple #7
0
 def new_message(self, msg):
     user = yield self.get_auth_user()
     if user and ['user', msg['user']] in user.get('blacklist', []):
         return
     html = uimodules.Message(self).render(msg)
     msg = msg.copy()
     replace_banned(self.regions(), msg)
     if user:
         msg['subscribed'] = user['name'] == msg['user']
     msg.update(dict(type='new_message', html=html))
     self.write_message(json.dumps(msg))
Exemple #8
0
    def respond(self, username, reco=None, tag=None):
        _ = yield self.get_auth_user()
        f = [("date", -1)]
        user = (yield objs.User.find_one({'name': username}))
        page = get_page(self)

        if reco == "recommendations":
            qdict = {'recommendations': username}
        elif reco == "all":
            qdict = {
                '$or': [{
                    'user': username
                }, {
                    'recommendations': username
                }]
            }
        else:
            qdict = {'user': username}

        if tag:
            tag = tornado.escape.url_unescape(tag)
            qdict['tags'] = tag
        messages = list((yield objs.Message.find_sort(qdict,
                                                      sort=f,
                                                      limit=20,
                                                      skip=20 * page)))
        for message in messages:
            replace_banned(self.regions(), message)
        hasmes = yield is_hasmes(qdict, page)

        format = self.get_argument("format", "")
        if format == 'rss':
            self.set_header("Content-Type",
                            'application/rss+xml; charset=UTF-8')
            defer.returnValue(
                rss.message_feed(messages,
                                 link=widgets.user_url(username),
                                 title='Поток сознания @%s' % username))
        elif format == 'json':
            json_messages = [message.filter_fields() for message in messages]
            defer.returnValue(json.dumps(json_messages, ensure_ascii=False))
        else:
            self.set_header("Cache-Control", "max-age=1")
            defer.returnValue({
                'username': username,
                'user': user,
                'messages': messages,
                'page': page,
                'tag': tag,
                'hasmes': hasmes,
            })
Exemple #9
0
    def respond(self, username, reco=None, tag=None):
        _ = yield self.get_auth_user()
        f = [("date", -1)]
        user = (yield objs.User.find_one({'name': username}))
        page = get_page(self)

        if reco == "recommendations":
            qdict = {'recommendations': username}
        elif reco == "all":
            qdict = {'$or': [{'user': username}, {
                'recommendations': username}]}
        else:
            qdict = {'user': username}

        if tag:
            tag = tornado.escape.url_unescape(tag)
            qdict['tags'] = tag
        messages = list((yield objs.Message.find_sort(qdict, sort=f, limit=20, skip=20 * page)))
        for message in messages:
            replace_banned(self.regions(), message)
        hasmes = yield is_hasmes(qdict, page)

        format = self.get_argument("format", "")
        if format == 'rss':
            self.set_header(
                "Content-Type", 'application/rss+xml; charset=UTF-8')
            defer.returnValue(rss.message_feed(messages,
                                               link=widgets.user_url(username),
                                               title='Поток сознания @%s' % username))
        elif format == 'json':
            json_messages = [message.filter_fields() for message in messages]
            defer.returnValue(json.dumps(json_messages, ensure_ascii=False))
        else:
            self.set_header("Cache-Control", "max-age=1")
            defer.returnValue({
                'username': username,
                'user': user,
                'messages': messages,
                'page': page,
                'tag': tag,
                'hasmes': hasmes,
            })
Exemple #10
0
    def respond(self, username, tag=None):
        _ = yield self.get_auth_user()
        f = [("date", -1)]
        user = (yield objs.User.find_one({'name': username}))
        page = get_page(self)
        qdict = {'recommendations': username}
        if tag:
            tag = tornado.escape.url_unescape(tag)
            qdict['tags'] = tag
        messages = list((yield objs.Message.find_sort(qdict, sort=f, limit=20, skip=20 * page)))
        for message in messages:
            replace_banned(self.regions(), message)
        hasmes = yield is_hasmes(qdict, page)

        self.set_header("Cache-Control", "max-age=1")
        defer.returnValue({
            'username': username,
            'user': user,
            'messages': messages,
            'page': page,
            'tag': tag,
            'hasmes': hasmes,
        })
Exemple #11
0
 def new_comment_compat(self, comment):
     comment = comment.copy()
     replace_banned(self.regions(), comment, 'comment')
     self.write_message(json.dumps(comment))
Exemple #12
0
 def new_comment_compat(self, comment):
     comment = comment.copy()
     replace_banned(self.regions(), comment, 'comment')
     self.write_message(json.dumps(comment))