]> git.openstreetmap.org Git - osqa.git/commitdiff
Added functionality to convert answers to comments as mentioned in Jira OSQA-462.
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 22 Dec 2010 22:14:50 +0000 (22:14 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 22 Dec 2010 22:14:50 +0000 (22:14 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@622 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/actions/node.py
forum/models/user.py
forum/settings/minrep.py
forum/skins/default/templates/node/convert_to_question.html [new file with mode: 0644]
forum/templatetags/node_tags.py
forum/urls.py
forum/views/commands.py

index 50e4ef13060ff5eb9064537d2a1c679c6f952dae..05d89eca09db4553c5327c8b0bbcc0f55db9389a 100644 (file)
@@ -179,6 +179,27 @@ class AnswerToCommentAction(ActionProxy):
             'question': self.describe_node(viewer, self.node.abs_parent),\r
         }\r
 \r
             'question': self.describe_node(viewer, self.node.abs_parent),\r
         }\r
 \r
+class AnswerToQuestionAction(ActionProxy):\r
+    verb = _("converted to question")\r
+\r
+    def process_data(self, title):\r
+        self.node.node_type = "question"\r
+        self.node.title = title\r
+        self.node.last_edited = self\r
+        self.node.update_last_activity(self.user, save=True)\r
+\r
+        try:\r
+            self.node.abs_parent.reset_answer_count_cache()\r
+        except AttributeError:\r
+            pass\r
+\r
+\r
+    def describe(self, viewer=None):\r
+        return _("%(user)s converted an answer to %(question)s into a separate question") % {\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 WikifyAction(ActionProxy):\r
     verb = _("wikified")\r
 \r
 class WikifyAction(ActionProxy):\r
     verb = _("wikified")\r
 \r
index 124ea17ca3465d235a91d54a2050ac713a427950..e50c1f0843e8c50ddd2da692f49f9181e328740e 100644 (file)
@@ -279,6 +279,10 @@ class User(BaseModel, DjangoUser):
     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))
     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))
+    
+    def can_convert_to_question(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_QUESTION))
 
     @true_if_is_super_or_staff
     def can_accept_answer(self, answer):
 
     @true_if_is_super_or_staff
     def can_accept_answer(self, answer):
index c403fe10100253ba5337c022d8d65fac91be898c..8588095a2e70428f5f18180890db17afc2a5f922 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
 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_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
 REP_TO_VIEW_FLAGS = Setting('REP_TO_VIEW_FLAGS', 2000, MIN_REP_SET, dict(\r
 label = _("Minimum reputation to view offensive flags"),\r
 help_text = _("The minimum reputation an user must have to view offensive flags.")))\r
 REP_TO_VIEW_FLAGS = Setting('REP_TO_VIEW_FLAGS', 2000, MIN_REP_SET, dict(\r
 label = _("Minimum reputation to view offensive flags"),\r
 help_text = _("The minimum reputation an user must have to view offensive flags.")))\r
@@ -75,4 +79,4 @@ help_text = _("The minimum reputation an user must have to view offensive flags.
 #label = _("Minimum reputation to disable nofollow"),\r
 #help_text = _("""\r
 #The minimum reputation an user must have to be allowed to disable the nofollow attribute of a post link.\r
 #label = _("Minimum reputation to disable nofollow"),\r
 #help_text = _("""\r
 #The minimum reputation an user must have to be allowed to disable the nofollow attribute of a post link.\r
-#""")))
\ No newline at end of file
+#""")))\r
diff --git a/forum/skins/default/templates/node/convert_to_question.html b/forum/skins/default/templates/node/convert_to_question.html
new file mode 100644 (file)
index 0000000..84ea16b
--- /dev/null
@@ -0,0 +1,7 @@
+{% load i18n %}
+<div>
+    <p>{% trans "Title of the new question:" %}</p>
+
+    <input type="text" name="title" />
+</div>
+
index 583b23cbb25d40c313be115b177ac54c8884226c..bc1fbf4df31cb390d7b3498110ac9356d65ea6b8 100644 (file)
@@ -136,6 +136,10 @@ def post_controls(post, user):
         if post.node_type == "answer" and user.can_convert_to_comment(post):\r
             menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
                         command=True, withprompt=True))\r
         if post.node_type == "answer" and user.can_convert_to_comment(post):\r
             menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
                         command=True, withprompt=True))\r
+        \r
+        if post.node_type == "answer" and user.can_convert_to_question(post):\r
+            menu.append(post_control(_('convert to question'), reverse('convert_to_question', kwargs={'id': post.id}),\r
+                        command=True, withprompt=True))\r
 \r
         if user.is_superuser or user.is_staff:\r
             plain_text = strip_tags(post.html)\r
 \r
         if user.is_superuser or user.is_staff:\r
             plain_text = strip_tags(post.html)\r
index 30fd5aca2f7dd1c74ff9e81b99d86156c2c9856a..718e390a0a65ad4388e8ef0d655b2e0547e59714 100644 (file)
@@ -94,6 +94,8 @@ urlpatterns += patterns('',
                         url(r'^%s(?P<id>\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'),
                         url(r'^%s(?P<id>\d+)/' % _('convert/'), app.commands.convert_to_comment,
                             name='convert_to_comment'),
                         url(r'^%s(?P<id>\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'),
                         url(r'^%s(?P<id>\d+)/' % _('convert/'), app.commands.convert_to_comment,
                             name='convert_to_comment'),
+                        url(r'^%s(?P<id>\d+)/' % _('convert_to_question/'), app.commands.convert_to_question,
+                            name='convert_to_question'),
                         url(r'^%s(?P<id>\d+)/' % _('wikify/'), app.commands.wikify, name='wikify'),
 
                         url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('question/'),
                         url(r'^%s(?P<id>\d+)/' % _('wikify/'), app.commands.wikify, name='wikify'),
 
                         url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('question/'),
index 7b44322edfa29ca979231e024476cb118778fd03..4fba05fd7fa1e8626a1f998b6b356cf9017285ce 100644 (file)
@@ -434,6 +434,36 @@ def convert_to_comment(request, id):
 
     return RefreshPageCommand()
 
 
     return RefreshPageCommand()
 
+@decorate.withfn(command)
+def convert_to_question(request, id):
+    user = request.user
+    answer = get_object_or_404(Answer, id=id)
+    question = answer.question
+
+    if not request.POST:
+        description = lambda a: _("Answer by %(uname)s: %(snippet)s...") % {'uname': a.author.username,
+                                                                            'snippet': a.summary[:10]}
+        nodes = [(question.id, _("Question"))]
+        [nodes.append((a.id, description(a))) for a in
+         question.answers.filter_state(deleted=False).exclude(id=answer.id)]
+
+        return render_to_response('node/convert_to_question.html', {'answer': answer})
+
+    if not user.is_authenticated():
+        raise AnonymousNotAllowedException(_("convert answers to questions"))
+
+    if not user.can_convert_to_question(answer):
+        raise NotEnoughRepPointsException(_("convert answers to questions"))
+
+    try:
+        title = request.POST.get('title', None)
+    except:
+        raise CommandException(_("You haven't specified the title of the new question"))
+
+    AnswerToQuestionAction(user=user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=dict(title=title))
+
+    return RefreshPageCommand()
+
 @decorate.withfn(command)
 def subscribe(request, id, user=None):
     if user:
 @decorate.withfn(command)
 def subscribe(request, id, user=None):
     if user: