# HG changeset patch # User Brian Neal # Date 1252886768 0 # Node ID 10d6182b9f6e06cb27a617d780d887be4f084ae8 # Parent d0d779dd0832e63245b61666281d45ad8dcf3e95 Forums: added error handling to the flagging of posts. Did the same with the comments function too. diff -r d0d779dd0832 -r 10d6182b9f6e gpp/forums/views.py --- a/gpp/forums/views.py Sun Sep 13 21:45:35 2009 +0000 +++ b/gpp/forums/views.py Mon Sep 14 00:06:08 2009 +0000 @@ -193,7 +193,7 @@ be the target of an AJAX post. """ if not request.user.is_authenticated(): - return HttpResponse('Please login or register to flag a post.') + return HttpResponseForbidden('Please login or register to flag a post.') id = request.POST.get('id') if id is None: diff -r d0d779dd0832 -r 10d6182b9f6e media/js/comments.js --- a/media/js/comments.js Sun Sep 13 21:45:35 2009 +0000 +++ b/media/js/comments.js Mon Sep 14 00:06:08 2009 +0000 @@ -29,9 +29,18 @@ 'or is not appropriate. ' + 'A moderator will be notified and will review the comment. ' + 'Are you sure you want to flag this comment?')) { - $.post('/comments/flag/', { id : id }, function(response) { - alert(response); - }, 'text'); + $.ajax({ + url: '/comments/flag/', + type: 'POST', + data: {id: id}, + dataType: 'text', + success: function (response, textStatus) { + alert(response); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); + } + }); } } return false; diff -r d0d779dd0832 -r 10d6182b9f6e media/js/forums.js --- a/media/js/forums.js Sun Sep 13 21:45:35 2009 +0000 +++ b/media/js/forums.js Mon Sep 14 00:06:08 2009 +0000 @@ -39,9 +39,18 @@ 'or is not appropriate. ' + 'A moderator will be notified and will review the post. ' + 'Are you sure you want to flag this post?')) { - $.post('/forums/flag-post/', { id : id }, function(response) { - alert(response); - }, 'text'); + $.ajax({ + url: '/forums/flag-post/', + type: 'POST', + data: {id: id}, + dataType: 'text', + success: function (response, textStatus) { + alert(response); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); + } + }); } } return false;