diff gpp/shoutbox/views.py @ 12:f408971657b9

Changed the shoutbox: posts are now made by Ajax. The smiley farm is loaded only on demand. jQuery is now in the base template. May add scrolling later.
author Brian Neal <bgneal@gmail.com>
date Wed, 15 Apr 2009 01:13:17 +0000
parents dbd703f7d63a
children 777451a98f9d
line wrap: on
line diff
--- a/gpp/shoutbox/views.py	Tue Apr 14 02:35:35 2009 +0000
+++ b/gpp/shoutbox/views.py	Wed Apr 15 01:13:17 2009 +0000
@@ -10,6 +10,7 @@
 from django.http import HttpResponseForbidden
 from django.http import HttpResponseRedirect
 from django.contrib.auth.decorators import login_required
+from django.views.decorators.http import require_POST
 
 from core.paginator import DiggPaginator
 from shoutbox.forms import ShoutBoxForm
@@ -18,14 +19,18 @@
 SHOUTS_PER_PAGE = 10
 
 @login_required
+@require_POST
 def shout(request):
-    if request.method == 'POST':
-        msg = request.POST.get('msg', '').strip()
-        if msg != '':
-            shout = Shout(user=request.user, shout=msg)
-            shout.save()
-            
-    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
+    msg = request.POST.get('msg', '').strip()
+    if msg == '':
+        return HttpResponse('')
+
+    shout = Shout(user=request.user, shout=msg)
+    shout.save()
+    return render_to_response('shoutbox/shout.html', {
+       'shout': shout,
+       },
+       context_instance = RequestContext(request))
 
 
 def view(request, page=1):
@@ -101,3 +106,5 @@
         return HttpResponse(id)
 
     return HttpResponseForbidden()
+
+# vim: ts=4 sw=4