Exemplo n.º 1
0
def edit(post_id):
    try:
        oid = ObjectId(post_id)
    except:
        return redirect(url_for("newpost"))
    post = db.posts.find_one({"_id": oid})
    if request.method == 'GET':
        form = EditPostForm()
        form.post_id.data = post_id
        form.title.data = post['title']
        form.content.data = post['body']
        return render_template("write.html", form=form, post_id=post_id)
    else:
        form = NewPostForm(request.form)
        if form.validate():
            title = form.title.data
            body = form.content.data
            md = Markdown()
            html = md.convert(gfm(body))
            db.posts.update(
                {"_id": oid},
                {"$set": {
                    "title": title,
                    "body": body,
                    "html": html
                }})
            return redirect(url_for("home"))
        else:
            return render_template("write.html", form=form, post_id=post_id)
Exemplo n.º 2
0
def edit(post_id):
    try:
        oid = ObjectId(post_id)
    except:
        return redirect(url_for("newpost"))
    post = db.posts.find_one({"_id":oid})
    if request.method == 'GET':
        form = EditPostForm()
        form.post_id.data = post_id
        form.title.data = post['title']
        form.content.data = post['body']
        return render_template("write.html", form=form, post_id=post_id)
    else:
        form = NewPostForm(request.form)
        if form.validate():
            title = form.title.data
            body = form.content.data
            md = Markdown()
            html = md.convert(gfm(body))
            db.posts.update({"_id":oid}, {"$set" :{"title":title, "body":body, "html":html}})
            return redirect(url_for("home"))
        else:
            return render_template("write.html", form=form, post_id=post_id)
Exemplo n.º 3
0
def edit_post(postid, content, return_where):
    if not permission_to_edit_post(session['userid'], postid):
        flash("You don't have permission to edit this content.")
        return redirect(url_for('error'))

    edit_form = EditPostForm(request.form)
    if edit_form.validate() and request.method == 'POST':
        edit_post_controller(postid, edit_form.content.data)
        if return_where == 'userpage':
            # get userid of page where post belongs to
            userpage = get_page(postid).ownerid
            return redirect(url_for('user_page', userid=userpage))
        elif return_where == 'grouppage':
            grouppage = get_page(postid).groupid
            return redirect(url_for('group_page', groupid=grouppage))
        else:
            return redirect(url_for('post_page', postid=postid))
    else:
        edit_form = EditPostForm()
        edit_form.content.data = content
        return render_template('pages/editpost.html',
                               form=edit_form,
                               content=content)