comparison comments/views.py @ 963:4619290d171d

Whitelist hot-linked image sources.
author Brian Neal <bgneal@gmail.com>
date Tue, 01 Sep 2015 20:33:40 -0500
parents ad69236e8501
children d260aef91ad7
comparison
equal deleted inserted replaced
962:10e7570a3aab 963:4619290d171d
65 65
66 # Check form validity 66 # Check form validity
67 67
68 form = CommentForm(target, request.POST) 68 form = CommentForm(target, request.POST)
69 if not form.is_valid(): 69 if not form.is_valid():
70 return HttpResponseBadRequest('Invalid comment; missing parameters?') 70 # The client side javascript is pretty simplistic right now and we don't
71 # want to change it yet. It is expecting a single error string. Just grab
72 # the first error message and use that.
73 errors = form.errors.as_data()
74 msg = errors.values()[0][0].message if errors else 'Unknown error'
75 return HttpResponseBadRequest(msg)
71 76
72 comment = form.get_comment_object(request.user, request.META.get("REMOTE_ADDR", None)) 77 comment = form.get_comment_object(request.user, request.META.get("REMOTE_ADDR", None))
73 78
74 # Check for spam 79 # Check for spam
75 80
76 if antispam.utils.spam_check(request, comment.comment): 81 if antispam.utils.spam_check(request, comment.comment):
77 return HttpResponseForbidden(antispam.BUSTED_MESSAGE) 82 return HttpResponseForbidden(antispam.BUSTED_MESSAGE)
78 83
79 comment.save() 84 comment.save(html=form.comment_html)
80 85
81 # return the rendered comment 86 # return the rendered comment
82 return render_to_response('comments/comment.html', { 87 return render_to_response('comments/comment.html', {
83 'comment': comment, 88 'comment': comment,
84 }, 89 },