def delete(self, user_id: int, post_id: int): """ Delete a post 1. User needs to be logged in 2. This deletes the post whose ID is specified on the url 3. This process is irreversible """ check_id_availability(self, user_id, users_list, str(User.__name__)) this_post = check_id_availability(self, post_id, posts_list, str(Post.__name__)) if current_user.id != user_id: users_ns.abort(403) for post in posts_list: if post.user_id == user_id and post.id == post_id: this_post = post break else: users_ns.abort(400, 'the requested user does not own this post') try: current_user.delete_post(this_post) except AssertionError as a: users_ns.abort(400, a.args[0]) response = self.api.make_response(None, 204) return response
def delete_post(id): post = Post.query.get_or_404(id) if current_user != post.author and \ not current_user.can(Permission.ADMINISTER): abort(403) current_user.delete_post(post) flash(u'你删除了一篇文章') if session.get('current_url') and (session.get('current_path') != ('/post/%d' % id)): return redirect(session.get('current_url')) else: return redirect(url_for('.user', username=current_user.username))
def delete_blog(id): blog = Post.query.get(id) if blog is None: flash('the blog id is not valid!') else: if current_user.id != blog.author_id: flash('你不是该微博的作者,不能删除该微博') return redirect(url_for('main.post', id=blog.id)) else: current_user.delete_post(blog) flash('成功删除一条微博') return redirect(url_for('main.blogs', username=current_user.username)) return redirect(url_for('main.index'))
def delete(self, user_id: int): """ Batch delete all user's posts 1. User must be logged in to delete all their posts 2. This deletes all posts that a user has created 3. This process os of course irreversible """ check_id_availability(user_id, users_list, str(User.__name__)) if current_user.id != user_id: users_ns.abort(403) my_posts_list = current_user.get_my_posts() for a_post in my_posts_list: try: current_user.delete_post(a_post) except PostTransactionError as e: users_ns.abort(e.abort_code, e.msg) return None, 204
def delete(self, user_id: int): """ Batch delete all user's posts 1. User must be logged in to delete all their posts 2. This deletes all posts that a user has created 3. This process os of course irreversible """ check_id_availability(self, user_id, users_list, str(User.__name__)) if current_user.id != user_id: users_ns.abort(403) my_posts_list, my_posts_list_output = self.my_posts(user_id) for a_post in my_posts_list: try: current_user.delete_post(a_post) except AssertionError as a: users_ns.abort(400, a.args[0]) return None, 204
def delete_post(post_id): current_user.delete_post(post_id) return redirect(request.referrer)