Example #1
0
def posts_create():
    form = PostForm(request.form)

    if (form.add_tag.data):
        form.tags.append(form.tag.data)
        form.tag.data = ''
        return render_template("posts/new.html", form=form)

    if not form.validate():
        return render_template("posts/new.html", form=form)

    p = Post(form.name.data, form.content.data)
    p.user_id = current_user.id

    db.session().add(p)
    db.session().commit()

    for tag in form.tags:
        tagd = Tag.query.filter_by(name=tag).first()
        if not tagd:
            t = Tag(tag)
            db.session().add(t)
            db.session().commit()
            pt = PostTag(t.id, p.id)
        else:
            pt = PostTag(tagd.id, p.id)

        db.session().add(pt)
        db.session().commit()

    PostForm.tags = []

    return redirect(url_for("posts_index"))
Example #2
0
def posts_create():
    form = PostForm(request.form)

    if not form.validate():
        return render_template("posts/new.html", form=form)

    p = Post(form.name.data, form.content.data)
    p.user_id = current_user.id

    db.session().add(p)
    db.session().commit()

    return redirect(url_for("posts_index"))
Example #3
0
def thread_reply(thread_id):
    thread = Thread.query.get(thread_id)

    form = PostForm(request.form)

    if not form.validate():
        return redirect(url_for("view_thread", thread_id=thread_id, form=form))

    post = Post(form.message.data)
    post.user_id = current_user.id
    post.thread_id = thread.id

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

    return redirect(
        url_for("view_thread", thread_id=thread_id, form=ThreadForm()))