[58] | 1 | ## Script (Python) "discussion_reply" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind state=state |
---|
| 7 | ##bind subpath=traverse_subpath |
---|
| 8 | ##parameters=subject,body_text,text_format='plain',username=None,password=None |
---|
| 9 | ##title=Reply to content |
---|
| 10 | |
---|
| 11 | from Products.PythonScripts.standard import url_quote_plus |
---|
| 12 | from Products.CMFCore.utils import getToolByName |
---|
[59] | 13 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
[58] | 14 | mtool = getToolByName(context, 'portal_membership') |
---|
| 15 | dtool = getToolByName(context, 'portal_discussion') |
---|
| 16 | req = context.REQUEST |
---|
| 17 | |
---|
| 18 | if username or password: |
---|
| 19 | # The user username/password inputs on on the comment form were used, |
---|
| 20 | # which might happen when anonymous commenting is enabled. If they typed |
---|
| 21 | # something in to either of the inputs, we send them to 'logged_in'. |
---|
| 22 | # 'logged_in' will redirect them back to this script if authentication |
---|
| 23 | # succeeds with a query string which will post the message appropriately |
---|
| 24 | # and show them the result. if 'logged_in' fails, the user will be |
---|
| 25 | # presented with the stock login failure page. This all depends |
---|
| 26 | # heavily on cookiecrumbler, but I believe that is a Plone requirement. |
---|
| 27 | came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text) |
---|
| 28 | came_from = url_quote_plus(came_from) |
---|
| 29 | portal_url = context.portal_url() |
---|
| 30 | |
---|
| 31 | return req.RESPONSE.redirect( |
---|
| 32 | '%s/logged_in?__ac_name=%s' |
---|
| 33 | '&__ac_password=%s' |
---|
| 34 | '&came_from=%s' % (portal_url, |
---|
| 35 | url_quote_plus(username), |
---|
| 36 | url_quote_plus(password), |
---|
| 37 | came_from, |
---|
| 38 | ) |
---|
| 39 | ) |
---|
| 40 | |
---|
| 41 | # if (the user is already logged in) or (if anonymous commenting is enabled and |
---|
| 42 | # they posted without typing a username or password into the form), we do |
---|
| 43 | # the following |
---|
| 44 | |
---|
| 45 | creator = mtool.getAuthenticatedMember().getId() |
---|
| 46 | tb = dtool.getDiscussionFor(context) |
---|
| 47 | id = tb.createReply(title=subject, text=body_text, Creator=creator) |
---|
| 48 | reply = tb.getReply(id) |
---|
| 49 | |
---|
| 50 | # TODO THIS NEEDS TO GO AWAY! |
---|
| 51 | if hasattr(dtool.aq_explicit, 'cookReply'): |
---|
| 52 | dtool.cookReply(reply, text_format='plain') |
---|
| 53 | |
---|
| 54 | parent = tb.aq_parent |
---|
| 55 | |
---|
| 56 | # return to the discussable object. |
---|
| 57 | redirect_target = context.plone_utils.getDiscussionThread(tb)[0] |
---|
[59] | 58 | view = redirect_target.getTypeInfo().getActionInfo('object/view', |
---|
| 59 | redirect_target)['url'] |
---|
[58] | 60 | anchor = reply.getId() |
---|
| 61 | |
---|
| 62 | from Products.CMFPlone.utils import transaction_note |
---|
[59] | 63 | transaction_note('Added comment to %s at %s' % (parent.title_or_id(), |
---|
| 64 | reply.absolute_url())) |
---|
[58] | 65 | |
---|
[59] | 66 | context.plone_utils.addPortalMessage(_(u'Comment added.')) |
---|
| 67 | target = '%s#%s' % (view, anchor) |
---|
[58] | 68 | return req.RESPONSE.redirect(target) |
---|