Beispiel #1
0
def posts_create(theme_num):

    form = PostForm(request.form)

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

    b = Topic(form.topic.data)
    old_topic = Topic.query.filter_by(name=form.topic.data).first()

    if not old_topic:
        b.theme_id = theme_num
        db.session().add(b)
        db.session().commit()
        Subject = Topic.query.filter_by(name=form.topic.data).first()

        a = Post(request.form.get("content"))
        a.topic = form.topic.data
        a.author = current_user.name
        a.account_id = current_user.id
        a.subject_id = Subject.id
        db.session().add(a)

        db.session().commit()

        return redirect(url_for("topic_id", theme_id=theme_num))

    else:
        flash("Topic already taken!")
        return render_template("posts/write.html",
                               form=form,
                               error="Topic already taken!",
                               theme_id=theme_num)
Beispiel #2
0
def posts_reply(topic_id):
    form = ReplyForm(request.form)
    subject = Topic.query.filter_by(id=topic_id).first()

    a = Post(request.form.get("content"))
    a.topic = subject.name
    a.author = current_user.name
    a.account_id = current_user.id
    a.subject_id = subject.id
    db.session().add(a)

    db.session().commit()

    return redirect(url_for("post_id", topic_id=topic_id))
Beispiel #3
0
def create_post(topic_id):
    topic = Topic.query.get(topic_id)

    if topic is None:
        return redirect(url_for("topics_index"))

    form = PostForm(request.form)

    if not form.validate():
        return render_template("topics/single.html", topic=topic, form=form)

    body = request.form.get("body")
    post = Post(body)
    post.topic = topic
    post.author_id = current_user.id

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

    return redirect(url_for("view_topic", topic_id=topic_id))