示例#1
0
def new_thread(request, pk):
    """Start a new thread."""
    if request.method == 'POST':
        form = ThreadForm(request.POST)
        if form.is_valid():
            p = form.cleaned_data
            forum = Forum.objects.get(pk=pk)
            """ save the thread in table Thread"""
            thread = Thread.objects.create(forum=forum, title=p["title"], creator=request.user)
            """ save the thread in table Post, too """
            Post.objects.create(thread=thread, title=p["title"], body=p["body"], creator=request.user)
        return HttpResponseRedirect(reverse("forum", args=[pk]))
示例#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()))