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))