Beispiel #1
0
    def post(self):
        form = NodeDescriptionEditForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        node_id = form.node_id.data
        description = form.description.data

        node = yield NodeDocument.find_one({'_id': ObjectId(node_id)})
        if not node:
            raise HTTPError(404)

        yield NodeDocument.update({'_id': ObjectId(node_id)}, {
            '$set': {
                'description':
                description,
                'last_modified_by':
                DBRef(UserDocument.meta['collection'],
                      ObjectId(self.current_user['_id'])),
                'last_modified_time':
                datetime.now()
            }
        })

        node = yield NodeDocument.get_node(node_id)
        html = self.render_string('community/template/node-description.html',
                                  current_node=node)

        self.write_json({'html': html})
Beispiel #2
0
    def post(self):
        form = NodeDescriptionEditForm(self.request.arguments)
        if not form.validate():
            raise HTTPError(404)

        node_id = form.node_id.data
        description = form.description.data

        node = yield NodeDocument.find_one({'_id': ObjectId(node_id)})
        if not node:
            raise HTTPError(404)

        yield NodeDocument.update(
            {'_id': ObjectId(node_id)},
            {'$set': {
                'description': description,
                'last_modified_by': DBRef(
                    UserDocument.meta['collection'],
                    ObjectId(self.current_user['_id'])
                ),
                'last_modified_time': datetime.now()
            }}
        )

        node = yield NodeDocument.get_node(node_id)
        html = self.render_string(
            'community/template/node-description.html',
            current_node=node
        )

        self.write_json({'html': html})
Beispiel #3
0
    def get(self):
        sort = self.get_argument('sort', "time")
        if sort not in ['time', 'popularity']:
            sort = 'time'

        node = self.get_argument('node', None)
        try:
            page = max(int(self.get_argument("page", 1)), 1)
        except:
            page = 1

        query = {
            'user_id': self.current_user and self.current_user['_id'],
            'sort': sort,
            'skip': (page - 1) * COMMUNITY_SETTINGS["topic_number_per_page"],
            'limit': COMMUNITY_SETTINGS['topic_number_per_page']
        }
        if node:
            node = yield NodeDocument.get_node(node)
            if not node:
                raise HTTPError(404)

            query.update({'node_id': node['_id']})

        topic_list = yield TopicDocument.get_topic_list(**query)
        hot_topic_list = yield TopicDocument.get_hot_topic_list(
            period=timedelta(days=1),
            limit=COMMUNITY_SETTINGS['hot_topic_number']
        )
        hot_node_list = yield NodeDocument.get_hot_node_list(
            size=COMMUNITY_SETTINGS['hot_node_number']
        )
        top_header_node_list = yield NodeDocument.get_top_header_node_list()

        total_page, pages = self.paginate(
            (yield TopicDocument.get_topic_number(node and node['_id'])),
            COMMUNITY_SETTINGS['topic_number_per_page'],
            page
        )

        kwargs = {}
        if self.current_user:
            kwargs = yield self.get_sidebar_arguments()

        kwargs.update({
            'sort': sort,
            'current_node': node,
            'topic_list': topic_list,
            'hot_topic_list': hot_topic_list,
            'top_header_node_list': top_header_node_list,
            'hot_node_list': hot_node_list,
            'page': page,
            'total_page': total_page,
            'pages': pages
        })

        self.render('community/template/community.html', **kwargs)
Beispiel #4
0
    def get(self):
        sort = self.get_argument('sort', "time")
        if sort not in ['time', 'popularity']:
            sort = 'time'

        node = self.get_argument('node', None)
        try:
            page = max(int(self.get_argument("page", 1)), 1)
        except:
            page = 1

        query = {
            'user_id': self.current_user and self.current_user['_id'],
            'sort': sort,
            'skip': (page - 1) * COMMUNITY_SETTINGS["topic_number_per_page"],
            'limit': COMMUNITY_SETTINGS['topic_number_per_page']
        }
        if node:
            node = yield NodeDocument.get_node(node)
            if not node:
                raise HTTPError(404)

            query.update({'node_id': node['_id']})

        topic_list = yield TopicDocument.get_topic_list(**query)
        hot_topic_list = yield TopicDocument.get_hot_topic_list(
            period=timedelta(days=1),
            limit=COMMUNITY_SETTINGS['hot_topic_number'])
        hot_node_list = yield NodeDocument.get_hot_node_list(
            size=COMMUNITY_SETTINGS['hot_node_number'])
        top_header_node_list = yield NodeDocument.get_top_header_node_list()

        total_page, pages = self.paginate(
            (yield TopicDocument.get_topic_number(node and node['_id'])),
            COMMUNITY_SETTINGS['topic_number_per_page'], page)

        kwargs = {}
        if self.current_user:
            kwargs = yield self.get_sidebar_arguments()

        kwargs.update({
            'sort': sort,
            'current_node': node,
            'topic_list': topic_list,
            'hot_topic_list': hot_topic_list,
            'top_header_node_list': top_header_node_list,
            'hot_node_list': hot_node_list,
            'page': page,
            'total_page': total_page,
            'pages': pages
        })

        self.render('community/template/community.html', **kwargs)
