[1] | 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 | from Products.PythonScripts.standard import url_quote_plus |
---|
| 10 | from Products.qPloneComments.utils import send_email |
---|
| 11 | |
---|
| 12 | req = context.REQUEST |
---|
| 13 | |
---|
| 14 | if 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 # |
---|
| 43 | isForAnonymous = context.isForAnonymous() |
---|
| 44 | comment_creator = req.get('Creator', None) |
---|
| 45 | if isForAnonymous and comment_creator: |
---|
| 46 | # Get entered anonymous name |
---|
| 47 | comment_creator = comment_creator |
---|
| 48 | else: |
---|
| 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 | |
---|
| 55 | tb = context.talkback |
---|
| 56 | id = tb.createReply(title=subject, text=body_text, Creator=comment_creator) |
---|
| 57 | reply = tb.getReply(id) |
---|
| 58 | |
---|
| 59 | #XXX THIS NEEDS TO GO AWAY! |
---|
| 60 | portal_discussion=context.portal_discussion |
---|
| 61 | if hasattr(portal_discussion.aq_explicit, 'cookReply'): |
---|
| 62 | portal_discussion.cookReply(reply, text_format='plain') |
---|
| 63 | |
---|
| 64 | parent = tb.aq_parent |
---|
| 65 | |
---|
| 66 | from Products.CMFPlone import transaction_note |
---|
| 67 | transaction_note('Added comment to %s at %s' % (parent.title_or_id(), reply.absolute_url())) |
---|
| 68 | |
---|
| 69 | target = '%s/%s' % (parent.absolute_url(), parent.getTypeInfo().getActionById('view')) |
---|
| 70 | |
---|
| 71 | # Send notification e-mail |
---|
| 72 | send_email(reply, context) |
---|
| 73 | |
---|
| 74 | # Inform user about awaiting moderation |
---|
| 75 | portal_status_message='Comment successfully added.' |
---|
| 76 | ifModerate = context.ifModerate() |
---|
| 77 | if ifModerate and reply: |
---|
| 78 | portal_status_message='Your comment awaits moderartion.' |
---|
| 79 | |
---|
| 80 | return state.set(portal_status_message=portal_status_message) |
---|