def reply(request, pk): """Reply to a thread --> new post.""" if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): p = form.cleaned_data thread = Thread.objects.get(pk=pk) post = Post.objects.create(thread=thread, title=p["title"], body=p["body"], creator=request.user) return HttpResponseRedirect(reverse("thread", args=[pk]) + "?page=last")
def post_dir(request, thread_id): thread_info = Thread.objects.get(pk=thread_id) post_list = Post.objects.filter(thread=thread_id) if request.method == "POST": form = PostForm(request.POST) post = form.save(commit=False) post.utilisateur = request.user post.thread = thread_info post.save() return HttpResponseRedirect(reverse("forum.views.post_dir", args=(thread_id,))) else: form = PostForm() return render_to_response( "forum/post.html", {"post_list": post_list, "thread_info": thread_info, "form": form}, context_instance=RequestContext(request), )
def post(request, ptype, pk): """Display a post form.""" action = reverse("%s" % ptype, args=[pk]) if ptype == "new_thread": title = "Start New Topic" subject = '' form = ThreadForm() elif ptype == "reply": title = "Reply to " + "\""+ Thread.objects.get(pk=pk).title + "\"" subject = "Re: " + Thread.objects.get(pk=pk).title form = PostForm(initial={'title': subject}) return render_to_response("forum/post.html", add_csrf(request, subject=subject, action=action, title=title, form=form, searchForm= ModelSearchForm()))
def post_dir(request, thread_id): thread_info = Thread.objects.get(pk=thread_id) post_list = Post.objects.filter(thread=thread_id) if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): thread = Post(thread=thread_info) form = PostForm(request.POST, instance=thread) form.save() return HttpResponseRedirect(reverse("forum.views.post_dir", args=(thread_id,))) else: form = PostForm() return render_to_response( "forum/post.html", {"post_list": post_list, "thread_info": thread_info, "form": form}, context_instance=RequestContext(request), )