Beispiel #5
0
    def get(self):
        node_id = self.get_argument("node_id", None)

        node = None
        if node_id:
            node = yield NodeDocument.get_node(node_id)
            if not node:
                node = None

        self.render("community/template/topic-new.html",
                    action="new",
                    node_one=node)
Beispiel #6
0
    def get(self):
        node_id = self.get_argument("node_id", None)

        node = None
        if node_id:
            node = yield NodeDocument.get_node(node_id)
            if not node:
                node = None

        self.render(
            "community/template/topic-new.html",
            action="new",
            node_one=node
        )
Beispiel #7
0
    def get(self, node_id):
        current_node = yield NodeDocument.get_node(node_id)
        if not current_node:
            raise HTTPError(404)

        sort = self.get_argument('sort', "time")
        if sort not in ['time', 'popularity']:
            sort = 'time'

        try:
            page = max(int(self.get_argument("page", 1)), 1)
        except:
            page = 1

        node_avatar_url = yield NodeAvatarDocument.get_node_avatar_url(
            node_id
        )
        topic_list = yield TopicDocument.get_topic_list(
            node_id=node_id,
            user_id=self.current_user and self.current_user['_id'],
            sort=sort,
            skip=(page - 1) * COMMUNITY_SETTINGS["topic_number_per_page"],
            limit=COMMUNITY_SETTINGS['topic_number_per_page']
        )
        active_author_list = yield TopicStatisticsDocument.get_active_author_list(
            node_id=node_id,
            period=timedelta(days=100),
            limit=10
        )
        total_page, pages = self.paginate(
            (yield TopicDocument.get_topic_number(current_node["_id"])),
            COMMUNITY_SETTINGS['topic_number_per_page'],
            page
        )

        kwargs = {
            'current_node': current_node,
            'node_avatar_url': node_avatar_url,
            'sort': sort,
            'topic_list': topic_list,
            'active_author_list': active_author_list,
            'page': page,
            'total_page': total_page,
            'pages': pages
        }

        self.render('community/template/node-one.html', **kwargs)
Beispiel #8
0
    def get(self, node_id):
        current_node = yield NodeDocument.get_node(node_id)
        if not current_node:
            raise HTTPError(404)

        sort = self.get_argument('sort', "time")
        if sort not in ['time', 'popularity']:
            sort = 'time'

        try:
            page = max(int(self.get_argument("page", 1)), 1)
        except:
            page = 1

        node_avatar_url = yield NodeAvatarDocument.get_node_avatar_url(node_id)
        topic_list = yield TopicDocument.get_topic_list(
            node_id=node_id,
            user_id=self.current_user and self.current_user['_id'],
            sort=sort,
            skip=(page - 1) * COMMUNITY_SETTINGS["topic_number_per_page"],
            limit=COMMUNITY_SETTINGS['topic_number_per_page'])
        active_author_list = yield TopicStatisticsDocument.get_active_author_list(
            node_id=node_id, period=timedelta(days=100), limit=10)
        total_page, pages = self.paginate(
            (yield TopicDocument.get_topic_number(current_node["_id"])),
            COMMUNITY_SETTINGS['topic_number_per_page'], page)

        kwargs = {
            'current_node': current_node,
            'node_avatar_url': node_avatar_url,
            'sort': sort,
            'topic_list': topic_list,
            'active_author_list': active_author_list,
            'page': page,
            'total_page': total_page,
            'pages': pages
        }

        self.render('community/template/node-one.html', **kwargs)