From bfcf39c1ff103ab78ca8d1ee7d22c044d1b5e7cb Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 12 Apr 2011 22:05:37 +0000 Subject: [PATCH] The convert to answer action now works only if the comment parent is a question or an answer. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@975 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/models/user.py | 7 +++++++ forum/skins/default/media/js/osqa.main.js | 7 ++++++- forum/skins/default/templates/node/comments.html | 2 +- forum/views/commands.py | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/forum/models/user.py b/forum/models/user.py index 523397e..afb33d3 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -292,6 +292,13 @@ class User(BaseModel, DjangoUser): return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS) def can_convert_comment_to_answer(self, comment): + # We need to know what is the comment parent node type. + comment_parent_type = comment.parent.node_type + + # If the parent is not a question or an answer this comment cannot be converted to an answer. + if comment_parent_type != "question" and comment_parent_type != "answer": + return False + return (comment.parent.node_type in ('question', 'answer')) and (self.is_superuser or self.is_staff or ( self == comment.author) or (self.reputation >= int(settings.REP_TO_CONVERT_COMMENTS_TO_ANSWERS))) diff --git a/forum/skins/default/media/js/osqa.main.js b/forum/skins/default/media/js/osqa.main.js index 2de5ecf..274ba38 100644 --- a/forum/skins/default/media/js/osqa.main.js +++ b/forum/skins/default/media/js/osqa.main.js @@ -75,7 +75,7 @@ var response_commands = { alert('ok'); }, - insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) { + insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) { var $container = $('#comments-container-' + post_id); var skeleton = $('#new-comment-skeleton-' + post_id).html().toString(); @@ -89,6 +89,11 @@ var response_commands = { $container.append(skeleton); + // Show the convert comment to answer tool only if the current comment can be converted + if (can_convert == true) { + $('#comment-' + comment_id + '-convert').show(); + } + $('#comment-' + comment_id).slideDown('slow'); }, diff --git a/forum/skins/default/templates/node/comments.html b/forum/skins/default/templates/node/comments.html index 1da9a2c..9105f56 100644 --- a/forum/skins/default/templates/node/comments.html +++ b/forum/skins/default/templates/node/comments.html @@ -69,7 +69,7 @@ class="comment-edit" rel="nofollow"> - ({% trans "just now" %}) diff --git a/forum/views/commands.py b/forum/views/commands.py index 175b6d1..0b54126 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -264,7 +264,8 @@ def comment(request, id): id, comment.id, comment.comment, user.decorated_name, user.get_profile_url(), reverse('delete_comment', kwargs={'id': comment.id}), reverse('node_markdown', kwargs={'id': comment.id}), - reverse('convert_comment', kwargs={'id': comment.id}), + reverse('convert_comment', kwargs={'id': comment.id}), + user.can_convert_comment_to_answer(comment), ] } } -- 2.39.5