comparison 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
comparison
equal deleted inserted replaced
11:cc8eb028def1 12:f408971657b9
8 from django.http import HttpResponse 8 from django.http import HttpResponse
9 from django.http import HttpResponseBadRequest 9 from django.http import HttpResponseBadRequest
10 from django.http import HttpResponseForbidden 10 from django.http import HttpResponseForbidden
11 from django.http import HttpResponseRedirect 11 from django.http import HttpResponseRedirect
12 from django.contrib.auth.decorators import login_required 12 from django.contrib.auth.decorators import login_required
13 from django.views.decorators.http import require_POST
13 14
14 from core.paginator import DiggPaginator 15 from core.paginator import DiggPaginator
15 from shoutbox.forms import ShoutBoxForm 16 from shoutbox.forms import ShoutBoxForm
16 from shoutbox.models import Shout 17 from shoutbox.models import Shout
17 18
18 SHOUTS_PER_PAGE = 10 19 SHOUTS_PER_PAGE = 10
19 20
20 @login_required 21 @login_required
22 @require_POST
21 def shout(request): 23 def shout(request):
22 if request.method == 'POST': 24 msg = request.POST.get('msg', '').strip()
23 msg = request.POST.get('msg', '').strip() 25 if msg == '':
24 if msg != '': 26 return HttpResponse('')
25 shout = Shout(user=request.user, shout=msg) 27
26 shout.save() 28 shout = Shout(user=request.user, shout=msg)
27 29 shout.save()
28 return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) 30 return render_to_response('shoutbox/shout.html', {
31 'shout': shout,
32 },
33 context_instance = RequestContext(request))
29 34
30 35
31 def view(request, page=1): 36 def view(request, page=1):
32 """This view allows one to view the shoutbox history.""" 37 """This view allows one to view the shoutbox history."""
33 paginator = DiggPaginator(Shout.objects.all(), SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2) 38 paginator = DiggPaginator(Shout.objects.all(), SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2)
99 return HttpResponseForbidden() 104 return HttpResponseForbidden()
100 shout.delete() 105 shout.delete()
101 return HttpResponse(id) 106 return HttpResponse(id)
102 107
103 return HttpResponseForbidden() 108 return HttpResponseForbidden()
109
110 # vim: ts=4 sw=4