示例#1
0
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")
示例#2
0
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()))