Example #1
0
def admin_posts_edit(post_id):
    post = Post.find_one(post_id)

    if request.method == 'POST':
        title = request.form["title"]
        content = request.form["content"]
        Post.admin_sent_posts_edit(post_id, title, content)
        return redirect(url_for('admins.admin_home'))

    request.form.title = post["subject"]
    request.form.content = post["content"]

    return render_template("admin/edit.html")
Example #2
0
def edit_post(post_id):
    """
    Edit sent post.
    :param post_id: _id of the post for edit that.
    :return: Edited post.
    """
    form = EditForm()
    post = Post.find_one(post_id)

    if request.method == 'POST':
        subject = form.subject.data
        content = form.content.data

        if subject is not None and content is not None:
            Post.edit(post_id, subject, content)
            flash("Post edited.")
            return redirect(url_for('posts.view_sent_posts', post=post))

        flash("fields can not be empty.")
        return redirect(url_for('posts.edit_post', post_id=post_id))

    form.subject.data = post["subject"]
    form.content.data = post["content"]
    return render_template('post/edit.html', form=form)