diff 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
line wrap: on
line diff
--- a/comments/views.py	Tue Aug 04 16:58:17 2015 -0500
+++ b/comments/views.py	Tue Sep 01 20:33:40 2015 -0500
@@ -67,7 +67,12 @@
 
     form = CommentForm(target, request.POST)
     if not form.is_valid():
-        return HttpResponseBadRequest('Invalid comment; missing parameters?')
+        # The client side javascript is pretty simplistic right now and we don't
+        # want to change it yet. It is expecting a single error string. Just grab
+        # the first error message and use that.
+        errors = form.errors.as_data()
+        msg = errors.values()[0][0].message if errors else 'Unknown error'
+        return HttpResponseBadRequest(msg)
 
     comment = form.get_comment_object(request.user, request.META.get("REMOTE_ADDR", None))
 
@@ -76,7 +81,7 @@
     if antispam.utils.spam_check(request, comment.comment):
         return HttpResponseForbidden(antispam.BUSTED_MESSAGE)
 
-    comment.save()
+    comment.save(html=form.comment_html)
 
     # return the rendered comment
     return render_to_response('comments/comment.html', {