source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/skins/captchas_discussion/discussion_reply.cpy @ 1863

Last change on this file since 1863 was 1863, checked in by liebster, 14 years ago

Changed definition plone message factory for using i18ndude rebuild

File size: 2.7 KB
Line 
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
11from Products.PythonScripts.standard import url_quote_plus
12from Products.CMFCore.utils import getToolByName
13from Products.CMFPlone import PloneMessageFactory as pmf
14mtool = getToolByName(context, 'portal_membership')
15dtool = getToolByName(context, 'portal_discussion')
16req = context.REQUEST
17
18if 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
45creator = mtool.getAuthenticatedMember().getId()
46tb = dtool.getDiscussionFor(context)
47id = tb.createReply(title=subject, text=body_text, Creator=creator)
48reply = tb.getReply(id)
49
50# TODO THIS NEEDS TO GO AWAY!
51if hasattr(dtool.aq_explicit, 'cookReply'):
52    dtool.cookReply(reply, text_format='plain')
53
54parent = tb.aq_parent
55
56# return to the discussable object.
57redirect_target = context.plone_utils.getDiscussionThread(tb)[0]
58view = redirect_target.getTypeInfo().getActionInfo('object/view',
59                                                   redirect_target)['url']
60anchor = reply.getId()
61
62from Products.CMFPlone.utils import transaction_note
63transaction_note('Added comment to %s at %s' % (parent.title_or_id(),
64                                                reply.absolute_url()))
65
66context.plone_utils.addPortalMessage(pmf(u'Comment added.'))
67target = '%s#%s' % (view, anchor)
68return req.RESPONSE.redirect(target)
Note: See TracBrowser for help on using the repository browser.