Beispiel #1
0
def edit(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.edit.test(403)

    form = PostForm(obj=post)
    if form.validate_on_submit():

        form.populate_obj(post)
        db.session.commit()

        if g.user.id != post.author_id:
            body = render_template("emails/post_edited.html",
                                   post=post)

            message = Message(subject="Your post has been edited",
                              body=body,
                              recipients=[post.author.email])

            mail.send(message)

            flash(_("The post has been updated"), "success")

        else:
            flash(_("Your post has been updated"), "success")
        return redirect(url_for("post.view", post_id=post_id))

    return render_template("post/edit_post.html",
                           post=post,
                           form=form)
Beispiel #2
0
def edit(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.edit.test(403)

    form = PostForm(obj=post)
    if form.validate_on_submit():

        form.populate_obj(post)
        db.session.commit()

        if g.user.id != post.author_id:
            body = render_template("emails/post_edited.html", post=post)

            message = Message(subject="Your post has been edited",
                              body=body,
                              recipients=[post.author.email])

            mail.send(message)

            flash(_("The post has been updated"), "success")

        else:
            flash(_("Your post has been updated"), "success")
        return redirect(url_for("post.view", post_id=post_id))

    return render_template("post/edit_post.html", post=post, form=form)
Beispiel #3
0
def submit():

    form = PostForm()
    
    if form.validate_on_submit():

        post = Post(author=g.user)
        form.populate_obj(post)

        db.session.add(post)
        db.session.commit()

        flash(_("Thank you for posting"), "success")

        return redirect(url_for("frontend.latest"))

    return render_template("submit.html", form=form)
Beispiel #4
0
def submit():

    form = PostForm()

    if form.validate_on_submit():

        post = Post(author=g.user)
        form.populate_obj(post)

        db.session.add(post)
        db.session.commit()

        flash(_("Thank you for posting"), "success")

        return redirect(url_for("frontend.latest"))

    return render_template("submit.html", form=form)