def put(self, image_id): image_id = int(image_id) image = Image.get(id=image_id) if not image: raise tornado.web.HTTPError(404) album_id = self.get_int('album_id', None) if not album_id: return self.send_error_result(msg=u'没有指定专辑哦') album = Album.get(id=album_id) if not album: return self.send_error_result(msg=u'专辑不存在') if album.user_id != self.current_user.id: return self.send_error_result(msg=u'此专辑不是您的专辑') if image.album_id != album_id: image.album_id = album_id return self.send_success_result()
def put(self, image_id): image_id = int(image_id) image = Image.get(id=image_id) if not image: raise tornado.web.HTTPError(404) album_id = self.get_int('album_id', None) if not album_id: return self.send_error_result(msg=u'没有指定专辑哦') album = Album.get(id=album_id) if not album: return self.send_error_result(msg=u'专辑不存在') if album.user_id != self.current_user.id: return self.send_error_result(msg=u'此专辑不是您的专辑') if image.album_id != album_id: image.album_id = album_id return self.send_success_result()
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 delete(self, image_id): image = Image.get(id=image_id) if not image: return self.redirect_next_url() if image.topic_id: return self.send_error_result(msg='此图片被主题《%s》引用,无法删除' % image.topic.title) if self.current_user.is_admin and image.user_id != self.current_user.id: subject = "图片删除通知 - " + config.site_name template = ('<p>尊敬的 <strong>{nickname}</strong> 您好!</p>' '您在 {site} 的图片由于违反社区规定而被删除。</p>') content = template.format(nickname=image.author.nickname, site=config.site_name) self.send_email(self, image.author.email, subject, content) if self.current_user.is_admin or image.user_id == self.current_user.id: image.delete() result = {'status': 'success', 'message': '已成功删除'} else: result = {'status': 'error', 'message': '你没有权限啊, baby'} return self.write(result)
def delete(self, image_id): image = Image.get(id=image_id) if not image: return self.redirect_next_url() if image.topic_id: return self.send_error_result(msg=u'此图片被主题《%s》引用,无法删除' % image.topic.title) if self.current_user.is_admin and image.user_id != self.current_user.id: subject = "图片删除通知 - " + config.site_name template = ( '<p>尊敬的 <strong>%(nickname)s</strong> 您好!</p>' '您在 %(site)s 的图片由于违反社区规定而被删除。</p>' ) % { 'nickname': image.author.nickname, 'site': config.site_name, } self.send_email(self, image.author.email, subject, template) if self.current_user.is_admin or image.user_id == self.current_user.id: image.remove() result = {'status': 'success', 'message': '已成功删除'} else: result = {'status': 'error', 'message': '你没有权限啊, baby'} return self.write(result)
def get(self, image_id): image_id = int(image_id) image = Image.get(id=image_id) if not image: raise tornado.web.HTTPError(404) return self.render("image/index.html", image=image)
def get(self, image_id): image_id = int(image_id) image = Image.get(id=image_id) if not image: raise tornado.web.HTTPError(404) return self.render("image/index.html", image=image)