Пример #1
0
def index():
    """
    Index, showing a "NewThreadForm" and a
    list of all existing threads.

    """
    return render_template('index.html',
                           form=NewThreadForm(),
                           threads=Thread.query.join(Post)\
                                    .order_by(Post.time_created.desc()).all())
Пример #2
0
def new_thread():
    """
    POST API endpoint for creating new threads.
    """

    form = NewThreadForm()
    if form.validate_on_submit():

        data = form.data.copy()
        poster = Poster.from_details(data.pop('name'))
        t = poster.create_thread(**data)
        return redirect(url_for('thread', thread_id=t.id))

    else:
        flash_form_errors(form)
        return redirect(url_for('index'))