|
@ -1,5 +1,5 @@ |
|
|
from flask import render_template, redirect, url_for, flash, request, \ |
|
|
from flask import render_template, redirect, url_for, flash, request, \ |
|
|
current_app |
|
|
|
|
|
|
|
|
current_app, abort |
|
|
from flask_login import login_required, current_user |
|
|
from flask_login import login_required, current_user |
|
|
from . import main |
|
|
from . import main |
|
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm |
|
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm |
|
@ -88,3 +88,21 @@ def edit_profile_admin(id): |
|
|
def post(id): |
|
|
def post(id): |
|
|
post = Post.query.get_or_404(id) |
|
|
post = Post.query.get_or_404(id) |
|
|
return render_template('post.html', posts=[post]) |
|
|
return render_template('post.html', posts=[post]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route('/edit/<int:id>', methods=['GET', 'POST']) |
|
|
|
|
|
@login_required |
|
|
|
|
|
def edit(id): |
|
|
|
|
|
post = Post.query.get_or_404(id) |
|
|
|
|
|
if current_user != post.author and \ |
|
|
|
|
|
not current_user.can(Permission.ADMIN): |
|
|
|
|
|
abort(403) |
|
|
|
|
|
form = PostForm() |
|
|
|
|
|
if form.validate_on_submit(): |
|
|
|
|
|
post.body = form.body.data |
|
|
|
|
|
db.session.add(post) |
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
flash('The post has been updated.') |
|
|
|
|
|
return redirect(url_for('.post', id=post.id)) |
|
|
|
|
|
form.body.data = post.body |
|
|
|
|
|
return render_template('edit_post.html', form=form) |