def blog_view(post_id, slug): post = Posts.by_id(post_id) tags = Tag.query.join(FatJunction, FatJunction.tag_id==Tag.id) \ .filter(FatJunction.blog_id==post.id).all() return render_template('blog_view.html', post=post, tags=tags)
def blog_delete(): post = Posts.by_id(request.args.get('post_id')) if post.author.id != current_user.id: return redirect(url_for('index')) db.session.delete(post) db.session.commit() flash('Post removed successfully!') url = url_for('index') return redirect(url)
def blog_edit(post_id, slug): post = Posts.by_id(post_id) if post.author.id != current_user.id: return redirect(url_for('index')) form = NewPost(**post.__dict__) if form.validate_on_submit(): post.title = form.data['title'] post.headline = form.data['headline'] post.body = form.data['body'] db.session.commit() flash('Post updated successfully!') url = url_for('blog_view', post_id=post.id, slug=post.slug) return redirect(url) return render_template('blog_edit.html', form=form, post=post)