X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/bb63044c86f47d0f98e60ad75e6d1230c6fc2bcf..a967cc431af1efebc9af8dc5fbfa64fd71a00529:/forum/actions/node.py diff --git a/forum/actions/node.py b/forum/actions/node.py index cd39924..53699e9 100644 --- a/forum/actions/node.py +++ b/forum/actions/node.py @@ -2,6 +2,7 @@ from django.utils.html import strip_tags from django.utils.translation import ugettext as _ from forum.models.action import ActionProxy from forum.models import Comment, Question, Answer, NodeRevision +import logging class NodeEditAction(ActionProxy): def create_revision_data(self, initial=False, **data): @@ -188,6 +189,8 @@ class CommentToAnswerAction(ActionProxy): self.node.last_edited = self self.node.update_last_activity(self.user, save=True) + # Now updated the cached data + question.reset_answer_count_cache() def describe(self, viewer=None): return _("%(user)s converted comment on %(question)s into an answer") % { @@ -195,19 +198,29 @@ class CommentToAnswerAction(ActionProxy): 'question': self.describe_node(viewer, self.node.abs_parent), } -class AnswerToQuestionAction(ActionProxy): +class AnswerToQuestionAction(NodeEditAction): verb = _("converted to question") - def process_data(self, title): + def process_data(self, **data): + revision_data = self.create_revision_data(**data) + revision = self.node.create_revision(self.user, **revision_data) + + original_question = self.node.question + + self.extra = { + 'covert_revision': revision.revision, + 'original_question': original_question + } + self.node.node_type = "question" - self.node.title = title - self.node.last_edited = self - self.node.update_last_activity(self.user, save=True) + self.node.parent = None + self.node.abs_parent = None - try: - self.node.abs_parent.reset_answer_count_cache() - except AttributeError: - pass + original_question.reset_answer_count_cache() + + def process_action(self): + self.node.last_edited = self + self.node.save() def describe(self, viewer=None):