def save(self, user, topic, reply=None): data = self.data content = str(data.get('content')) data.update({ 'user_id': user.id, 'topic_id': topic.id, 'content': strip_xss_tags(content) }) if reply: category = 'edit' pre_content = reply.content cur_content = data.get('content') changed = 0 if pre_content != cur_content: diff_content = ghdiff.diff(pre_content, cur_content, css=None) changed = 1 if changed == 1: reply.content = cur_content History(user_id=user.id, content=diff_content, reply_id=reply.id).save() else: return reply else: category = 'create' reply = Reply(**data) return reply.save(category=category)
def save(self, user, topic=None): data = self.data node_name = data.pop('node_name', None) if not node_name: logging.info('no node_name in form data, data: %s', data) if not self.node: self.node = Node.get(name=node_name) if not self.node: logging.info('node is None in form instance, self: %s', self) content = unicode(data.get('content')) data.update({ 'user_id': user.id, 'node_id': self.node.id, 'content': strip_xss_tags(content) }) if topic: category = 'edit' pre_node_id = topic.node_id pre_title = topic.title pre_content = topic.content cur_node_id = data.get('node_id') cur_title = data.get('title') cur_content = data.get('content') changed = 0 if pre_node_id != cur_node_id: topic.node.topic_count -= 1 self.node.topic_count += 1 diff_content = '主题节点从' + '<a class="node" href="' +\ topic.node.url + '">' + topic.node.name +\ '</a>移动到<a class="node" href="' + self.node.url + '">' +\ self.node.name + '</a>' changed = 1 if pre_title != cur_title or pre_content != cur_content: content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content diff_content = ghdiff.diff(content1, content2, css=None) changed = 1 if changed == 1: topic.node_id = cur_node_id topic.title = cur_title topic.content = cur_content History(user_id=user.id, content=diff_content, topic_id=topic.id).save() else: return topic else: category = 'create' topic = Topic(**data) return topic.save(category=category)
def save(self, user, topic=None): data = self.data node_name = data.pop('node_name', None) if not node_name: logging.info('no node_name in form data, data: %s', data) if not self.node: self.node = Node.get(name=node_name) if not self.node: logging.info('node is None in form instance, self: %s', self) content = str(data.get('content')) data.update({'user_id': user.id, 'node_id': self.node.id, 'content': strip_xss_tags(content)}) if topic: category = 'edit' pre_node_id = topic.node_id pre_title = topic.title pre_content = topic.content cur_node_id = data.get('node_id') cur_title = data.get('title') cur_content = data.get('content') changed = 0 if pre_node_id != cur_node_id: topic.node.topic_count -= 1 self.node.topic_count += 1 diff_content = '主题节点从' + '<a class="node" href="' +\ topic.node.url + '">' + topic.node.name +\ '</a>移动到<a class="node" href="' + self.node.url + '">' +\ self.node.name + '</a>' changed = 1 if pre_title != cur_title or pre_content != cur_content: content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content diff_content = ghdiff.diff(content1, content2, css=None) changed = 1 if changed == 1: topic.node_id = cur_node_id topic.title = cur_title topic.content = cur_content History(user_id=user.id, content=diff_content, topic_id=topic.id).save() else: return topic else: category = 'create' topic = Topic(**data) return topic.save(category=category)
def post(self): user = self.current_user content = self.get_argument('content', None) image_ids = self.get_argument('image_ids', None) images = [] if not (content and len(strip_tags(content)) >= 3): result = { 'status': 'error', 'message': '推文内容至少 3 字符' } return self.send_result(result, '/timeline') tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save() tweet.put_notifier() if image_ids: image_ids = image_ids.split(',') for image_id in image_ids: image_id = int(image_id) image = Image.get(id=image_id) if not image: continue image.tweet_id = tweet.id images.append({ 'id': image.id, 'path': image.path, 'width': image.width, 'height': image.height, }) if images: tweet.has_img = 'true' result = { 'status': 'success', 'message': '推文创建成功', 'content': tweet.content, 'name': tweet.author.name, 'nickname': tweet.author.nickname, 'author_avatar': tweet.author.get_avatar(size=48), 'author_url': tweet.author.url, 'author_name': tweet.author.name, 'author_nickname': tweet.author.nickname, 'tweet_url': tweet.url, 'created': tweet.created, 'id': tweet.id, 'images': images, } return self.send_result(result, '/timeline')
def post(self): user = self.current_user content = self.get_argument('content', None) image_ids = self.get_argument('image_ids', None) images = [] if not (content and len(strip_tags(content)) >= 3): result = {'status': 'error', 'message': '推文内容至少 3 字符'} return self.send_result(result, '/timeline') tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save() tweet.put_notifier() if image_ids: image_ids = image_ids.split(',') for image_id in image_ids: image_id = int(image_id) image = Image.get(id=image_id) if not image: continue image.tweet_id = tweet.id images.append({ 'id': image.id, 'path': image.path, 'width': image.width, 'height': image.height, }) if images: tweet.has_img = 'true' result = { 'status': 'success', 'message': '推文创建成功', 'content': tweet.content, 'name': tweet.author.name, 'nickname': tweet.author.nickname, 'author_avatar': tweet.author.get_avatar(size=48), 'author_url': tweet.author.url, 'author_name': tweet.author.name, 'author_nickname': tweet.author.nickname, 'tweet_url': tweet.url, 'created': tweet.created, 'id': tweet.id, 'images': images, } return self.send_result(result, '/timeline')
def save(self, user, topic, reply=None): data = self.data content = str(data.get('content')) data.update({'user_id': user.id, 'topic_id': topic.id, 'content': strip_xss_tags(content)}) if reply: category = 'edit' pre_content = reply.content cur_content = data.get('content') changed = 0 if pre_content != cur_content: diff_content = ghdiff.diff(pre_content, cur_content, css=None) changed = 1 if changed == 1: reply.content = cur_content History(user_id=user.id, content=diff_content, reply_id=reply.id).save() else: return reply else: category = 'create' reply = Reply(**data) return reply.save(category=category)
def save(self, user): data = self.data name = unicode(data.get('name')) data.update({'user_id': user.id, 'name': strip_xss_tags(name)}) album = Album(**data) return album.save()