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