source: products/qPloneCaptchas/trunk/skins/captchas_discussion/2.5/discussion_reply.cpy @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 2.6 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
13mtool = getToolByName(context, 'portal_membership')
14dtool = getToolByName(context, 'portal_discussion')
15req = context.REQUEST
16
17if username or password:
18    # The user username/password inputs on on the comment form were used,
19    # which might happen when anonymous commenting is enabled. If they typed
20    # something in to either of the inputs, we send them to 'logged_in'.
21    # 'logged_in' will redirect them back to this script if authentication
22    # succeeds with a query string which will post the message appropriately
23    # and show them the result.  if 'logged_in' fails, the user will be
24    # presented with the stock login failure page.  This all depends
25    # heavily on cookiecrumbler, but I believe that is a Plone requirement.
26    came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text)
27    came_from = url_quote_plus(came_from)
28    portal_url = context.portal_url()
29
30    return req.RESPONSE.redirect(
31        '%s/logged_in?__ac_name=%s'
32        '&__ac_password=%s'
33        '&came_from=%s' % (portal_url,
34                               url_quote_plus(username),
35                               url_quote_plus(password),
36                               came_from,
37                               )
38        )
39
40# if (the user is already logged in) or (if anonymous commenting is enabled and
41# they posted without typing a username or password into the form), we do
42# the following
43
44creator = mtool.getAuthenticatedMember().getUserName()
45tb = dtool.getDiscussionFor(context)
46id = tb.createReply(title=subject, text=body_text, Creator=creator)
47reply = tb.getReply(id)
48
49# TODO THIS NEEDS TO GO AWAY!
50if hasattr(dtool.aq_explicit, 'cookReply'):
51    dtool.cookReply(reply, text_format='plain')
52
53parent = tb.aq_parent
54
55# return to the discussable object.
56redirect_target = context.plone_utils.getDiscussionThread(tb)[0]
57view = redirect_target.getTypeInfo().getActionById('view')
58anchor = reply.getId()
59
60from Products.CMFPlone.utils import transaction_note
61transaction_note('Added comment to %s at %s' % (parent.title_or_id(), reply.absolute_url()))
62
63target = '%s/%s?portal_status_message=Comment+added#%s' % (redirect_target.absolute_url(), view, anchor)
64return req.RESPONSE.redirect(target)
Note: See TracBrowser for help on using the repository browser.