'question': self.describe_node(viewer, self.node.abs_parent),\r
}\r
\r
+class CommentToAnswerAction(ActionProxy):\r
+ verb = _("converted")\r
+\r
+ def process_data(self, question):\r
+ self.node.parent = question\r
+ self.node.node_type = "answer"\r
+ self.node.last_edited = self\r
+ self.node.update_last_activity(self.user, save=True)\r
+\r
+\r
+ def describe(self, viewer=None):\r
+ return _("%(user)s converted comment on %(question)s into an answer") % {\r
+ 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
+ 'question': self.describe_node(viewer, self.node.abs_parent),\r
+ }\r
+\r
class AnswerToQuestionAction(ActionProxy):\r
verb = _("converted to question")\r
\r
def can_delete_comment(self, comment):
return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS)
+ @true_if_is_super_or_staff
+ def can_convert_comment_to_answer(self, comment):
+ return self == comment.author or self.reputation >= int(settings.REP_TO_COMMENTS_TO_ANSWERS)
+
def can_convert_to_comment(self, answer):
return (not answer.marked) and (self.is_superuser or self.is_staff or answer.author == self or self.reputation >= int
(settings.REP_TO_CONVERT_TO_COMMENT))
label = _("Minimum reputation to convert answers to comment"),\r
help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a comment.")))\r
\r
+REP_TO_CONVERT_COMMENTS_TO_ANSWERS = Setting('REP_TO_CONVERT_COMMENTS_TO_ANSWERS', 2000, MIN_REP_SET, dict(\r
+label = _("Minimum reputation to convert comments to answers"),\r
+help_text = _("The minimum reputation an user must have to be allowed to convert comments into an answer.")))\r
+\r
REP_TO_CONVERT_TO_QUESTION = Setting('REP_TO_CONVERT_TO_QUESTION', 2000, MIN_REP_SET, dict(\r
label = _("Minimum reputation to convert answers to questions"),\r
help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a question.")))\r
});\r
},\r
\r
- insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url) {\r
+ insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) {\r
var $container = $('#comments-container-' + post_id);\r
var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();\r
\r
.replace(new RegExp('%USERNAME%', 'g'), username)\r
.replace(new RegExp('%PROFILE_URL%', 'g'), profile_url)\r
.replace(new RegExp('%DELETE_URL%', 'g'), delete_url)\r
- .replace(new RegExp('%EDIT_URL%', 'g'), edit_url);\r
+ .replace(new RegExp('%EDIT_URL%', 'g'), edit_url)\r
+ .replace(new RegExp('%CONVERT_URL%', 'g'), convert_url);\r
\r
$container.append(skeleton);\r
\r
for (var command in data.commands) {\r
response_commands[command].apply(null, data.commands[command])\r
\r
+\r
}\r
\r
if (data['message'] != undefined) {\r
<a id="comment-{{ comment.id }}-delete" href="{% url delete_comment id=comment.id %}" title="{% trans "Delete comment" %}"\r
class="ajax-command comment-delete" rel="nofollow"> </a>\r
{% endif %}\r
+ {% if comment.can_convert %}\r
+ <a rel="nofollow" id="comment-{{ comment.id }}-convert" href="{% url convert_comment id=comment.id %}" title="{% trans "Convert comment to answer" %}"\r
+ class="ajax-command comment-convert confirm" rel="nofollow">{% trans "Convert comment to answer" %}</a>\r
+ {% endif %}\r
+ \r
+\r
<span class="comment-age">({% diff_date comment.added_at %})</span>\r
<a class="comment-user userinfo" href="{{comment.user.get_profile_url}}">{{comment.user.decorated_name}}</a>\r
{% if show_gravatar %}{% gravatar comment.user 18 %}{% endif %}\r
<div class="comment{% if not comment.top_scorer %} not_top_scorer{% endif %}" id="comment-%ID%">\r
<div id="post-%ID%-score" class="comment-score"></div>\r
<div class="comment-text">%COMMENT%</div>\r
- <div class="comment-info" id="comment-{{comment.id}}-info">\r
+ <div class="comment-info" id="comment-%ID%-info">\r
<a id="comment-%ID%-edit" href="%EDIT_URL%"\r
class="comment-edit" rel="nofollow"> </a>\r
<a id="comment-%ID%-delete" href="%DELETE_URL%"\r
class="ajax-command comment-delete" rel="nofollow"> </a>\r
+ <a rel="nofollow" id="comment-%ID%-convert" href="%CONVERT_URL%" title="{% trans "Convert comment to answer" %}"\r
+ class="ajax-command comment-convert confirm" rel="nofollow">{% trans "Convert comment to answer" %}</a>\r
+\r
<span class="comment-age">({% trans "just now" %})</span>\r
<a class="comment-user" href="%PROFILE_URL%">%USERNAME%</a>\r
{% if user.is_authenticated %}\r
</form>\r
{% endif %}\r
</div>\r
-
\ No newline at end of file
+ \r
</span>
{% endcomment %}
</div>
-{% endspaceless %}
\ No newline at end of file
+{% endspaceless %}
<a id="latest" href="{{ base_url }}latest"{% ifequal current "latest" %} class="on"{% endifequal %} title="{% trans "most recently asked questions" %}">{% trans "newest" %}</a>\r
<a id="hottest" href="{{ base_url }}hottest"{% ifequal current "hottest" %} class="on"{% endifequal %} title="{% trans "hottest questions" %}">{% trans "hottest" %}</a>\r
<a id="mostvoted" href="{{ base_url }}mostvoted"{% ifequal current "mostvoted" %} class="on"{% endifequal %} title="{% trans "most voted questions" %}">{% trans "most voted" %}</a>\r
-</div>
\ No newline at end of file
+</div>\r
context = {\r
'can_delete': user.can_delete_comment(c),\r
'can_like': user.can_like_comment(c),\r
- 'can_edit': user.can_edit_comment(c)\r
+ 'can_edit': user.can_edit_comment(c),\r
+ 'can_convert': user.can_convert_comment_to_answer(c)\r
}\r
\r
if c in top_scorers or c.is_reply_to(user):\r
url(r'^%s(?P<id>\d+)/' % _('comment/'), app.commands.comment, name='comment'),
url(r'^%s(?P<id>\d+)/$' % _('delete_comment/'), app.commands.delete_comment,
name="delete_comment"),
+ url(r'^%s(?P<id>\d+)/$' % _('convert_comment/'), app.commands.convert_comment_to_answer,
+ name="convert_comment"),
url(r'^%s(?P<id>\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer")
,
url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite")
'insert_comment': [
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('node_markdown', kwargs={'id': comment.id}),
+ reverse('convert_comment', kwargs={'id': comment.id}),
]
}
}
return RefreshPageCommand()
+@decorate.withfn(command)
+def convert_comment_to_answer(request, id):
+ user = request.user
+ comment = get_object_or_404(Comment, id=id)
+ parent = comment.parent
+
+ if not parent.question:
+ question = parent
+ else:
+ question = parent.question
+
+ if not user.is_authenticated():
+ raise AnonymousNotAllowedException(_("convert comments to answers"))
+
+ if not user.can_convert_comment_to_answer(comment):
+ raise NotEnoughRepPointsException(_("convert comments to answers"))
+
+ CommentToAnswerAction(user=user, node=comment, ip=request.META['REMOTE_ADDR']).save(data=dict(question=question))
+
+ return RefreshPageCommand()
+
@decorate.withfn(command)
def convert_to_question(request, id):
user = request.user