def get(self, topic_id): topic = yield TopicDocument.get_topic( topic_id, self.current_user and self.current_user['_id']) if not topic: raise HTTPError(404) if self.current_user and topic['author']['_id'] != self.current_user[ '_id']: yield TopicDocument.update({'_id': topic['_id']}, {'$inc': { 'read_times': 1 }}) comment_list = yield TopicCommentDocument.get_comment_list( topic['_id'], limit=COMMUNITY_SETTINGS['topic_comment_number_per_page']) recommend_topic_list = yield TopicDocument.get_recommend_topic_list( topic_id) like_list = yield TopicLikeDocument.get_like_list(topic_id) kwargs = { 'topic': topic, 'comment_list': comment_list, 'like_list': like_list, 'recommend_topic_list': recommend_topic_list, 'COMMUNITY_SETTINGS': COMMUNITY_SETTINGS } self.render('community/template/topic-one.html', **kwargs)
def get(self, topic_id): topic = yield TopicDocument.get_topic( topic_id, self.current_user and self.current_user['_id'] ) if not topic: raise HTTPError(404) if self.current_user and topic['author']['_id'] != self.current_user['_id']: yield TopicDocument.update( {'_id': topic['_id']}, {'$inc': {'read_times': 1}} ) comment_list = yield TopicCommentDocument.get_comment_list( topic['_id'], limit=COMMUNITY_SETTINGS['topic_comment_number_per_page'] ) recommend_topic_list = yield TopicDocument.get_recommend_topic_list( topic_id ) like_list = yield TopicLikeDocument.get_like_list(topic_id) kwargs = { 'topic': topic, 'comment_list': comment_list, 'like_list': like_list, 'recommend_topic_list': recommend_topic_list, 'COMMUNITY_SETTINGS': COMMUNITY_SETTINGS } self.render('community/template/topic-one.html', **kwargs)
def post(self): form = TopicEditForm(self.request.arguments) if not form.validate(): raise HTTPError(404) response_data = {} topic_id = form.topic_id.data title = form.title.data content = form.content.data nodes = form.nodes.data.split(',') anonymous = form.anonymous.data topic = yield TopicDocument.get_topic( topic_id, self.current_user['_id'] ) if (not topic or len(nodes) > 3 or topic['author']['_id'] != self.current_user['_id']): raise HTTPError(404) nodes = list(set(nodes)) node_ids = [] for node in nodes: existed = yield NodeDocument.find_one({'name': node}) if existed: node_id = existed['_id'] else: node_id = yield NodeDocument.insert({'name': node}) node_ids.append( DBRef(NodeDocument.meta['collection'], ObjectId(node_id)) ) document = { 'author': DBRef( UserDocument.meta['collection'], ObjectId(self.current_user['_id']) ), 'title': title, 'anonymous': anonymous, 'nodes': node_ids, 'content': content } images = yield self.get_images(content) document.update({'images': images}) topic_id = yield TopicDocument.update( {'_id': ObjectId(topic_id)}, {'$set': document} ) self.write_json(response_data)
def post(self): form = TopicEditForm(self.request.arguments) if not form.validate(): raise HTTPError(404) response_data = {} topic_id = form.topic_id.data title = form.title.data content = form.content.data nodes = form.nodes.data.split(',') anonymous = form.anonymous.data topic = yield TopicDocument.get_topic(topic_id, self.current_user['_id']) if (not topic or len(nodes) > 3 or topic['author']['_id'] != self.current_user['_id']): raise HTTPError(404) nodes = list(set(nodes)) node_ids = [] for node in nodes: existed = yield NodeDocument.find_one({'name': node}) if existed: node_id = existed['_id'] else: node_id = yield NodeDocument.insert({'name': node}) node_ids.append( DBRef(NodeDocument.meta['collection'], ObjectId(node_id))) document = { 'author': DBRef(UserDocument.meta['collection'], ObjectId(self.current_user['_id'])), 'title': title, 'anonymous': anonymous, 'nodes': node_ids, 'content': content } images = yield self.get_images(content) document.update({'images': images}) topic_id = yield TopicDocument.update({'_id': ObjectId(topic_id)}, {'$set': document}) self.write_json(response_data)