source: products/SimpleBlog/trunk/TrackbackWorkflow.py

Last change on this file was 1, checked in by myroslav, 14 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 8.1 KB
Line 
1#
2#
3# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
4# Original workflow id/title: trackback_workflow/TrackBack Workflow
5# Date: 2005/09/30 17:29:38.476 GMT+3
6#
7# WARNING: this dumps does NOT contain any scripts you might have added to
8# the workflow, IT IS YOUR RESPONSABILITY TO MAKE BACKUPS FOR THESE SCRIPTS.
9#
10# The following scripts have been detected and should be backed up:
11# - notifyTrackBack (Script (Python))
12# - sbPublishEntry (Script (Python))
13# - notifyTB (External Method)
14#
15"""
16Programmatically creates a workflow type
17"""
18__version__ = "$Revision: 1.1.1.1 $"[11:-2]
19
20from Products.CMFCore.WorkflowTool import addWorkflowFactory
21
22from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
23
24script_notifyTrackBack = """## Script (Python) "notifyTrackBack"
25##bind container=container
26##bind context=context
27##bind namespace=
28##bind script=script
29##bind subpath=traverse_subpath
30##parameters=change_state=None
31##title=notify about TrackBack creating
32##
33from zLOG import LOG
34LOG('SimpleBlog.TrackbackWorkflow',203,'debug','notifyTrackBack sript JUST CALLED')
35if not change_state:
36    return None
37obj = change_state.object
38# get to- and from- emails
39member = context.portal_membership.getAuthenticatedMember()
40blog = context.simpleblog_tool.getFrontPage(obj)
41to_email = blog.getAdminEmail()
42from_email = context.portal_url.getPortalObject().getProperty("email_from_address", "andrijm@neonet.if.ua")
43if to_email:
44    # get additional data for mail-template
45    post_title = obj.aq_parent.Title()
46    obj_url = obj.absolute_url()
47    charset = context.portal_properties.site_properties.getProperty('default_charset','utf-8')
48    body = obj.notifyTBtemplate(from_email=from_email, to_email=to_email, charset=charset, post_title=post_title, obj_url=obj_url)
49    try:
50        mh = context.MailHost
51        mh.send(body)
52    except:
53        pass
54LOG('SimpleBlog.TrackbackWorkflow',203,'debug','notifyTrackBack sript SUCCESSFULLY COMPLETED')
55"""
56
57
58def setupTrackback_workflow(wf):
59    "..."
60    wf.setProperties(title='TrackBack Workflow')
61
62    for s in ['new', 'pending', 'published']:
63        wf.states.addState(s)
64    for t in ['retract', 'publish', 'make_pending']:
65        wf.transitions.addTransition(t)
66    for v in ['action', 'review_history', 'comments', 'actor', 'time']:
67        wf.variables.addVariable(v)
68    for l in []:
69        wf.worklists.addWorklist(l)
70    for p in ('Access contents information', 'Modify portal content', 'View'):
71        wf.addManagedPermission(p)
72
73
74    #from Products.PythonScripts.PythonScript import manage_addPythonScript
75    #for p in ['notifyTrackBack']:
76    #    manage_addPythonScript(wf.scripts, p)
77    #    srcdef = wf.scripts['notifyTrackBack']
78    #    srcdef.ZPythonScript_edit('', script_notifyTrackBack)
79    #    srcdef._proxy_roles = ( "Manager", )
80    #    #roles = ("Manager",)
81    #    #srcdef.manage_proxy(roles)
82
83    from Products.ExternalMethod.ExternalMethod import manage_addExternalMethod
84    manage_addExternalMethod(wf.scripts, 
85                             id='notifyTrackBack', 
86                             title='',
87                             module='SimpleBlog.utils',
88                             function='notifyTrackBack')
89
90    ## Initial State
91    wf.states.setInitialState('new')
92
93    ## States initialization
94    sdef = wf.states['new']
95    sdef.setProperties(title="""""",
96                       transitions=('make_pending',))
97    sdef.setPermission('Access contents information', 1, [])
98    sdef.setPermission('Modify portal content', 1, [])
99    sdef.setPermission('View', 1, [])
100
101    sdef = wf.states['pending']
102    sdef.setProperties(title="""""",
103                       transitions=('publish',))
104    sdef.setPermission('Access contents information', 0, ['Manager', 'Owner'])
105    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner'])
106    sdef.setPermission('View', 0, ['Manager', 'Owner'])
107
108    sdef = wf.states['published']
109    sdef.setProperties(title="""Public""",
110                       transitions=('retract',))
111    sdef.setPermission('Access contents information', 1, ['Anonymous', 'Manager'])
112    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner'])
113    sdef.setPermission('View', 0, ['Anonymous', 'Authenticated', 'Manager'])
114
115
116    ## Transitions initialization
117    tdef = wf.transitions['retract']
118    tdef.setProperties(title="""Member retracts published item""",
119                       new_state_id="""pending""",
120                       trigger_type=1,
121                       script_name="""""",
122                       after_script_name="""""",
123                       actbox_name="""Retract""",
124                       actbox_url="""%(content_url)s/content_retract_form""",
125                       actbox_category="""workflow""",
126                       props={'guard_roles': 'Owner; Manager'},
127                       )
128
129    tdef = wf.transitions['publish']
130    tdef.setProperties(title="""Reviewer publishes content""",
131                       new_state_id="""published""",
132                       trigger_type=1,
133                       script_name="""""",
134                       after_script_name="""""",
135                       actbox_name="""Publish""",
136                       actbox_url="""%(content_url)s/content_publish_form""",
137                       actbox_category="""workflow""",
138                       props={'guard_roles': 'Manager; Owner'},
139                       )
140
141    tdef = wf.transitions['make_pending']
142    tdef.setProperties(title="""Make pending""",
143                       new_state_id="""pending""",
144                       trigger_type=0,
145                       script_name="""notifyTrackBack""",
146                       after_script_name="""""",
147                       actbox_name="""""",
148                       actbox_url="""""",
149                       actbox_category="""workflow""",
150                       props=None,
151                       )
152
153    ## State Variable
154    wf.variables.setStateVar('review_state')
155
156    ## Variables initialization
157    vdef = wf.variables['action']
158    vdef.setProperties(description="""The last transition""",
159                       default_value="""""",
160                       default_expr="""transition/getId|nothing""",
161                       for_catalog=0,
162                       for_status=1,
163                       update_always=1,
164                       props=None)
165
166    vdef = wf.variables['review_history']
167    vdef.setProperties(description="""Provides access to workflow history""",
168                       default_value="""""",
169                       default_expr="""state_change/getHistory""",
170                       for_catalog=0,
171                       for_status=0,
172                       update_always=0,
173                       props={'guard_permissions': 'Request review; Review portal content'})
174
175    vdef = wf.variables['comments']
176    vdef.setProperties(description="""Comments about the last transition""",
177                       default_value="""""",
178                       default_expr="""python:state_change.kwargs.get('comment', '')""",
179                       for_catalog=0,
180                       for_status=1,
181                       update_always=1,
182                       props=None)
183
184    vdef = wf.variables['actor']
185    vdef.setProperties(description="""The ID of the user who performed the last transition""",
186                       default_value="""""",
187                       default_expr="""user/getId""",
188                       for_catalog=0,
189                       for_status=1,
190                       update_always=1,
191                       props=None)
192
193    vdef = wf.variables['time']
194    vdef.setProperties(description="""Time of the last transition""",
195                       default_value="""""",
196                       default_expr="""state_change/getDateTime""",
197                       for_catalog=0,
198                       for_status=1,
199                       update_always=1,
200                       props=None)
201
202    ## Worklists Initialization
203
204def createTrackback_workflow(id):
205    "..."
206    ob = DCWorkflowDefinition(id)
207    setupTrackback_workflow(ob)
208    return ob
209
210addWorkflowFactory(createTrackback_workflow,
211                   id='trackback_workflow',
212                   title='TrackBack Workflow')
213
214   
Note: See TracBrowser for help on using the repository browser.