Commit 0efd1e02 authored by Romain Courteaud's avatar Romain Courteaud

Bug fix: warn when trying to generate a workflow method with the same id of a

property.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5552 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5833f7d3
...@@ -208,102 +208,111 @@ def initializePortalTypeDynamicProperties(self, klass, ptype): ...@@ -208,102 +208,111 @@ def initializePortalTypeDynamicProperties(self, klass, ptype):
from Utils import initializeDefaultProperties from Utils import initializeDefaultProperties
initializeDefaultProperties([prop_holder], object=self) initializeDefaultProperties([prop_holder], object=self)
#LOG('initializeDefaultProperties: %s' % ptype, 0, str(prop_holder.__dict__)) #LOG('initializeDefaultProperties: %s' % ptype, 0, str(prop_holder.__dict__))
# We should now make sure workflow methods are defined # initializePortalTypeDynamicWorkflowMethods(self,
# and also make sure simulation state is defined initializePortalTypeDynamicWorkflowMethods(self, klass, prop_holder)
portal_workflow = getToolByName(self, 'portal_workflow') # We can now associate it after initialising security
#LOG('getWorkflowsFor', 0, str((self, [wf.id for wf in portal_workflow.getWorkflowsFor(self)]))) InitializeClass(prop_holder)
for wf in portal_workflow.getWorkflowsFor(self): prop_holder.__propholder__ = prop_holder
wf_id = wf.id # For now, this line below is commented, because this breaks
#LOG('in aq_portal_type %s' % id, 0, "found state workflow %s" % wf.id) # _aq_dynamic without JP's patch to Zope for an unknown reason.
if wf.__class__.__name__ in ('DCWorkflowDefinition', ): #klass.__ac_permissions__ = prop_holder.__ac_permissions__
# Create state var accessor Base.aq_portal_type[ptype] = prop_holder
state_var = wf.variables.getStateVar()
method_id = 'get%s' % UpperCase(state_var) def initializePortalTypeDynamicWorkflowMethods(self, klass, prop_holder):
if not hasattr(prop_holder, method_id): # We should now make sure workflow methods are defined
method = WorkflowState.Getter(method_id, wf_id) # and also make sure simulation state is defined
setattr(prop_holder, method_id, method) # Attach to portal_type portal_workflow = getToolByName(self, 'portal_workflow')
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id ) # LOG('getWorkflowsFor', 0,
method_id = 'get%sTitle' % UpperCase(state_var) # str((self, [wf.id for wf in portal_workflow.getWorkflowsFor(self)])))
if not hasattr(prop_holder, method_id): for wf in portal_workflow.getWorkflowsFor(self):
method = WorkflowState.TitleGetter(method_id, wf_id) # LOG('in aq_portal_type %s' % id, 0,
setattr(prop_holder, method_id, method) # Attach to portal_type # "found state workflow %s" % wf.id)
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id ) if wf.__class__.__name__ in ('DCWorkflowDefinition', ):
#LOG('in aq_portal_type %s' % id, 0, "added state method %s" % method_id)
#LOG('in aq_portal_type %s' % id, 0, "found transition workflow %s" % wf.id)
# Generate methods that support the translation of workflow states
for wf in portal_workflow.getWorkflowsFor(self):
wf_id = wf.id wf_id = wf.id
if wf.__class__.__name__ in ('DCWorkflowDefinition', ): # Create state var accessor
# Create state var accessor # and generate methods that support the translation of workflow states
state_var = wf.variables.getStateVar() state_var = wf.variables.getStateVar()
method_id = 'getTranslated%s' % UpperCase(state_var) for method_id, getter in (
if not hasattr(prop_holder, method_id): ('get%s' % UpperCase(state_var), WorkflowState.Getter),
method = WorkflowState.TranslatedGetter(method_id, wf_id) ('get%sTitle' % UpperCase(state_var), WorkflowState.TitleGetter),
setattr(prop_holder, method_id, method) # Attach to portal_type ('getTranslated%s' % UpperCase(state_var),
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id ) WorkflowState.TranslatedGetter),
method_id = 'getTranslated%sTitle' % UpperCase(state_var) ('getTranslated%sTitle' % UpperCase(state_var),
WorkflowState.TranslatedTitleGetter)):
if not hasattr(prop_holder, method_id): if not hasattr(prop_holder, method_id):
method = WorkflowState.TranslatedTitleGetter(method_id, wf_id) method = getter(method_id, wf_id)
setattr(prop_holder, method_id, method) # Attach to portal_type # Attach to portal_type
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id ) setattr(prop_holder, method_id, method)
if wf.__class__.__name__ in ('DCWorkflowDefinition', ): prop_holder.security.declareProtected(
for tr_id in wf.transitions.objectIds(): Permissions.AccessContentsInformation,
tdef = wf.transitions.get(tr_id, None) method_id )
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD: for wf in portal_workflow.getWorkflowsFor(self):
method_id = convertToMixedCase(tr_id) wf_id = wf.id
# We have to make a difference between a method which is on if wf.__class__.__name__ in ('DCWorkflowDefinition', ):
# the prop_holder or on the klass, if the method is on the for tr_id in wf.transitions.objectIds():
# klass, then the WorkflowMethod created also need to be on the klass tdef = wf.transitions.get(tr_id, None)
if not hasattr(prop_holder, method_id) and not hasattr(klass,method_id): if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD:
method = WorkflowMethod(klass._doNothing, tr_id) method_id = convertToMixedCase(tr_id)
setattr(prop_holder, method_id, method) # Attach to portal_type # We have to make a difference between a method which is on
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id ) # the prop_holder or on the klass, if the method is on the
#LOG('in aq_portal_type %s' % id, 0, "added transition method %s" % method_id) # klass, then the WorkflowMethod created also need to be on the klass
if (not hasattr(prop_holder, method_id)) and \
(not hasattr(klass, method_id)):
method = WorkflowMethod(klass._doNothing, tr_id)
# Attach to portal_type
setattr(prop_holder, method_id, method)
prop_holder.security.declareProtected(
Permissions.AccessContentsInformation,
method_id )
# LOG('in aq_portal_type %s' % id, 0,
# "added transition method %s" % method_id)
else:
# Wrap method into WorkflowMethod is needed
try:
method = getattr(klass, method_id)
except AttributeError:
method = getattr(prop_holder, method_id)
work_method_holder = prop_holder
else:
work_method_holder = klass
# Wrap method
if callable(method):
if not isinstance(method, WorkflowMethod):
setattr(work_method_holder, method_id,
WorkflowMethod(method, method_id))
else:
LOG('initializePortalTypeDynamicWorkflowMethods', 100,
'WARNING! Can not initialize %s on %s' % \
(method_id, str(work_method_holder)))
# XXX This part is (more or less...) a copy and paste
elif wf.__class__.__name__ in ('InteractionWorkflowDefinition', ):
for tr_id in wf.interactions.objectIds():
tdef = wf.interactions.get(tr_id, None)
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD:
for imethod_id in tdef.method_id:
method_id = imethod_id
if (not hasattr(prop_holder, method_id)) and \
(not hasattr(klass,method_id)):
method = WorkflowMethod(klass._doNothing, imethod_id)
# Attach to portal_type
setattr(prop_holder, method_id, method)
prop_holder.security.declareProtected(
Permissions.AccessContentsInformation,
method_id)
else: else:
# Wrap method into WorkflowMethod is needed # Wrap method into WorkflowMethod is needed
if getattr(klass,method_id,None) is not None: if getattr(klass,method_id,None) is not None:
method = getattr(klass, method_id) method = getattr(klass, method_id)
if callable(method): if callable(method):
if not isinstance(method, WorkflowMethod): if not isinstance(method, WorkflowMethod):
setattr(klass, method_id, WorkflowMethod(method, method_id)) method = WorkflowMethod(method, method_id)
setattr(klass, method_id, method)
else: else:
method = getattr(prop_holder, method_id) method = getattr(prop_holder, method_id)
if callable(method): if callable(method):
if not isinstance(method, WorkflowMethod): if not isinstance(method, WorkflowMethod):
setattr(prop_holder, method_id, WorkflowMethod(method, method_id)) method = WorkflowMethod(method, method_id)
elif wf.__class__.__name__ in ('InteractionWorkflowDefinition', ): setattr(prop_holder, method_id, method)
for tr_id in wf.interactions.objectIds():
tdef = wf.interactions.get(tr_id, None)
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD:
for imethod_id in tdef.method_id:
method_id = imethod_id
if not hasattr(prop_holder, method_id) and not hasattr(klass,method_id):
method = WorkflowMethod(klass._doNothing, imethod_id)
setattr(prop_holder, method_id, method) # Attach to portal_type
prop_holder.security.declareProtected( Permissions.AccessContentsInformation, method_id )
else:
# Wrap method into WorkflowMethod is needed
if getattr(klass,method_id,None) is not None:
method = getattr(klass, method_id)
if callable(method):
if not isinstance(method, WorkflowMethod):
method = WorkflowMethod(method, method_id)
setattr(klass, method_id, method)
else:
method = getattr(prop_holder, method_id)
if callable(method):
if not isinstance(method, WorkflowMethod):
method = WorkflowMethod(method, method_id)
setattr(prop_holder, method_id, method)
# We can now associate it after initialising security
InitializeClass(prop_holder)
prop_holder.__propholder__ = prop_holder
# For now, this line below is commented, because this breaks
# _aq_dynamic without JP's patch to Zope for an unknown reason.
#klass.__ac_permissions__ = prop_holder.__ac_permissions__
Base.aq_portal_type[ptype] = prop_holder
class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment