Permalink
Browse files

Fix reporting Ajax form errors, hide comment fields on errors

Keeps the JSON response clean for errors; no need to include
`is_moderated`, `comment_id` or `html` in there.
  • Loading branch information...
vdboor committed Nov 11, 2012
1 parent 23af7ad commit 5499ae6bca4451f8106ce83b586b34a5fb82638b
Showing with 13 additions and 10 deletions.
  1. +13 −10 fluent_comments/views.py
View
@@ -117,24 +117,27 @@ def _ajax_result(request, form, action, comment=None):
json_errors[field_name] = _render_errors(field)
success = False
- comment_html = None
- if comment:
+ json = {
+ 'success': success,
+ 'action': action,
+ 'errors': json_errors,
+ }
+
+ if comment is not None:
context = {
'comment': comment,
'action': action,
'preview': (action == 'preview'),
}
comment_html = render_to_string('comments/comment.html', context, context_instance=RequestContext(request))
- json_response = simplejson.dumps({
- 'success': success,
- 'action': action,
- 'errors': json_errors,
- 'html': comment_html,
- 'comment_id': comment.id if comment else None,
- 'is_moderated': not comment.is_public, # is_public flags changes in comment_will_be_posted
- })
+ json.update({
+ 'html': comment_html,
+ 'comment_id': comment.id,
+ 'is_moderated': not comment.is_public, # is_public flags changes in comment_will_be_posted
+ })
+ json_response = simplejson.dumps(json)
return HttpResponse(json_response, mimetype="application/json")

0 comments on commit 5499ae6

Please sign in to comment.