[858] | 1 | ## Script (Python) "discussion_edit" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=subject,body_text |
---|
| 8 | ##title=Delete discussion item |
---|
| 9 | ## |
---|
| 10 | |
---|
| 11 | from Products.PythonScripts.standard import url_quote_plus |
---|
| 12 | from Products.CMFCore.utils import getToolByName |
---|
| 13 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
| 14 | dtool = getToolByName(context, 'portal_discussion') |
---|
| 15 | req = context.REQUEST |
---|
| 16 | |
---|
| 17 | tb = dtool.getDiscussionFor(context) |
---|
| 18 | id = context.getId() |
---|
| 19 | reply = tb.getReply(id) |
---|
| 20 | |
---|
| 21 | modif_date = reply.modification_date |
---|
| 22 | |
---|
| 23 | # Set Title |
---|
| 24 | reply.setTitle(subject) |
---|
| 25 | |
---|
| 26 | # Update text |
---|
| 27 | reply.edit(text_format=reply.Format(), text=body_text) |
---|
| 28 | |
---|
| 29 | # TODO THIS NEEDS TO GO AWAY! |
---|
| 30 | if hasattr(dtool.aq_explicit, 'cookReply'): |
---|
| 31 | dtool.cookReply(reply, text_format='plain') |
---|
| 32 | |
---|
| 33 | # Set modification date to old value |
---|
| 34 | reply.setModificationDate(modification_date=modif_date) |
---|
| 35 | |
---|
| 36 | parent = tb.aq_parent |
---|
| 37 | |
---|
| 38 | # return to the discussable object. |
---|
| 39 | redirect_target = context.plone_utils.getDiscussionThread(tb)[0] |
---|
| 40 | view = redirect_target.getTypeInfo().getActionInfo('object/view', |
---|
| 41 | redirect_target)['url'] |
---|
| 42 | anchor = reply.getId() |
---|
| 43 | |
---|
| 44 | from Products.CMFPlone.utils import transaction_note |
---|
| 45 | transaction_note('Added comment to %s at %s' % (parent.title_or_id(), |
---|
| 46 | reply.absolute_url())) |
---|
| 47 | |
---|
| 48 | context.plone_utils.addPortalMessage(_(u'Comment updated.')) |
---|
| 49 | target = '%s#%s' % (view, anchor) |
---|
| 50 | return req.RESPONSE.redirect(target) |
---|