]> git.openstreetmap.org Git - osqa.git/commitdiff
Adding ability to convert comments to answers.
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 27 Dec 2010 17:42:19 +0000 (17:42 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 27 Dec 2010 17:42:19 +0000 (17:42 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@631 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/actions/node.py
forum/models/user.py
forum/settings/minrep.py
forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/node/comments.html
forum/skins/default/templates/paginator/sort_tabs.html
forum/skins/default/templates/question_list/sort_tabs.html
forum/templatetags/node_tags.py
forum/urls.py
forum/views/commands.py

index 05d89eca09db4553c5327c8b0bbcc0f55db9389a..cd39924d0c22ccb9c922a84f83f23cf717506b29 100644 (file)
@@ -179,6 +179,22 @@ class AnswerToCommentAction(ActionProxy):
             '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
index 8a80f03c3c167e586b660a73c603d1460ef0f409..e3c97fa90d6bf4f61cd30d41bdc432a95d2652fc 100644 (file)
@@ -276,6 +276,10 @@ class User(BaseModel, DjangoUser):
     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))
index 8588095a2e70428f5f18180890db17afc2a5f922..b2ff60d172df6a9416979de875f15611d4062239 100644 (file)
@@ -67,6 +67,10 @@ REP_TO_CONVERT_TO_COMMENT = Setting('REP_TO_CONVERT_TO_COMMENT', 2000, MIN_REP_S
 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
index f97f1cdded40462d80e9ae481081ec30f33e5842..7571a4b52ade1f64b1488fc6bb410de612e43726 100644 (file)
@@ -71,7 +71,7 @@ var response_commands = {
         });\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
@@ -80,7 +80,8 @@ var response_commands = {
                 .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
@@ -264,6 +265,7 @@ function process_ajax_response(data, evt, callback) {
         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
index 702d3ad26fa955fe9371d698a82de590f151dceb..5fea00c030dca680d5ba7bc4fc1025b86ded234f 100644 (file)
                     <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
@@ -74,4 +83,4 @@
     </form>\r
     {% endif %}\r
 </div>\r
-    
\ No newline at end of file
+    \r
index bd4cb3c412a677208a16b752e0af69a0c6c2a41f..a0662a9fd4c67e800181120c144b66b8cc5975d9 100644 (file)
@@ -10,4 +10,4 @@
     </span>
     {% endcomment %}
 </div>
-{% endspaceless %}
\ No newline at end of file
+{% endspaceless %}
index b170549d50323e81b548e52493ecb8303f347cc2..eff04084c96469be3ed6a3b69df2154db3296f78 100644 (file)
@@ -5,4 +5,4 @@
     <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
index bc1fbf4df31cb390d7b3498110ac9356d65ea6b8..720f822304406b729f712d87a57ba6f26dab6947 100644 (file)
@@ -173,7 +173,8 @@ def comments(post, user):
         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
index 718e390a0a65ad4388e8ef0d655b2e0547e59714..5c5f622c477663c0f36214b6f3bff54208395d82 100644 (file)
@@ -81,6 +81,8 @@ urlpatterns += patterns('',
                         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")
index 4fba05fd7fa1e8626a1f998b6b356cf9017285ce..fcdd0561a79b2410fd4da7b42e5cd4129e9bb654 100644 (file)
@@ -264,7 +264,8 @@ def comment(request, id):
         '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}),            
                 ]
         }
         }
@@ -434,6 +435,27 @@ def convert_to_comment(request, 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