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 | ## |
---|
11 | REQUEST=context.REQUEST |
---|
12 | |
---|
13 | from Products.CMFPlone import transaction_note |
---|
14 | from Products.CMFCore.utils import getToolByName |
---|
15 | from ZODB.POSException import ConflictError |
---|
16 | |
---|
17 | plone_utils = getToolByName(context, 'plone_utils') |
---|
18 | site_properties = getToolByName(context, 'portal_properties').site_properties |
---|
19 | |
---|
20 | # need to check visible state of 'sendto' action in portal_actions |
---|
21 | # but I couldn't figure out how - update collector issue #1490 |
---|
22 | # when implemented |
---|
23 | at = getToolByName(context, 'portal_actions') |
---|
24 | |
---|
25 | #if not sendto_action.visible : |
---|
26 | if 0: |
---|
27 | return state.set( |
---|
28 | status='failure', |
---|
29 | portal_status_message='You are not allowed to send this link.') |
---|
30 | |
---|
31 | # Try to find the view action. If not found, use absolute_url() |
---|
32 | url = context.absolute_url() |
---|
33 | ti = context.getTypeInfo() |
---|
34 | if ti is not None: |
---|
35 | view = ti.getActionById('view', '') |
---|
36 | if view: |
---|
37 | url = '/'.join((url, view)) |
---|
38 | |
---|
39 | variables = {'send_from_address' : REQUEST.send_from_address, |
---|
40 | 'send_to_address' : REQUEST.send_to_address, |
---|
41 | 'url' : url, |
---|
42 | 'title' : context.Title(), |
---|
43 | 'description' : context.Description(), |
---|
44 | 'comment' : REQUEST.get('comment', None) |
---|
45 | } |
---|
46 | |
---|
47 | try: |
---|
48 | plone_utils.sendto( variables ) |
---|
49 | except ConflictError: |
---|
50 | raise |
---|
51 | except: #XXX To many things could possibly go wrong. So we catch all. |
---|
52 | exception = context.plone_utils.exceptionString() |
---|
53 | return state.set(status='failure', portal_status_message=exception) |
---|
54 | |
---|
55 | tmsg='Sent page %s to %s' % (url, REQUEST.send_to_address) |
---|
56 | transaction_note(tmsg) |
---|
57 | |
---|
58 | return state.set(portal_status_message='Mail sent.') |
---|