comparison gpp/comments/views.py @ 215:8c1832b9d815

Implement #84; additional checks on spammers; implement stranger status.
author Brian Neal <bgneal@gmail.com>
date Sat, 29 May 2010 04:51:28 +0000
parents d203a4a986d2
children
comparison
equal deleted inserted replaced
214:28988cce138b 215:8c1832b9d815
16 from core.functions import email_admins 16 from core.functions import email_admins
17 from core.markup import site_markup 17 from core.markup import site_markup
18 from comments.forms import CommentForm 18 from comments.forms import CommentForm
19 from comments.models import Comment 19 from comments.models import Comment
20 from comments.models import CommentFlag 20 from comments.models import CommentFlag
21 import antispam
22 import antispam.utils
23
21 24
22 @login_required 25 @login_required
23 @require_POST 26 @require_POST
24 def post_comment(request): 27 def post_comment(request):
25 """ 28 """
26 This function handles the posting of comments. If successful, returns 29 This function handles the posting of comments. If successful, returns
27 the comment text as the response. This function is mean't to be the target 30 the comment text as the response. This function is meant to be the target
28 of an AJAX post. 31 of an AJAX post.
29 """ 32 """
30 # Look up the object we're trying to comment about 33 # Look up the object we're trying to comment about
31 ctype = request.POST.get('content_type', None) 34 ctype = request.POST.get('content_type', None)
32 object_pk = request.POST.get('object_pk', None) 35 object_pk = request.POST.get('object_pk', None)
64 67
65 form = CommentForm(target, request.POST) 68 form = CommentForm(target, request.POST)
66 if not form.is_valid(): 69 if not form.is_valid():
67 return HttpResponseBadRequest('Invalid comment; missing parameters?') 70 return HttpResponseBadRequest('Invalid comment; missing parameters?')
68 71
69 # else, create and save the comment 72 comment = form.get_comment_object(request.user, request.META.get("REMOTE_ADDR", None))
70 73
71 comment = form.get_comment_object(request.user, request.META.get("REMOTE_ADDR", None)) 74 # Check for spam
75
76 if antispam.utils.spam_check(request, comment.comment):
77 return HttpResponseForbidden(antispam.BUSTED_MESSAGE)
78
72 comment.save() 79 comment.save()
73 80
74 # return the rendered comment 81 # return the rendered comment
75 return render_to_response('comments/comment.html', { 82 return render_to_response('comments/comment.html', {
76 'comment': comment, 83 'comment': comment,