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)))
alert('ok');\r
},\r
\r
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) {\r
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) {\r
var $container = $('#comments-container-' + post_id);\r
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();\r
\r
\r
$container.append(skeleton);\r
\r
+ // Show the convert comment to answer tool only if the current comment can be converted\r
+ if (can_convert == true) {\r
+ $('#comment-' + comment_id + '-convert').show();\r
+ }\r
+\r
$('#comment-' + comment_id).slideDown('slow');\r
},\r
\r
class="comment-edit" rel="nofollow"> </a>\r
<a id="comment-%ID%-delete" href="%DELETE_URL%" title="{% trans "Delete comment" %}"\r
class="ajax-command comment-delete confirm" rel="nofollow"> </a>\r
- <a rel="nofollow" id="comment-%ID%-convert" href="%CONVERT_URL%" title="{% trans "Convert comment to answer" %}"\r
+ <a rel="nofollow" id="comment-%ID%-convert" style="display:none;" href="%CONVERT_URL%" title="{% trans "Convert comment to answer" %}"\r
class="ajax-command comment-convert confirm" rel="nofollow"> </a>\r
\r
<span class="comment-age">({% trans "just now" %})</span>\r
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),
]
}
}