source: products/qPloneCaptchas/tags/1.3.3/skins/captchas_sendto_form/2.5/sendto.cpy @ 2284

Last change on this file since 2284 was 3, checked in by crchemist, 19 years ago

initial import

  • Property svn:eol-style set to native
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.'))
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.'))
37    return state.set(status='failure')
38
39# Try to find the view action. If not found, use absolute_url()
40url = context.absolute_url()
41ti = context.getTypeInfo()
42if ti is not None:
43    view = ti.getActionById('view', '')
44    if view:
45        url = '/'.join((url, view))
46
47variables = {'send_from_address' : REQUEST.send_from_address,
48             'send_to_address'   : REQUEST.send_to_address,
49             'subject'           : pretty_title_or_id(context),
50             'url'               : url,
51             'title'             : pretty_title_or_id(context),
52             'description'       : context.Description(),
53             'comment'           : REQUEST.get('comment', None),
54             'envelope_from'     : site_properties.email_from_address
55             }
56
57try:
58    plone_utils.sendto( **variables )
59except ConflictError:
60    raise
61except: # TODO To many things could possibly go wrong. So we catch all.
62    exception = context.plone_utils.exceptionString()
63    message = _(u'Unable to send mail: ${exception}',
64                mapping={u'exception' : exception})
65    context.plone_utils.addPortalMessage(message)
66    return state.set(status='failure')
67
68tmsg='Sent page %s to %s' % (url, REQUEST.send_to_address)
69transaction_note(tmsg)
70
71context.plone_utils.addPortalMessage(_(u'Mail sent.'))
72return state
Note: See TracBrowser for help on using the repository browser.