comparison gpp/shoutbox/views.py @ 13:777451a98f9d

Shoutbox work: shouts now have absolute URLs. Shouts can now be flagged as abuse. Minor tweak to breadcrumbs css. Added flag date to comments admin.
author Brian Neal <bgneal@gmail.com>
date Thu, 16 Apr 2009 02:00:17 +0000
parents f408971657b9
children 62eb9cbbcffc
comparison
equal deleted inserted replaced
12:f408971657b9 13:777451a98f9d
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 from django.views.decorators.http import require_POST
14 14
15 from core.paginator import DiggPaginator 15 from core.paginator import DiggPaginator
16 from core.functions import email_admins
16 from shoutbox.forms import ShoutBoxForm 17 from shoutbox.forms import ShoutBoxForm
17 from shoutbox.models import Shout 18 from shoutbox.models import Shout
19 from shoutbox.models import ShoutFlag
18 20
19 SHOUTS_PER_PAGE = 10 21 SHOUTS_PER_PAGE = 10
20 22
21 @login_required 23 @login_required
22 @require_POST 24 @require_POST
31 'shout': shout, 33 'shout': shout,
32 }, 34 },
33 context_instance = RequestContext(request)) 35 context_instance = RequestContext(request))
34 36
35 37
36 def view(request, page=1): 38 def view_shout(request, id):
39 """This view is for viewing an individual shout."""
40 try:
41 shout = Shout.objects.get(pk=id)
42 except Shout.DoesNotExist:
43 return render_to_response('shoutbox/missing_shout.html', {},
44 context_instance = RequestContext(request))
45
46 return render_to_response('shoutbox/view_shout.html', {
47 'shout': shout,
48 },
49 context_instance = RequestContext(request))
50
51
52 def view_history(request, page=1):
37 """This view allows one to view the shoutbox history.""" 53 """This view allows one to view the shoutbox history."""
38 paginator = DiggPaginator(Shout.objects.all(), SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2) 54 paginator = DiggPaginator(Shout.objects.all(), SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2)
39 try: 55 try:
40 the_page = paginator.page(int(page)) 56 the_page = paginator.page(int(page))
41 except InvalidPage: 57 except InvalidPage:
105 shout.delete() 121 shout.delete()
106 return HttpResponse(id) 122 return HttpResponse(id)
107 123
108 return HttpResponseForbidden() 124 return HttpResponseForbidden()
109 125
126
127 @require_POST
128 def flag(request):
129 """
130 This function handles the flagging of shouts by users. This function should
131 be the target of an AJAX post.
132 """
133 if not request.user.is_authenticated():
134 return HttpResponse('Please login or register to flag a shout.')
135
136 id = request.POST.get('id', None)
137 if id is None:
138 return HttpResponseBadRequest('No id')
139
140 try:
141 shout = Shout.objects.get(pk=id)
142 except Shout.DoesNotExist:
143 return HttpResponseBadRequest('No shout with id %s' % id)
144
145 flag = ShoutFlag(user=request.user, shout=shout)
146 flag.save()
147 email_admins('A Shout Has Been Flagged', """Hello,
148
149 A user has flagged a shout for review.
150 """)
151 return HttpResponse('The shout was flagged. A moderator will review the shout shortly. ' \
152 'Thanks for helping to improve the quality of this site.')
153
110 # vim: ts=4 sw=4 154 # vim: ts=4 sw=4