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

Last change on this file since 1871 was 1871, checked in by liebster, 14 years ago

Revert 2726 to 2589 commits for tagging plone-3 compatible version

File size: 2.5 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
28at = getToolByName(context, 'portal_actions')
29show = False
30actions = at.listActionInfos(object=context)
31# Check for visbility of sendto action
32for action in actions:
33    if action['id'] == 'sendto' and action['category'] == 'document_actions':
34        show = True
35if not show:
36    context.plone_utils.addPortalMessage(_(u'You are not allowed to send this link.'), 'error')
37    return state.set(status='failure')
38
39# Find the view action.
40context_state = context.restrictedTraverse("@@plone_context_state")
41url = context_state.view_url()
42
43variables = {'send_from_address' : REQUEST.send_from_address,
44             'send_to_address'   : REQUEST.send_to_address,
45             'subject'           : pretty_title_or_id(context),
46             'url'               : url,
47             'title'             : pretty_title_or_id(context),
48             'description'       : context.Description(),
49             'comment'           : REQUEST.get('comment', None),
50             'envelope_from'     : site_properties.email_from_address
51             }
52
53try:
54    plone_utils.sendto( **variables )
55except ConflictError:
56    raise
57except: # TODO To many things could possibly go wrong. So we catch all.
58    exception = context.plone_utils.exceptionString()
59    message = _(u'Unable to send mail: ${exception}',
60                mapping={u'exception' : exception})
61    context.plone_utils.addPortalMessage(message, 'error')
62    return state.set(status='failure')
63
64tmsg='Sent page %s to %s' % (url, REQUEST.send_to_address)
65transaction_note(tmsg)
66
67context.plone_utils.addPortalMessage(_(u'Mail sent.'))
68return state
Note: See TracBrowser for help on using the repository browser.