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
verb = _("asked")\r
\r
def process_data(self, **data):\r
- question = Question(author=self.user, **self.create_revision_data(True, **data))\r
+ processed_data = self.create_revision_data(True, **data)\r
+ if 'added_at' in data:\r
+ processed_data['added_at'] = data['added_at']\r
+\r
+ question = Question(author=self.user, **processed_data)\r
question.save()\r
self.node = question\r
\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
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
+ 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
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 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
+ 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
verb = _("closed")\r
\r
def process_action(self):\r
- self.node.extra_action = self\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
- self.node.extra_action = None\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
- }
\ 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 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
+ # 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
+ '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(NodeEditAction):\r
+ verb = _("converted to question")\r
+\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.parent = None\r
+ self.node.abs_parent = None\r
+\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
+ 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
+ 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