コード例 #1
0
ファイル: views.py プロジェクト: imfht/flaskapps
def delete_thread(thread_uid):
    """Delete given thread and all its comments.

    :param thread_uid: Thread unique ID.
    """
    thread = storage.get_thread(thread_uid)
    if not thread:
        abort(404)

    if thread['author'] != g.username:
        abort(403)

    if request.method == 'GET':
        return render_template('delete_thread.html',
                               thread=thread,
                               thread_uid=thread_uid)

    if request.form.get('confirm') != 'confirm':
        return error('delete_thread:confirm')

    storage.delete_thread(thread_uid)
    flash('Thread Succesfully Deleted: {0}'.format(thread['subject']),
          'success')

    return to_threads()
コード例 #2
0
ファイル: views.py プロジェクト: imfht/flaskapps
def comments(thread_uid):
    """List all comments in given thread.

    :param thread_uid: Thread unique ID.
    """
    thread = storage.get_thread(thread_uid, counter=True)
    if not thread:
        abort(404)
    return render_template('comments.html',
                           comments=storage.list_comments(thread_uid),
                           thread=thread,
                           thread_uid=thread_uid)
コード例 #3
0
ファイル: views.py プロジェクト: imfht/flaskapps
def comment(thread_uid):
    """Add new comment to given thread.

    :param thread: Thread unique ID.
    """
    thread = storage.get_thread(thread_uid)
    if not thread:
        abort(404)

    text = request.form.get('text') or ''
    if not text:
        return error('comment:text')

    storage.add_comment(thread_uid, g.username, text)
    flash('Your comment successfully added!', 'success')

    return redirect(url_for('comments', thread_uid=thread_uid))