Created
November 26, 2013 11:08
-
-
Save maethu/7656668 to your computer and use it in GitHub Desktop.
Fix WF of ftw.task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zope.component.hooks import setSite | |
import transaction | |
from Testing.makerequest import makerequest | |
from AccessControl.SecurityManagement import newSecurityManager | |
user = app.acl_users.getUser('zopemaster') | |
user = user.__of__(app.acl_users) | |
newSecurityManager(app, user) | |
app = makerequest(app) | |
plone = app.get('agg.teamraum.ch').platform | |
setSite(plone) | |
workflow = plone.portal_workflow | |
ACTION_STATE_MAPPING = { | |
'resolve': 'resolved', | |
'activate': 'active', | |
'deactivate': 'inactive', | |
'reactivate': 'active'} | |
for brain in plone.portal_catalog(path='/agg.teamraum.ch/platform/projects'): | |
obj = brain.getObject() | |
history = obj.workflow_history.get('egov_task_workflow') | |
if not history: | |
continue | |
last_entry = history[-1] | |
last_action = last_entry['action'] | |
if last_action not in ACTION_STATE_MAPPING: | |
new_state = 'inactive' | |
else: | |
new_state = ACTION_STATE_MAPPING[last_action] | |
print "*" * 20 | |
print "FIX: %s" % brain.getPath() | |
print "last action: %s " % last_action | |
print "current state: %s" % brain.review_state | |
print "new state: %s" % new_state | |
if brain.review_state == new_state: | |
print "DO NOTHING" | |
continue | |
print "Setting new state to %s" % new_state | |
from copy import copy | |
new_history = copy(obj.workflow_history.data) | |
new_history['egov_task_workflow'][-1]['review_state'] = new_state | |
obj.workflow_history.data = new_history | |
workflows = workflow.getWorkflowsFor(obj) | |
workflows[0].updateRoleMappingsFor(obj) | |
plone.portal_catalog.catalog_object(obj, idxs=['getId'], update_metadata=True) | |
print "*" * 20 | |
# import pdb;pdb.set_trace() | |
transaction.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfekt. Merssi!