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)
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)
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)
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)