source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/skins/captchas_sendto_form/sendto.cpy

Last change on this file was 2454, checked in by mylan, 14 years ago

#194: Fixed sendto form for plone-4

File size: 2.1 KB
Line 
1## Controller Python Script "sendto"
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=
9##title=Send an URL to a friend
10##
11REQUEST=context.REQUEST
12
13from Products.CMFPlone.utils import transaction_note
14from Products.CMFPlone.PloneTool import AllowSendto
15from Products.CMFCore.utils import getToolByName
16from Products.CMFPlone import PloneMessageFactory as _
17from ZODB.POSException import ConflictError
18
19plone_utils = getToolByName(context, 'plone_utils')
20mtool = getToolByName(context, 'portal_membership')
21site_properties = getToolByName(context, 'portal_properties').site_properties
22pretty_title_or_id = plone_utils.pretty_title_or_id
23
24if not mtool.checkPermission(AllowSendto, context):
25    context.plone_utils.addPortalMessage(_(u'You are not allowed to send this link.'), 'error')
26    return state.set(status='failure')
27
28# Find the view action.
29context_state = context.restrictedTraverse("@@plone_context_state")
30url = context_state.view_url()
31
32variables = {'send_from_address' : REQUEST.send_from_address,
33             'send_to_address'   : REQUEST.send_to_address,
34             'subject'           : pretty_title_or_id(context),
35             'url'               : url,
36             'title'             : pretty_title_or_id(context),
37             'description'       : context.Description(),
38             'comment'           : REQUEST.get('comment', None),
39             'envelope_from'     : site_properties.email_from_address
40             }
41
42try:
43    plone_utils.sendto( **variables )
44except ConflictError:
45    raise
46except: # TODO To many things could possibly go wrong. So we catch all.
47    exception = context.plone_utils.exceptionString()
48    message = _(u'Unable to send mail: ${exception}',
49                mapping={u'exception' : exception})
50    context.plone_utils.addPortalMessage(message, 'error')
51    return state.set(status='failure')
52
53tmsg='Sent page %s to %s' % (url, REQUEST.send_to_address)
54transaction_note(tmsg)
55
56context.plone_utils.addPortalMessage(_(u'Mail sent.'))
57return state
Note: See TracBrowser for help on using the repository browser.