source: products/qPloneComments/trunk/skins/qplonecomments/discussion_reply.cpy @ 1221

Last change on this file since 1221 was 806, checked in by crchemist, 17 years ago

Add role 'Editor' to portal.

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