]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/actions/node.py
disabling the submit buttons for question and answers.
[osqa.git] / forum / actions / node.py
index d7f938313f2482cf98bba14bef862ef01066a69e..dbbb6589107e1a11566da5f25a6c58f3e7cae2da 100644 (file)
@@ -5,7 +5,7 @@ from forum.models import Comment, Question, Answer, NodeRevision
 \r
 class NodeEditAction(ActionProxy):\r
     def create_revision_data(self, initial=False, **data):\r
 \r
 class NodeEditAction(ActionProxy):\r
     def create_revision_data(self, initial=False, **data):\r
-        revision_data = dict(summary=data.get('summary', (initial and _('Initial revision' or ''))), body=data['text'])\r
+        revision_data = dict(summary=data.get('summary', (initial and _('Initial revision') or '')), body=data['text'])\r
 \r
         if data.get('title', None):\r
             revision_data['title'] = strip_tags(data['title'].strip())\r
 \r
         if data.get('title', None):\r
             revision_data['title'] = strip_tags(data['title'].strip())\r
@@ -16,6 +16,8 @@ class NodeEditAction(ActionProxy):
         return revision_data\r
 \r
 class AskAction(NodeEditAction):\r
         return revision_data\r
 \r
 class AskAction(NodeEditAction):\r
+    verb = _("asked")\r
+\r
     def process_data(self, **data):\r
         question = Question(author=self.user, **self.create_revision_data(True, **data))\r
         question.save()\r
     def process_data(self, **data):\r
         question = Question(author=self.user, **self.create_revision_data(True, **data))\r
         question.save()\r
@@ -28,6 +30,8 @@ class AskAction(NodeEditAction):
         }\r
 \r
 class AnswerAction(NodeEditAction):\r
         }\r
 \r
 class AnswerAction(NodeEditAction):\r
+    verb = _("answered")\r
+\r
     def process_data(self, **data):\r
         answer = Answer(author=self.user, parent=data['question'], **self.create_revision_data(True, **data))\r
         answer.save()\r
     def process_data(self, **data):\r
         answer = Answer(author=self.user, parent=data['question'], **self.create_revision_data(True, **data))\r
         answer.save()\r
@@ -38,13 +42,15 @@ class AnswerAction(NodeEditAction):
 \r
     def describe(self, viewer=None):\r
         question = self.node.parent\r
 \r
     def describe(self, viewer=None):\r
         question = self.node.parent\r
-        return _("%(user)s answered %(asker)s %(question)s") % {\r
+        return _("%(user)s answered %(asker)s on %(question)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'asker': self.hyperlink(question.author.get_profile_url(), self.friendly_username(viewer, question.author)),\r
             'question': self.hyperlink(self.node.get_absolute_url(), question.title)\r
         }\r
 \r
 class CommentAction(ActionProxy):\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'asker': self.hyperlink(question.author.get_profile_url(), self.friendly_username(viewer, question.author)),\r
             'question': self.hyperlink(self.node.get_absolute_url(), question.title)\r
         }\r
 \r
 class CommentAction(ActionProxy):\r
+    verb = _("commented")\r
+\r
     def process_data(self, text='', parent=None):\r
         comment = Comment(author=self.user, parent=parent, body=text)\r
         comment.save()\r
     def process_data(self, text='', parent=None):\r
         comment = Comment(author=self.user, parent=parent, body=text)\r
         comment.save()\r
@@ -57,22 +63,38 @@ class CommentAction(ActionProxy):
         }\r
 \r
 class ReviseAction(NodeEditAction):\r
         }\r
 \r
 class ReviseAction(NodeEditAction):\r
+    verb = _("edited")\r
+\r
     def process_data(self, **data):\r
         revision_data = self.create_revision_data(**data)\r
     def process_data(self, **data):\r
         revision_data = self.create_revision_data(**data)\r
-        revision = self.node.create_revision(self.user, action=self, **revision_data)\r
+        revision = self.node.create_revision(self.user, **revision_data)\r
         self.extra = revision.revision\r
 \r
         self.extra = revision.revision\r
 \r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
+\r
     def describe(self, viewer=None):\r
         return _("%(user)s edited %(post_desc)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'post_desc': self.describe_node(viewer, self.node)\r
         }\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s edited %(post_desc)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'post_desc': self.describe_node(viewer, self.node)\r
         }\r
 \r
+    def get_absolute_url(self):\r
+        return self.node.get_revisions_url()\r
+\r
 class RetagAction(ActionProxy):\r
 class RetagAction(ActionProxy):\r
