'question': self.describe_node(viewer, self.node.abs_parent),\r
}\r
\r
+class AnswerToQuestionAction(ActionProxy):\r
+ verb = _("converted to question")\r
+\r
+ def process_data(self, title):\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
+\r
+ try:\r
+ self.node.abs_parent.reset_answer_count_cache()\r
+ except AttributeError:\r
+ pass\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 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):
label = _("Minimum reputation to convert answers to comment"),\r
help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a comment.")))\r
\r
+REP_TO_CONVERT_TO_QUESTION = Setting('REP_TO_CONVERT_TO_QUESTION', 2000, MIN_REP_SET, dict(\r
+label = _("Minimum reputation to convert answers to questions"),\r
+help_text = _("The minimum reputation an user must have to be allowed to convert an answer into a question.")))\r
+\r
REP_TO_VIEW_FLAGS = Setting('REP_TO_VIEW_FLAGS', 2000, MIN_REP_SET, dict(\r
label = _("Minimum reputation to view offensive flags"),\r
help_text = _("The minimum reputation an user must have to view offensive flags.")))\r
#label = _("Minimum reputation to disable nofollow"),\r
#help_text = _("""\r
#The minimum reputation an user must have to be allowed to disable the nofollow attribute of a post link.\r
-#""")))
\ No newline at end of file
+#""")))\r
--- /dev/null
+{% load i18n %}
+<div>
+ <p>{% trans "Title of the new question:" %}</p>
+
+ <input type="text" name="title" />
+</div>
+
if post.node_type == "answer" and user.can_convert_to_comment(post):\r
menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
command=True, withprompt=True))\r
+ \r
+ if post.node_type == "answer" and user.can_convert_to_question(post):\r
+ menu.append(post_control(_('convert to question'), reverse('convert_to_question', kwargs={'id': post.id}),\r
+ command=True, withprompt=True))\r
\r
if user.is_superuser or user.is_staff:\r
plain_text = strip_tags(post.html)\r
url(r'^%s(?P<id>\d+)/' % _('node_markdown/'), app.commands.node_markdown, name='node_markdown'),
url(r'^%s(?P<id>\d+)/' % _('convert/'), app.commands.convert_to_comment,
name='convert_to_comment'),
+ url(r'^%s(?P<id>\d+)/' % _('convert_to_question/'), app.commands.convert_to_question,
+ name='convert_to_question'),
url(r'^%s(?P<id>\d+)/' % _('wikify/'), app.commands.wikify, name='wikify'),
url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('question/'),
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: