Commit 755f7616 authored by wenjie.zheng's avatar wenjie.zheng

Base.py and WorkflowState.py: Regenerate erp5workflow state accessor which...

Base.py and WorkflowState.py: Regenerate erp5workflow state accessor which override base categories accessor.
parent e136b3cd
...@@ -1288,7 +1288,7 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -1288,7 +1288,7 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
""" """
module = self.portal.person_module module = self.portal.person_module
person = module.newContent(portal_type='Person') person = module.newContent(portal_type='Person')
self.assertEqual(person.getValidationStateId(), 'draft') self.assertEqual(person.getValidationState(), 'draft')
self.assertFalse(self.portal.portal_workflow.isTransitionPossible(person, self.assertFalse(self.portal.portal_workflow.isTransitionPossible(person,
'invalidate')) 'invalidate'))
# test low-level implementation # test low-level implementation
......
...@@ -60,6 +60,32 @@ class Getter(BaseGetter): ...@@ -60,6 +60,32 @@ class Getter(BaseGetter):
psyco.bind(__call__) psyco.bind(__call__)
class ERP5WorkflowStateGetter(BaseGetter):
"""
Gets an attribute value. A default value can be
provided if needed
"""
_need__name__=1
# Generic Definition of Method Object
# This is required to call the method form the Web
func_code = func_code()
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
def __init__(self, id, key):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance):
erp5Workflow_module = instance.getPortalObject()._getOb("workflow_module", None)
wf = erp5Workflow_module._getOb(self._key)
return instance._getDefaultAcquiredValue(wf.getStateBaseCategory()).getId()
psyco.bind(__call__)
class TitleGetter(BaseGetter): class TitleGetter(BaseGetter):
""" """
Gets the title of the current state Gets the title of the current state
...@@ -85,6 +111,31 @@ class TitleGetter(BaseGetter): ...@@ -85,6 +111,31 @@ class TitleGetter(BaseGetter):
psyco.bind(__call__) psyco.bind(__call__)
class ERP5WorkflowStateTitleGetter(BaseGetter):
"""
Gets the title of the current state
"""
_need__name__=1
# Generic Definition of Method Object
# This is required to call the method form the Web
func_code = func_code()
func_code.co_varnames = ('self',)
func_code.co_argcount = 1
func_defaults = ()
def __init__(self, id, key):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance):
erp5Workflow_module = instance.getPortalObject()._getOb("workflow_module", None)
wf = erp5Workflow_module._getOb(self._key)
return instance._getDefaultAcquiredValue(wf.getStateBaseCategory()).getTitle()
psyco.bind(__call__)
class TranslatedGetter(Getter): class TranslatedGetter(Getter):
""" returns the workflow state ID transated. DEPRECATED """ returns the workflow state ID transated. DEPRECATED
""" """
...@@ -99,6 +150,21 @@ class TranslatedGetter(Getter): ...@@ -99,6 +150,21 @@ class TranslatedGetter(Getter):
psyco.bind(__call__) psyco.bind(__call__)
class ERP5WorkflowStateTranslatedGetter(Getter):
""" returns the workflow state ID transated. DEPRECATED
"""
def __call__(self, instance):
portal = instance.getPortalObject()
erp5Workflow_module = instance.getPortalObject()._getOb("workflow_module", None)
wf = erp5Workflow_module._getOb(self._key)
state_id = instance._getDefaultAcquiredValue(wf.getStateBaseCategory()).getId()
warn('Translated workflow state getters, such as %s are deprecated' %
self._id, DeprecationWarning)
return portal.Localizer.erp5_ui.gettext(state_id).encode('utf8')
psyco.bind(__call__)
class TranslatedTitleGetter(TitleGetter): class TranslatedTitleGetter(TitleGetter):
""" """
Gets the translated title of the current state Gets the translated title of the current state
...@@ -122,6 +188,30 @@ class TranslatedTitleGetter(TitleGetter): ...@@ -122,6 +188,30 @@ class TranslatedTitleGetter(TitleGetter):
psyco.bind(__call__) psyco.bind(__call__)
class ERP5WorkflowStateTranslatedTitleGetter(TitleGetter):
"""
Gets the translated title of the current state
"""
def __call__(self, instance):
portal = instance.getPortalObject()
localizer = portal.Localizer
wf_id = self._key
erp5Workflow_module = instance.getPortalObject()._getOb("workflow_module", None)
wf = erp5Workflow_module._getOb(self._key)
selected_language = localizer.get_selected_language()
state_title = instance._getDefaultAcquiredValue(wf.getStateBaseCategory()).getTitle()
msg_id = '%s [state in %s]' % (state_title, wf_id)
result = localizer.erp5_ui.gettext(msg_id,
lang=selected_language,
default='')
if result == '':
result = localizer.erp5_ui.gettext(state_title,
lang=selected_language)
return result.encode('utf8')
psyco.bind(__call__)
def SerializeGetter(id, key): def SerializeGetter(id, key):
def serialize(self): def serialize(self):
"""Prevent concurrent transaction from changing of state of this object """Prevent concurrent transaction from changing of state of this object
...@@ -134,3 +224,16 @@ def SerializeGetter(id, key): ...@@ -134,3 +224,16 @@ def SerializeGetter(id, key):
self._p_changed = 1 self._p_changed = 1
serialize.__name__ = id serialize.__name__ = id
return serialize return serialize
def ERP5WorkflowStateSerializeGetter(id, key):### same as SerializeGetter for the moment
def serialize(self):
"""Prevent concurrent transaction from changing of state of this object
"""
try:
self = aq_base(self).workflow_history
self = self[key]
except (AttributeError, KeyError):
pass
self._p_changed = 1
serialize.__name__ = id
return serialize
...@@ -630,13 +630,35 @@ def intializePortalTypeERP5WorkflowMethod(ptype_klass, portal_ERP5Workflow): ...@@ -630,13 +630,35 @@ def intializePortalTypeERP5WorkflowMethod(ptype_klass, portal_ERP5Workflow):
wf5_module = aq_inner(portal_ERP5Workflow) wf5_module = aq_inner(portal_ERP5Workflow)
portal_type = portal_ERP5Workflow.getPortalObject().getDefaultModule(portal_type="portal_types") portal_type = portal_ERP5Workflow.getPortalObject().getDefaultModule(portal_type="portal_types")
pt = portal_type._getOb(ptype_klass.__name__, None) pt = portal_type._getOb(ptype_klass.__name__, None)
for ERP5Workflow in pt.erp5workflow_list:
for tr in wf5_module._getOb(ERP5Workflow).objectValues(portal_type="Transition"): for ERP5Workflow_id in pt.erp5workflow_list:
ERP5Workflow = wf5_module._getOb(ERP5Workflow_id)
state_var = ERP5Workflow.getStateBaseCategory()
### zwj: generate erp5worflow state var accessor, override base category accessor
for method_id, getter in (
('get%s' % UpperCase(state_var), WorkflowState.ERP5WorkflowStateGetter),
('get%sTitle' % UpperCase(state_var), WorkflowState.ERP5WorkflowStateTitleGetter),
('getTranslated%s' % UpperCase(state_var),
WorkflowState.ERP5WorkflowStateTranslatedGetter),
('getTranslated%sTitle' % UpperCase(state_var),
WorkflowState.ERP5WorkflowStateTranslatedTitleGetter),
('serialize%s' % UpperCase(state_var), WorkflowState.ERP5WorkflowStateSerializeGetter),
):
#if not hasattr(ptype_klass, method_id):
### zwj: shouldn't override the DC accessors or the portal type using DCWorkflow will have problems
method = getter(method_id, ERP5Workflow_id)
# Attach to portal_type
ptype_klass.registerAccessor(method,
Permissions.AccessContentsInformation)
LOG("Register Accessor %s of %s"%(method_id, ERP5Workflow_id), WARNING, "zwj")
### zwj: generate erp5workflow mehtods
for tr in wf5_module._getOb(ERP5Workflow_id).objectValues(portal_type="Transition"):
tr_id = tr.id tr_id = tr.id
method_id = convertToMixedCase(tr_id) method_id = convertToMixedCase(tr_id)
wf_id = ERP5Workflow ptype_klass.registerERP5WorkflowMethod(method_id, ERP5Workflow_id, tr_id, 0)
ptype_klass.registerERP5WorkflowMethod(method_id, wf_id, tr_id, 0) LOG("ERP5Workflow method %s is generated"%tr_id,WARNING," for %s"%ERP5Workflow_id)
LOG("ERP5Workflow method %s is generated"%tr_id,WARNING," for %s"%wf_id)
def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
"""We should now make sure workflow methods are defined """We should now make sure workflow methods are defined
...@@ -669,7 +691,7 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): ...@@ -669,7 +691,7 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
WorkflowState.TranslatedTitleGetter), WorkflowState.TranslatedTitleGetter),
('serialize%s' % UpperCase(state_var), WorkflowState.SerializeGetter), ('serialize%s' % UpperCase(state_var), WorkflowState.SerializeGetter),
): ):
if not hasattr(ptype_klass, method_id): #if not hasattr(ptype_klass, method_id):
method = getter(method_id, wf_id) method = getter(method_id, wf_id)
# Attach to portal_type # Attach to portal_type
ptype_klass.registerAccessor(method, ptype_klass.registerAccessor(method,
......
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