]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/actions/node.py
Use the islatest field on the apps feed to get the latest version of an app.
[osqa.git] / forum / actions / node.py
index cd39924d0c22ccb9c922a84f83f23cf717506b29..53699e967d1e91f83673274d9e28502667bdb5d7 100644 (file)
@@ -2,6 +2,7 @@ from django.utils.html import strip_tags
 from django.utils.translation import ugettext as _\r
 from forum.models.action import ActionProxy\r
 from forum.models import Comment, Question, Answer, NodeRevision\r
+import logging\r
 \r
 class NodeEditAction(ActionProxy):\r
     def create_revision_data(self, initial=False, **data):\r
@@ -188,6 +189,8 @@ class CommentToAnswerAction(ActionProxy):
         self.node.last_edited = self\r
         self.node.update_last_activity(self.user, save=True)\r
 \r
+        # Now updated the cached data\r
+        question.reset_answer_count_cache()\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s converted comment on %(question)s into an answer") % {\r
@@ -195,19 +198,29 @@ class CommentToAnswerAction(ActionProxy):
             'question': self.describe_node(viewer, self.node.abs_parent),\r
         }\r
 \r
-class AnswerToQuestionAction(ActionProxy):\r
+class AnswerToQuestionAction(NodeEditAction):\r
     verb = _("converted to question")\r
 \r
-    def process_data(self, title):\r
+    def process_data(self,  **data):\r
+        revision_data = self.create_revision_data(**data)\r
+        revision = self.node.create_revision(self.user, **revision_data)\r
+\r
+        original_question = self.node.question\r
+\r
+        self.extra = {\r
+            'covert_revision': revision.revision,\r
+            'original_question': original_question\r
+        }\r
+\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
+        self.node.parent = None\r
+        self.node.abs_parent = None\r
 \r
-        try:\r
-            self.node.abs_parent.reset_answer_count_cache()\r
-        except AttributeError:\r
-            pass\r
+        original_question.reset_answer_count_cache()\r
+\r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
 \r
 \r
     def describe(self, viewer=None):\r