+    verb = _("retagged")\r
+\r
     def process_data(self, tagnames=''):\r
         active = self.node.active_revision\r
         revision_data = dict(summary=_('Retag'), title=active.title, tagnames=strip_tags(tagnames.strip()), body=active.body)\r
     def process_data(self, tagnames=''):\r
         active = self.node.active_revision\r
         revision_data = dict(summary=_('Retag'), title=active.title, tagnames=strip_tags(tagnames.strip()), body=active.body)\r
-        self.node.create_revision(self.user, action=self, **revision_data)\r
+        revision = self.node.create_revision(self.user, **revision_data)\r
+        self.extra = revision.revision\r
+\r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s retagged %(post_desc)s") % {\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s retagged %(post_desc)s") % {\r
@@ -80,12 +102,21 @@ class RetagAction(ActionProxy):
             'post_desc': self.describe_node(viewer, self.node)\r
         }\r
 \r
             'post_desc': self.describe_node(viewer, self.node)\r
         }\r
 \r
+    def get_absolute_url(self):\r
+        return self.node.get_revisions_url()\r
+\r
 class RollbackAction(ActionProxy):\r
 class RollbackAction(ActionProxy):\r
+    verb = _("reverted")\r
+\r
     def process_data(self, activate=None):\r
         previous = self.node.active_revision\r
     def process_data(self, activate=None):\r
         previous = self.node.active_revision\r
-        self.node.activate_revision(self.user, activate, self)\r
+        self.node.activate_revision(self.user, activate)\r
         self.extra = "%d:%d" % (previous.revision, activate.revision)\r
 \r
         self.extra = "%d:%d" % (previous.revision, activate.revision)\r
 \r
+    def process_action(self):\r
+        self.node.last_edited = self\r
+        self.node.save()\r
+\r
     def describe(self, viewer=None):\r
         revisions = [NodeRevision.objects.get(node=self.node, revision=int(n)) for n in self.extra.split(':')]\r
 \r
     def describe(self, viewer=None):\r
         revisions = [NodeRevision.objects.get(node=self.node, revision=int(n)) for n in self.extra.split(':')]\r
 \r
@@ -96,20 +127,69 @@ class RollbackAction(ActionProxy):
             'final': revisions[1].revision, 'final_sum': revisions[1].summary,\r
         }\r
 \r
             'final': revisions[1].revision, 'final_sum': revisions[1].summary,\r
         }\r
 \r
+    def get_absolute_url(self):\r
+        return self.node.get_revisions_url()\r
+\r
 class CloseAction(ActionProxy):\r
 class CloseAction(ActionProxy):\r
+    verb = _("closed")\r
+\r
     def process_action(self):\r
     def process_action(self):\r
-        self.node.extra_action = self\r
         self.node.marked = True\r
         self.node.marked = True\r
-        self.node.save()\r
+        self.node.nstate.closed = self\r
+        self.node.last_edited = self\r
+        self.node.update_last_activity(self.user, save=True)\r
 \r
     def cancel_action(self):\r
 \r
     def cancel_action(self):\r
-        self.node.extra_action = None\r
         self.node.marked = False\r
         self.node.marked = False\r
-        self.node.save()\r
+        self.node.nstate.closed = None\r
+        self.node.update_last_activity(self.user, save=True)\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s closed %(post_desc)s: %(reason)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'post_desc': self.describe_node(viewer, self.node),\r
             'reason': self.extra\r
 \r
     def describe(self, viewer=None):\r
         return _("%(user)s closed %(post_desc)s: %(reason)s") % {\r
             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
             'post_desc': self.describe_node(viewer, self.node),\r
             'reason': self.extra\r
-        }
\ No newline at end of file
+        }\r
+\r
+class AnswerToCommentAction(ActionProxy):\r
+    verb = _("converted")\r
+\r
+    def process_data(self, new_parent=None):\r
+        self.node.parent = new_parent\r
+        self.node.node_type = "comment"\r
+\r
+        for comment in self.node.comments.all():\r
+            comment.parent = new_parent\r
+            comment.save()\r
+\r
+        self.node.last_edited = self\r
+        self.node.update_last_activity(self.user, save=True)\r
+        try:\r
+            self.node.abs_parent.reset_answer_count_cache()\r
+        except AttributeError:\r
+            pass\r
+\r
+    def describe(self, viewer=None):\r
+        return _("%(user)s converted an answer to %(question)s into a comment") % {\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
+    def process_action(self):\r
+        self.node.nstate.wiki = self\r
+        self.node.last_edited = self\r
+        self.node.update_last_activity(self.user, save=True)\r
+\r
+    def cancel_action(self):\r
+        self.node.nstate.wiki = None\r
+        self.node.update_last_activity(self.user, save=True)\r
+\r
+    def describe(self, viewer=None):\r
+        return _("%(user)s marked %(node)s as community wiki.") % {\r
+            'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),\r
+            'node': self.describe_node(viewer, self.node),\r
+        }\r
+\r