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'))
def new_post(thread_id): """ POST API endpoint for creating a new post for the thread with given `thread_id`. Also returns a 404 if it doesn't exist. """ t = Thread.query.get_or_404(thread_id) form = NewPostForm() if form.validate_on_submit(): data = form.data.copy() poster = Poster.from_details(data.pop('name')) poster.create_post(t, **data) return redirect(url_for('thread', thread_id=thread_id)) else: flash_form_errors(form) return redirect(url_for('thread', thread_id=thread_id))