source: products/qPloneComments/tags/1.7b/skins/qplonecomments/discussion_reply.cpy @ 1591

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

Building directory structure

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