def forum_view(request, id, slug): """ Render the forum (the thread list), also handle the new thread form """ forum = get_object_or_404(Forum, pk=id) captcha_error = '' if request.POST: result = new_thread(request, forum=forum, user=request.user) if result.errors: threadform = result.threadform postform = result.postform captcha_error = result.captcha_error else: # this function was called after a new thread was made, instead of # returning back to the forum page, redirect to the newly # created thread return HttpResponseRedirect(result.thread.get_absolute_url()) if not request.POST or not result.errors: postform = PostForm() threadform = ThreadForm() if "-" + slugify(forum.name) != slug: # slug does not match, redirect to the correct slug return HttpResponseRedirect(forum.get_absolute_url()) threads = forum.threads_by_bumped() c = {'threads': threads, 'forum': forum, 'new_form': render_new_form(postform=postform, threadform=threadform, user=request.user, captcha_error=captcha_error)} return render_to_response('forum/forum.html', c, context_instance=RequestContext(request))
def thread_view(request, id, slug): """ Render the thread and all the posts in it """ thread = get_object_or_404(Thread, pk=id) captcha_error = '' errors = None if "-" + slugify(thread.title) != slug: # slug does not match, redirect to the correct slug return HttpResponseRedirect(thread.get_absolute_url()) if request.POST: result = new_post(request, thread=thread, user=request.user) if result.errors: # some errors occured, reuse all form objects postform = result.postform captcha_error = result.captcha_error if not request.POST or not result.errors: if thread.forum.force_anon: default_user = None else: default_user = request.user.id postform = PostForm() c = {'posts': thread.post_set.all(), 'thread': thread, 'forum': thread.forum, 'new_form': render_new_form(postform=postform, user=request.user, captcha_error=captcha_error)} return render_to_response('forum/thread.html', c, context_instance=RequestContext(request))