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