diff gpp/forums/views.py @ 89:021492db4aad

Forums: Got the reply function working.
author Brian Neal <bgneal@gmail.com>
date Sat, 12 Sep 2009 21:29:31 +0000
parents 515d1daec811
children 317c7bcaecee
line wrap: on
line diff
--- a/gpp/forums/views.py	Sat Sep 12 18:51:55 2009 +0000
+++ b/gpp/forums/views.py	Sat Sep 12 21:29:31 2009 +0000
@@ -3,11 +3,13 @@
 """
 from django.contrib.auth.decorators import login_required
 from django.http import Http404
+from django.http import HttpResponseBadRequest
 from django.http import HttpResponseRedirect
 from django.core.urlresolvers import reverse
 from django.shortcuts import get_object_or_404
 from django.shortcuts import render_to_response
 from django.template import RequestContext
+from django.views.decorators.http import require_POST
 
 from forums.models import Forum
 from forums.models import Topic
@@ -67,7 +69,7 @@
         'topic': topic,
         'posts': posts,
         'last_page': last_page,
-        'form': PostForm(),
+        'form': PostForm(initial={'topic_id': topic.id}),
         },
         context_instance=RequestContext(request))
 
@@ -105,3 +107,24 @@
         'topic': topic,
         },
         context_instance=RequestContext(request))
+
+
+@login_required
+@require_POST
+def quick_reply_ajax(request):
+    """
+    This function handles the quick reply to a thread function. This
+    function is meant to be the target of an AJAX post, and returns
+    the HTML for the new post, which the client-side script appends
+    to the document.
+    """
+    form = PostForm(request.POST)
+    if form.is_valid():
+        post = form.save(request.user, request.META.get("REMOTE_ADDR"))
+        return render_to_response('forums/display_post.html', {
+            'post': post,
+            },
+            context_instance=RequestContext(request))
+
+    return HttpResponseBadRequest();
+