1 | ## Script (Python) "content_status_modify" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=workflow_action, REQUEST=None, **kw |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: content_status_modify.py 29468 2005-11-11 12:33:08Z avoinea $ |
---|
11 | """ |
---|
12 | FIXME: add docstring. |
---|
13 | """ |
---|
14 | |
---|
15 | wftool = context.portal_workflow |
---|
16 | |
---|
17 | if REQUEST is not None: |
---|
18 | kw.update(REQUEST.form) |
---|
19 | |
---|
20 | comments = kw.get('comments', '') |
---|
21 | |
---|
22 | folder = context.aq_parent |
---|
23 | id = context.getId() |
---|
24 | url = None |
---|
25 | |
---|
26 | psm = 'psm_status_changed' |
---|
27 | |
---|
28 | if workflow_action in ('retract','approve'): |
---|
29 | # accept, reject, ... |
---|
30 | if comments: |
---|
31 | del kw['comments'] |
---|
32 | kw['comment'] = comments |
---|
33 | res = wftool.doActionFor(context, workflow_action, dest_container=context, **kw) |
---|
34 | if same_type(res, ()): |
---|
35 | if res[0] == 'ObjectMoved': |
---|
36 | rpath = res[1] |
---|
37 | url = context.portal_url() |
---|
38 | if not url.endswith('/'): |
---|
39 | url += '/' |
---|
40 | url += rpath |
---|
41 | elif workflow_action != 'copy_submit': |
---|
42 | # accept, reject, ... |
---|
43 | if comments: |
---|
44 | del kw['comments'] |
---|
45 | kw['comment'] = comments |
---|
46 | res = wftool.doActionFor(context, workflow_action, **kw) |
---|
47 | if same_type(res, ()): |
---|
48 | if res[0] == 'ObjectMoved': |
---|
49 | rpath = res[1] |
---|
50 | url = context.portal_url() |
---|
51 | if not url.endswith('/'): |
---|
52 | url += '/' |
---|
53 | url += rpath |
---|
54 | else: |
---|
55 | # No section has been specified |
---|
56 | # XXX We should get a list in here |
---|
57 | if REQUEST and len(REQUEST.form) < 3: |
---|
58 | psm = 'psm_you_must_select_sections_for_publishing' |
---|
59 | |
---|
60 | # publishing: copy and initalize proxy into one or more sections |
---|
61 | allowed_transitions = wftool.getAllowedPublishingTransitions(context) |
---|
62 | for transition in allowed_transitions: |
---|
63 | rpaths = kw.get(transition) |
---|
64 | if rpaths: |
---|
65 | if same_type(rpaths, ''): |
---|
66 | rpaths = (rpaths,) |
---|
67 | for rpath in rpaths: |
---|
68 | wftool.doActionFor(context, workflow_action, |
---|
69 | dest_container=rpath, |
---|
70 | initial_transition=transition, |
---|
71 | comment=comments) |
---|
72 | |
---|
73 | if REQUEST is not None: |
---|
74 | # If the object has been deleted, we can't redirect to it. |
---|
75 | if url is None: |
---|
76 | if id in folder.objectIds(): |
---|
77 | url = context.absolute_url() |
---|
78 | else: |
---|
79 | url = folder.absolute_url() |
---|
80 | |
---|
81 | if psm == 'psm_you_must_select_sections_for_publishing': |
---|
82 | redirect_url = '%s/content_submit_form?%s' % ( |
---|
83 | url, 'portal_status_message=%s'%psm) |
---|
84 | else: |
---|
85 | redirect_url = '%s/?%s' % (url, 'portal_status_message=%s'%psm) |
---|
86 | REQUEST.RESPONSE.redirect(redirect_url) |
---|