source: products/qPloneCaptchas/tags/0.8/skins/captchas_qcomments/2.1.2/discussion_reply.cpy @ 1

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

Building directory structure

  • Property svn:eol-style set to native
File size: 3.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.qPloneComments.utils import send_email
14
15mtool = getToolByName(context, 'portal_membership')
16dtool = getToolByName(context, 'portal_discussion')
17req = context.REQUEST
18pp = getToolByName(context,'portal_properties')
19# Get properties
20isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
21ifModerate = pp['qPloneComments'].getProperty('enable_moderation', None);
22
23if username or password:
24    # The user username/password inputs on on the comment form were used,
25    # which might happen when anonymous commenting is enabled. If they typed
26    # something in to either of the inputs, we send them to 'logged_in'.
27    # 'logged_in' will redirect them back to this script if authentication
28    # succeeds with a query string which will post the message appropriately
29    # and show them the result.  if 'logged_in' fails, the user will be
30    # presented with the stock login failure page.  This all depends
31    # heavily on cookiecrumbler, but I believe that is a Plone requirement.
32    came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text)
33    came_from = url_quote_plus(came_from)
34    portal_url = context.portal_url()
35
36    return req.RESPONSE.redirect(
37        '%s/logged_in?__ac_name=%s'
38        '&__ac_password=%s'
39        '&came_from=%s' % (portal_url,
40                               url_quote_plus(username),
41                               url_quote_plus(password),
42                               came_from,
43                               )
44        )
45
46# if (the user is already logged in) or (if anonymous commenting is enabled and
47# they posted without typing a username or password into the form), we do
48# the following
49
50#########################################################
51# Get discussion item (reply) author and creating reply #
52comment_creator = req.get('Creator', None)
53if isForAnonymous and comment_creator:
54    # Get entered anonymous name
55    comment_creator = comment_creator
56else:
57    member = mtool.getAuthenticatedMember()
58    # Get Member Full name.If not entered - get user login name
59    comment_creator = member.getProperty('fullname')
60    if not comment_creator:
61        comment_creator = member.getUserName()
62
63tb = dtool.getDiscussionFor(context)
64id = tb.createReply(title=subject, text=body_text, Creator=comment_creator)
65reply = tb.getReply(id)
66
67# TODO THIS NEEDS TO GO AWAY!
68if hasattr(dtool.aq_explicit, 'cookReply'):
69    dtool.cookReply(reply, text_format='plain')
70
71parent = tb.aq_parent
72
73# Send notification e-mail
74send_notification_message = send_email(reply, context, state="approve")
75if not ifModerate:
76    send_notification_message += send_email(reply, context, state="published")
77
78# return to the discussable object.
79redirect_target = context.plone_utils.getDiscussionThread(tb)[0]
80view = redirect_target.getTypeInfo().getActionById('view')
81anchor = reply.getId()
82
83# Inform user about awaiting moderation
84portal_status_message='Comment+successfully+added'
85if ifModerate and reply:
86    portal_status_message='Your+comment+awaits+moderation'
87
88from Products.CMFPlone.utils import transaction_note
89transaction_note('Added comment to %s at %s' % (parent.title_or_id(), reply.absolute_url()))
90
91target = '%s/%s?portal_status_message=%s#%s' % (redirect_target.absolute_url(), view, portal_status_message, anchor)
92
93return req.RESPONSE.redirect(target)
Note: See TracBrowser for help on using the repository browser.