source: products/quintagroup.plonecomments/branches/jquery/quintagroup/plonecomments/skins/quintagroup_plonecomments/discussion_reply.cpy @ 2597

Last change on this file since 2597 was 2137, checked in by kroman0, 14 years ago

PEP8 fixes

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