コード例 #1
0
    def get(self):
        '''朋友首页'''

        kwargs = yield self.get_sidebar_arguments()

        friend_list = yield FriendDocument.get_friend_list(
            self.current_user['_id'])
        kwargs.update({'friend_list': friend_list})
        self.render('home/template/friend/friend.html', **kwargs)
コード例 #2
0
ファイル: document.py プロジェクト: forging2012/Young
    def get_friends_status_list(user_id, skip=0, limit=None):
        '''得到user_id的朋友的状态, 包括自己.

        :Parameters:
          - `user_id`: 用户id
          - `skip`: 默认0
          - `limit`: 默认None
        '''

        friend_list = yield FriendDocument.get_friend_list(user_id)
        shielded_friend_list = yield FriendDocument.get_shielded_friends(
            user_id
        )
        blocked_friend_list = yield FriendDocument.get_blocked_friends(
            user_id
        )

        all_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in friend_list
        ]

        shielded_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in shielded_friend_list
        ]

        blocked_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in blocked_friend_list
        ]

        friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(user_id))
        ]

        for friend in all_friend_dbref_list:
            if (friend not in shielded_friend_dbref_list and
                    friend not in blocked_friend_dbref_list):
                friend_dbref_list.append(friend)

        cursor = StatusDocument.find({
            'author': {'$in': friend_dbref_list}
        }).sort([('publish_time', pymongo.DESCENDING)]).skip(skip)

        if limit is not None:
            cursor = cursor.limit(limit)

        status_list = yield StatusDocument.to_list(cursor)
        status_list = yield StatusDocument.translate_dbref_in_document_list(
            status_list
        )
        status_list = yield StatusDocument._extend_status_list(
            status_list, user_id
        )

        raise gen.Return(status_list)
コード例 #3
0
    def get_friends_status_list(user_id, skip=0, limit=None):
        '''得到user_id的朋友的状态, 包括自己.

        :Parameters:
          - `user_id`: 用户id
          - `skip`: 默认0
          - `limit`: 默认None
        '''

        friend_list = yield FriendDocument.get_friend_list(user_id)
        shielded_friend_list = yield FriendDocument.get_shielded_friends(
            user_id)
        blocked_friend_list = yield FriendDocument.get_blocked_friends(user_id)

        all_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in friend_list
        ]

        shielded_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in shielded_friend_list
        ]

        blocked_friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(friend['_id']))
            for friend in blocked_friend_list
        ]

        friend_dbref_list = [
            DBRef(UserDocument.meta['collection'], ObjectId(user_id))
        ]

        for friend in all_friend_dbref_list:
            if (friend not in shielded_friend_dbref_list
                    and friend not in blocked_friend_dbref_list):
                friend_dbref_list.append(friend)

        cursor = StatusDocument.find({
            'author': {
                '$in': friend_dbref_list
            }
        }).sort([('publish_time', pymongo.DESCENDING)]).skip(skip)

        if limit is not None:
            cursor = cursor.limit(limit)

        status_list = yield StatusDocument.to_list(cursor)
        status_list = yield StatusDocument.translate_dbref_in_document_list(
            status_list)
        status_list = yield StatusDocument._extend_status_list(
            status_list, user_id)

        raise gen.Return(status_list)
コード例 #4
0
ファイル: handler.py プロジェクト: forging2012/Young
    def get(self):
        '''朋友首页'''

        kwargs = yield self.get_sidebar_arguments()

        friend_list = yield FriendDocument.get_friend_list(
            self.current_user['_id']
        )
        kwargs.update({
            'friend_list': friend_list
        })
        self.render('home/template/friend/friend.html', **kwargs)