[822] | 1 | ## Script (Python) "discussion_publish_comment" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=obj=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | from Products.CMFPlone.utils import transaction_note |
---|
| 11 | from Products.CMFCore.utils import getToolByName |
---|
| 12 | from quintagroup.plonecomments.utils import publishDiscussion, manage_mails |
---|
| 13 | from Products.CMFPlone import MessageFactory |
---|
| 14 | _ = MessageFactory('quintagroup.plonecomments') |
---|
| 15 | |
---|
| 16 | if obj is None: |
---|
| 17 | obj = context |
---|
| 18 | |
---|
| 19 | parent = obj.inReplyTo() |
---|
| 20 | if parent is not None: |
---|
| 21 | dtool = getToolByName(context, 'portal_discussion') |
---|
| 22 | talkback = dtool.getDiscussionFor(parent) |
---|
| 23 | else: |
---|
| 24 | talkback = parent = obj.aq_parent |
---|
| 25 | |
---|
| 26 | reply = talkback.getReply(obj.getId()) |
---|
| 27 | publishDiscussion(reply) |
---|
| 28 | manage_mails(reply, context, action='publishing') |
---|
| 29 | |
---|
| 30 | putils = getToolByName(context, 'plone_utils') |
---|
| 31 | redirect_target = putils.getDiscussionThread(talkback)[0] |
---|
| 32 | view = redirect_target.getTypeInfo().getActionInfo('object/view')['url'] |
---|
[1059] | 33 | rt = redirect_target.absolute_url() |
---|
| 34 | |
---|
| 35 | if rt and rt[-1] == '/': |
---|
| 36 | rt = rt[:-1] |
---|
| 37 | |
---|
| 38 | if view and view[0] == '/': |
---|
| 39 | view = view[1:] |
---|
| 40 | |
---|
| 41 | if view and view[-1] == '/': |
---|
| 42 | view = view[:-1] |
---|
| 43 | |
---|
[822] | 44 | anchor = reply.getId() |
---|
| 45 | |
---|
| 46 | transaction_note('Published discussion item') |
---|
| 47 | |
---|
| 48 | context.plone_utils.addPortalMessage(_(u'Comment published.')) |
---|
[1059] | 49 | target = '%s/%s#%s' % (rt, view, anchor) |
---|
[822] | 50 | |
---|
| 51 | return context.REQUEST.RESPONSE.redirect(target) |
---|