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