def edit_post(post_id): post = Post.query.filter_by(id=post_id).first_or_404() if not can_edit_post(user=current_user, post=post): flash(_("You do not have the permissions to edit this post."), "danger") return redirect(post.topic.url) form = ReplyForm() if form.validate_on_submit(): if "preview" in request.form: return render_template("forum/new_post.html", topic=post.topic, form=form, preview=form.content.data) else: form.populate_obj(post) post.date_modified = datetime.datetime.utcnow() post.modified_by = current_user.username post.save() return redirect(post.topic.url) else: form.content.data = post.content return render_template("forum/forum/new_post.html", topic=post.topic, form=form)
def reply_post(topic_id, post_id): topic = Topic.query.filter_by(id=topic_id).first_or_404() post = Post.query.filter_by(id=post_id).first_or_404() if not can_post_reply(user=current_user, topic=topic): flash(_("You do not have the permissions to post in this topic."), "danger") return redirect(topic.forum.url) form = ReplyForm() if form.validate_on_submit(): if "preview" in request.form: return render_template("forum/new_post.html", topic=topic, form=form, preview=form.content.data) else: form.save(current_user, topic) return redirect(post.topic.url) else: form.content.data = format_quote(post.user_id, post.content) return render_template("forum/forum/new_post.html", topic=post.topic, form=form)