-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZMSWorkflowActivitiesManager.py
189 lines (169 loc) · 7.13 KB
/
ZMSWorkflowActivitiesManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
################################################################################
# ZMSWorkflowActivitiesManager.py
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
################################################################################
# Imports.
import ZPublisher.HTTPRequest
import copy
import sys
import time
import urllib
# Product Imports.
import _blobfields
import _globals
################################################################################
################################################################################
###
### Class
###
################################################################################
################################################################################
class ZMSWorkflowActivitiesManager:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.setActivity
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def setActivity(self, id, newId, newName, newIcon=None):
obs = self.activities
# Remove exisiting entry.
if id in obs:
i = obs.index(id)
del obs[i]
del obs[i]
else:
i = len(obs)
# Values.
newValues = {}
newValues['name'] = newName
newValues['icon'] = newIcon
for obj_id in ['%s.icon'%str(id),'%s.icon'%str(newId)]:
if obj_id in self.objectIds():
self.manage_delObjects([obj_id])
if isinstance(newIcon,_blobfields.MyBlob):
self.manage_addFile(id='%s.icon'%newId,title=newIcon.getFilename(),file=newIcon.getData())
# Update attribute.
obs.insert(i,newValues)
obs.insert(i,newId)
self.activities = copy.copy(obs)
# Return with new id.
return newId
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.getActivities
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def getActivities(self):
obs = self.activities
activities = []
for i in range(len(obs)/2):
id = obs[i*2]
activity = obs[i*2+1].copy()
activity['id'] = id
activities.append(activity)
return activities
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.getActivityIds
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def getActivityIds(self):
obs = self.getActivities()
return map(lambda x: x['id'], obs)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.getActivity
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def getActivity(self, id, for_export=False):
activity = filter(lambda x: x['id']==id, self.getActivities())[0]
activity = copy.deepcopy(activity)
if not for_export:
if activity['icon']:
activity['icon'] = self.absolute_url()+'/'+id+'.icon'
return activity
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.getActivityDetails
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def getActivityDetails(self, id):
ids = self.getActivityIds()
froms = []
tos = []
for transition in self.getTransitions():
if transition['to'] is not None and len(transition['to']) > 0 and id in transition['to']:
for ac_id in transition['from']:
if ac_id in ids:
idx = ids.index(ac_id)
if idx not in froms:
froms.append(idx)
if transition['from'] is not None and len(transition['from']) > 0 and id in transition['from']:
for ac_id in transition['to']:
if ac_id in ids:
idx = ids.index(ac_id)
if idx not in tos:
tos.append(idx)
froms.sort()
tos.sort()
idxs = self.concat_list(froms,tos)
idx = ids.index(id)
return {'froms':froms, 'tos': tos, 'idxs': idxs, 'idx': idx}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
ZMSWorkflowActivitiesManager.manage_changeActivities
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
def manage_changeActivities(self, lang, btn='', REQUEST=None, RESPONSE=None):
""" ZMSWorkflowActivitiesManager.manage_changeActivities """
message = ''
id = REQUEST.get('id','')
# Cancel.
# -------
if btn in [ self.getZMILangStr('BTN_CANCEL'), self.getZMILangStr('BTN_BACK')]:
id = ''
# Change.
# -------
if btn == self.getZMILangStr('BTN_SAVE'):
item = self.getActivity(id)
newId = REQUEST.get('inpId').strip()
newName = REQUEST.get('inpName').strip()
newIcon = REQUEST.get('inpIcon','')
if isinstance(newIcon,ZPublisher.HTTPRequest.FileUpload):
if len(getattr(newIcon,'filename',''))==0:
newIcon = item.get('icon',None)
else:
newIcon = _blobfields.createBlobField(self,_globals.DT_IMAGE,newIcon)
id = self.setActivity( item.get('id',None), newId, newName, newIcon)
message = self.getZMILangStr('MSG_CHANGED')
# Delete.
# -------
elif btn in ['delete',self.getZMILangStr('BTN_DELETE')]:
id = self.delItem(id, 'activities')
message = self.getZMILangStr('MSG_CHANGED')
# Insert.
# -------
elif btn == self.getZMILangStr('BTN_INSERT'):
item = {}
newId = REQUEST.get('newId').strip()
newName = REQUEST.get('newName').strip()
newIcon = REQUEST.get('newIcon','')
if isinstance(newIcon,ZPublisher.HTTPRequest.FileUpload):
if len(getattr(newIcon,'filename',''))==0:
newIcon = item.get('icon',None)
else:
newIcon = _blobfields.createBlobField(self,_globals.DT_IMAGE,newIcon)
id = self.setActivity( item.get('id',None), newId, newName, newIcon)
message = self.getZMILangStr('MSG_INSERTED')%id
# Move to.
# --------
elif btn == 'move_to':
pos = REQUEST['pos']
self.moveItem(id, pos, 'activities')
message = self.getZMILangStr('MSG_MOVEDOBJTOPOS')%(("<i>%s</i>"%id),(pos+1))
id = ''
# Return with message.
message = urllib.quote(message)
return RESPONSE.redirect('manage_main?lang=%s&manage_tabs_message=%s#_Activities'%(lang,message))
################################################################################