From c72f65e13db0229d8f5f74b69dc9bdba88d55d75 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 22 Dec 2010 22:14:50 +0000 Subject: [PATCH] Added functionality to convert answers to comments as mentioned in Jira OSQA-462. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@622 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/actions/node.py | 21 +++++++++++++ forum/models/user.py | 4 +++ forum/settings/minrep.py | 6 +++- .../templates/node/convert_to_question.html | 7 +++++ forum/templatetags/node_tags.py | 4 +++ forum/urls.py | 2 ++ forum/views/commands.py | 30 +++++++++++++++++++ 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 forum/skins/default/templates/node/convert_to_question.html diff --git a/forum/actions/node.py b/forum/actions/node.py index 50e4ef1..05d89ec 100644 --- a/forum/actions/node.py +++ b/forum/actions/node.py @@ -179,6 +179,27 @@ class AnswerToCommentAction(ActionProxy): 'question': self.describe_node(viewer, self.node.abs_parent), } +class AnswerToQuestionAction(ActionProxy): + verb = _("converted to question") + + def process_data(self, title): + self.node.node_type = "question" + self.node.title = title + self.node.last_edited = self + self.node.update_last_activity(self.user, save=True) + + try: + self.node.abs_parent.reset_answer_count_cache() + except AttributeError: + pass + + + def describe(self, viewer=None): + return _("%(user)s converted an answer to %(question)s into a separate question") % { + 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'question': self.describe_node(viewer, self.node.abs_parent), + } + class WikifyAction(ActionProxy): verb = _("wikified") diff --git a/forum/models/user.py b/forum/models/user.py index 124ea17..e50c1f0 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -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_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): diff --git a/forum/settings/minrep.py b/forum/settings/minrep.py index c403fe1..8588095 100644 --- a/forum/settings/minrep.py +++ b/forum/settings/minrep.py @@ -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"), help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a comment."))) +REP_TO_CONVERT_TO_QUESTION = Setting('REP_TO_CONVERT_TO_QUESTION', 2000, MIN_REP_SET, dict( +label = _("Minimum reputation to convert answers to questions"), +help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a question."))) + REP_TO_VIEW_FLAGS = Setting('REP_TO_VIEW_FLAGS', 2000, MIN_REP_SET, dict( label = _("Minimum reputation to view offensive flags"), help_text = _("The minimum reputation an user must have to view offensive flags."))) @@ -75,4 +79,4 @@ help_text = _("The minimum reputation an user must have to view offensive flags. #label = _("Minimum reputation to disable nofollow"), #help_text = _(""" #The minimum reputation an user must have to be allowed to disable the nofollow attribute of a post link. -#"""))) \ No newline at end of file +#"""))) 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 index 0000000..84ea16b --- /dev/null +++ b/forum/skins/default/templates/node/convert_to_question.html @@ -0,0 +1,7 @@ +{% load i18n %} +
+

{% trans "Title of the new question:" %}

+ + +
+ diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index 583b23c..bc1fbf4 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -136,6 +136,10 @@ def post_controls(post, user): if post.node_type == "answer" and user.can_convert_to_comment(post): menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}), command=True, withprompt=True)) + + if post.node_type == "answer" and user.can_convert_to_question(post): + menu.append(post_control(_('convert to question'), reverse('convert_to_question', kwargs={'id': post.id}), + command=True, withprompt=True)) if user.is_superuser or user.is_staff: plain_text = strip_tags(post.html) diff --git a/forum/urls.py b/forum/urls.py index 30fd5ac..718e390 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -94,6 +94,8 @@ urlpatterns += patterns('', url(r'^%s(?P\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'), url(r'^%s(?P\d+)/' % _('convert/'), app.commands.convert_to_comment, name='convert_to_comment'), + url(r'^%s(?P\d+)/' % _('convert_to_question/'), app.commands.convert_to_question, + name='convert_to_question'), url(r'^%s(?P\d+)/' % _('wikify/'), app.commands.wikify, name='wikify'), url(r'^%s(?P\d+)/(?P[\w-]*)$' % _('question/'), diff --git a/forum/views/commands.py b/forum/views/commands.py index 7b44322..4fba05f 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -434,6 +434,36 @@ def convert_to_comment(request, id): 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: -- 2.39.5