Ejemplo n.º 1
0
    def get(self):
        form = MessageForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        category = form.category.data

        kwargs = yield self.get_sidebar_arguments()

        if category == MessageTopic.CHAT_MESSAGE_NEW:
            message_list = yield ChatMessageDocument.get_chat_message_list(
                self.current_user['_id'],
                limit=HOME_SETTINGS['message_number_per_page']
            )
        else:
            message_list = yield MessageDocument.get_message_list(
                self.current_user['_id'],
                message_topic=category,
                limit=HOME_SETTINGS['message_number_per_page']
            )

            yield MessageDocument.set_read(self.current_user['_id'], category)

        kwargs.update({
            'message_list': message_list,
            'category': category
        })

        self.render('home/template/message/message.html', **kwargs)
Ejemplo n.º 2
0
    def get(self):
        form = MessageForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        category = form.category.data

        kwargs = yield self.get_sidebar_arguments()

        if category == MessageTopic.CHAT_MESSAGE_NEW:
            message_list = yield ChatMessageDocument.get_chat_message_list(
                self.current_user['_id'],
                limit=HOME_SETTINGS['message_number_per_page']
            )
        else:
            message_list = yield MessageDocument.get_message_list(
                self.current_user['_id'],
                message_topic=category,
                limit=HOME_SETTINGS['message_number_per_page']
            )

            yield MessageDocument.set_read(self.current_user['_id'], category)

        kwargs.update({
            'message_list': message_list,
            'category': category
        })

        self.render('home/template/message/message.html', **kwargs)
Ejemplo n.º 3
0
    def post(self):
        '''加载更多消息'''

        form = MessageMoreForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        page = form.page.data
        category = form.category.data

        skip = HOME_SETTINGS['message_number_per_page'] * page
        limit = HOME_SETTINGS['message_number_per_page']

        if category == MessageTopic.CHAT_MESSAGE_NEW:
            message_list = yield ChatMessageDocument.get_chat_message_list(
                self.current_user['_id'],
                skip=skip,
                limit=limit
            )
        else:
            message_list = yield MessageDocument.get_message_list(
                self.current_user['_id'],
                message_topic=category,
                skip=skip,
                limit=limit
            )

        if category == MessageTopic._FRIENDS_DYNAMIC:
            path = 'message-friends-dynamic-list-item.html'
        elif category == MessageTopic._COMMENT_AND_REPLY:
            path = 'message-comment-and-reply-list-item.html'
        elif category == MessageTopic.AT:
            path = 'message-at-list-item.html'
        elif category == MessageTopic.CHAT_MESSAGE_NEW:
            path = 'message-chat-message-list-item.html'
        elif category == MessageTopic.FRIEND_REQUEST_NEW:
            path = 'message-friend-request-list-item.html'
        elif category == MessageTopic.LIKE:
            path = 'message-like-list-item.html'

        path = os.path.join("home/template/message", path)

        html = ''.join(
            self.render_string(
                path, message=message, MessageTopic=MessageTopic
            ) for message in message_list
        )

        response_data = json.dumps({'html': html, 'page': page + 1})
        self.finish(response_data)
Ejemplo n.º 4
0
    def post(self):
        '''加载更多消息'''

        form = MessageMoreForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        page = form.page.data
        category = form.category.data

        skip = HOME_SETTINGS['message_number_per_page'] * page
        limit = HOME_SETTINGS['message_number_per_page']

        if category == MessageTopic.CHAT_MESSAGE_NEW:
            message_list = yield ChatMessageDocument.get_chat_message_list(
                self.current_user['_id'],
                skip=skip,
                limit=limit
            )
        else:
            message_list = yield MessageDocument.get_message_list(
                self.current_user['_id'],
                message_topic=category,
                skip=skip,
                limit=limit
            )

        if category == MessageTopic._FRIENDS_DYNAMIC:
            path = 'message-friends-dynamic-list-item.html'
        elif category == MessageTopic._COMMENT_AND_REPLY:
            path = 'message-comment-and-reply-list-item.html'
        elif category == MessageTopic.AT:
            path = 'message-at-list-item.html'
        elif category == MessageTopic.CHAT_MESSAGE_NEW:
            path = 'message-chat-message-list-item.html'
        elif category == MessageTopic.FRIEND_REQUEST_NEW:
            path = 'message-friend-request-list-item.html'
        elif category == MessageTopic.LIKE:
            path = 'message-like-list-item.html'

        path = os.path.join("home/template/message", path)

        html = ''.join(
            self.render_string(
                path, message=message, MessageTopic=MessageTopic
            ) for message in message_list
        )

        self.write_json({'html': html, 'page': page + 1})