source: products/qPloneCaptchas/tags/1.3.1/skins/captchas_sendto_form/2.1.2/sendto.cpy @ 458

Last change on this file since 458 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 ZODB.POSException import ConflictError
17
18plone_utils = getToolByName(context, 'plone_utils')
19mtool = getToolByName(context, 'portal_membership')
20site_properties = getToolByName(context, 'portal_properties').site_properties
21pretty_title_or_id = plone_utils.pretty_title_or_id
22empty_title = plone_utils.getEmptyTitle()
23
24if not mtool.checkPermission(AllowSendto, context):
25    return state.set(
26            status='failure',
27            portal_status_message='You are not allowed to send this link.')
28
29at = getToolByName(context, 'portal_actions')
30show = False
31actions = at.listActionInfos(object=context)
32# Check for visbility of sendto action
33for action in actions:
34    if action['id'] == 'sendto' and action['category'] == 'document_actions':
35        show = True
36if not show:
37    return state.set(
38        status='failure',
39        portal_status_message='You are not allowed to send this link.')
40
41# Try to find the view action. If not found, use absolute_url()
42url = context.absolute_url()
43ti = context.getTypeInfo()
44if ti is not None:
45    view = ti.getActionById('view', '')
46    if view:
47        url = '/'.join((url, view))
48
49variables = {'send_from_address' : REQUEST.send_from_address,
50             'send_to_address'   : REQUEST.send_to_address,
51             'subject'           : pretty_title_or_id(context),
52             'url'               : url,
53             'title'             : pretty_title_or_id(context),
54             'description'       : context.Description(),
55             'comment'           : REQUEST.get('comment', None),
56             'envelope_from'     : site_properties.email_from_address
57             }
58
59try:
60    plone_utils.sendto( **variables )
61except ConflictError:
62    raise
63except: # TODO To many things could possibly go wrong. So we catch all.
64    exception = context.plone_utils.exceptionString()
65    message = context.translate("Unable to send mail: ${exception}",
66                                {'exception': exception})
67    return state.set(status='failure', portal_status_message=message)
68
69tmsg='Sent page %s to %s' % (url, REQUEST.send_to_address)
70transaction_note(tmsg)
71
72return state.set(portal_status_message='Mail sent.')
Note: See TracBrowser for help on using the repository browser.