Commit 57fcbcec authored by Arnaud Fontaine's avatar Arnaud Fontaine

ERP5Workflow: Remove unused variable_default_value and use...

ERP5Workflow: Remove unused variable_default_value and use variable_default_expression instead (!1378).
parent d3648027
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
</value> </value>
</item> </item>
<item> <item>
<key> <string>variable_default_value</string> </key> <key> <string>variable_default_expression</string> </key>
<value> <string>here/getPortalType</string> </value> <value> <string>here/getPortalType</string> </value>
</item> </item>
</dictionary> </dictionary>
......
...@@ -84,7 +84,6 @@ ...@@ -84,7 +84,6 @@
<value> <value>
<list> <list>
<string>my_causality</string> <string>my_causality</string>
<string>my_variable_default_value</string>
<string>my_variable_default_expression</string> <string>my_variable_default_expression</string>
</list> </list>
</value> </value>
......
...@@ -227,6 +227,10 @@ ...@@ -227,6 +227,10 @@
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <int>0</int> </value> <value> <int>0</int> </value>
</item> </item>
<item>
<key> <string>input_type</string> </key>
<value> <string>text</string> </value>
</item>
<item> <item>
<key> <string>max_length</string> </key> <key> <string>max_length</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -237,7 +241,7 @@ ...@@ -237,7 +241,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Expression (Override Default Value if Set)</string> </value> <value> <string>Expression</string> </value>
</item> </item>
<item> <item>
<key> <string>truncate</string> </key> <key> <string>truncate</string> </key>
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
<string>Causality</string> <string>Causality</string>
</tuple> </tuple>
<tuple> <tuple>
<string>WorkflowVariable_getNonEvaluatedVariableDefault</string> <string>variable_default_expression</string>
<string>Value</string> <string>Value</string>
</tuple> </tuple>
</list> </list>
......
default_value = context.getVariableDefaultExpression(evaluate=0)
if default_value is None:
# variable_default_expression takes precedence over "static" variable_default_value property
default_value = repr(context.getVariableDefaultValue())
return default_value
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WorkflowVariable_getNonEvaluatedVariableDefault</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -91,7 +91,6 @@ ...@@ -91,7 +91,6 @@
<string>my_for_catalog</string> <string>my_for_catalog</string>
<string>my_status_included</string> <string>my_status_included</string>
<string>my_automatic_update</string> <string>my_automatic_update</string>
<string>my_variable_default_value</string>
<string>my_variable_default_expression</string> <string>my_variable_default_expression</string>
</list> </list>
</value> </value>
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Default Expression (Overrides Default Value)</string> </value> <value> <string>Default Expression</string> </value>
</item> </item>
</dictionary> </dictionary>
</value> </value>
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<list> <list>
<string>listbox_for_catalog</string> <string>listbox_for_catalog</string>
<string>listbox_automatic_update</string> <string>listbox_automatic_update</string>
<string>listbox_title</string> <string>listbox_variable_default_expression</string>
<string>listbox_reference</string> <string>listbox_reference</string>
</list> </list>
</value> </value>
......
...@@ -90,8 +90,8 @@ ...@@ -90,8 +90,8 @@
<string>Title</string> <string>Title</string>
</tuple> </tuple>
<tuple> <tuple>
<string>WorkflowVariable_getNonEvaluatedVariableDefault</string> <string>variable_default_expression</string>
<string>Default Value</string> <string>Default Expression</string>
</tuple> </tuple>
<tuple> <tuple>
<string>automatic_update</string> <string>automatic_update</string>
...@@ -114,14 +114,14 @@ ...@@ -114,14 +114,14 @@
<key> <string>editable_columns</string> </key> <key> <string>editable_columns</string> </key>
<value> <value>
<list> <list>
<tuple>
<string>title</string>
<string>Title</string>
</tuple>
<tuple> <tuple>
<string>reference</string> <string>reference</string>
<string>Reference</string> <string>Reference</string>
</tuple> </tuple>
<tuple>
<string>variable_default_expression</string>
<string>Default Expression</string>
</tuple>
<tuple> <tuple>
<string>automatic_update</string> <string>automatic_update</string>
<string>Update on every Transition</string> <string>Update on every Transition</string>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>listbox_title</string> </value> <value> <string>listbox_variable_default_expression</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>listbox_title</string> </value> <value> <string>Default Expression</string> </value>
</item> </item>
<item> <item>
<key> <string>truncate</string> </key> <key> <string>truncate</string> </key>
......
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
</value> </value>
</item> </item>
<item> <item>
<key> <string>variable_default_value</string> </key> <key> <string>variable_default_expression</string> </key>
<value> <string>edit</string> </value> <value> <string>python: \'edit\'</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Defines the default value (default_expression property takes precedence).</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variable_default_value_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: \'\'</string> </value>
</item>
<item>
<key> <string>storage_id</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -125,7 +125,7 @@ class InteractionWorkflow(Workflow): ...@@ -125,7 +125,7 @@ class InteractionWorkflow(Workflow):
ec = createExpressionContext(StateChangeInfo(ob, self, status)) ec = createExpressionContext(StateChangeInfo(ob, self, status))
value = variable_default_expression(ec) value = variable_default_expression(ec)
else: else:
value = vdef.getVariableDefaultValue() value = ''
return value return value
...@@ -250,6 +250,7 @@ class InteractionWorkflow(Workflow): ...@@ -250,6 +250,7 @@ class InteractionWorkflow(Workflow):
if not vdef.getStatusIncluded(): if not vdef.getStatusIncluded():
continue continue
expression = None expression = None
value = ''
if not vdef.getAutomaticUpdate() and id_ in former_status: if not vdef.getAutomaticUpdate() and id_ in former_status:
# Preserve former value # Preserve former value
value = former_status[id_] value = former_status[id_]
...@@ -257,18 +258,16 @@ class InteractionWorkflow(Workflow): ...@@ -257,18 +258,16 @@ class InteractionWorkflow(Workflow):
variable_default_expression = vdef.getVariableDefaultExpression() variable_default_expression = vdef.getVariableDefaultExpression()
if variable_default_expression is not None: if variable_default_expression is not None:
expression = variable_default_expression expression = variable_default_expression
else: if expression is not None:
value = vdef.getVariableDefaultValue() # Evaluate an expression.
if expression is not None: if econtext is None:
# Evaluate an expression. # Lazily create the expression context.
if econtext is None: if sci is None:
# Lazily create the expression context. sci = StateChangeInfo(
if sci is None: ob, self, former_status, tdef,
sci = StateChangeInfo( None, None, None)
ob, self, former_status, tdef, econtext = createExpressionContext(sci)
None, None, None) value = expression(econtext)
econtext = createExpressionContext(sci)
value = expression(econtext)
status[id_] = value status[id_] = value
sci = StateChangeInfo( sci = StateChangeInfo(
...@@ -436,7 +435,7 @@ class InteractionWorkflow(Workflow): ...@@ -436,7 +435,7 @@ class InteractionWorkflow(Workflow):
# 2. Variable as XML # 2. Variable as XML
variable_reference_list = [] variable_reference_list = []
variable_list = self.objectValues(portal_type='Workflow Variable') variable_list = self.objectValues(portal_type='Workflow Variable')
variable_prop_id_to_show = ['description', 'variable_default_value', 'variable_default_expression', variable_prop_id_to_show = ['description', 'variable_default_expression',
'for_catalog', 'for_status', 'automatic_update'] 'for_catalog', 'for_status', 'automatic_update']
for vdef in variable_list: for vdef in variable_list:
variable_reference_list.append(vdef.getReference()) variable_reference_list.append(vdef.getReference())
...@@ -449,9 +448,6 @@ class InteractionWorkflow(Workflow): ...@@ -449,9 +448,6 @@ class InteractionWorkflow(Workflow):
if property_id == 'automatic_update': if property_id == 'automatic_update':
property_value = vdef.getAutomaticUpdate() property_value = vdef.getAutomaticUpdate()
sub_object = SubElement(variable, property_id, attrib=dict(type='int')) sub_object = SubElement(variable, property_id, attrib=dict(type='int'))
elif property_id == 'variable_default_value':
property_value = vdef.getVariableDefaultValue()
sub_object = SubElement(variable, property_id, attrib=dict(type='string'))
else: else:
property_value = vdef.getProperty(property_id) property_value = vdef.getProperty(property_id)
property_type = vdef.getPropertyType(property_id) property_type = vdef.getPropertyType(property_id)
......
...@@ -572,7 +572,7 @@ class Workflow(XMLObject): ...@@ -572,7 +572,7 @@ class Workflow(XMLObject):
ec = createExpressionContext(StateChangeInfo(ob, self, status)) ec = createExpressionContext(StateChangeInfo(ob, self, status))
value = variable_default_expression(ec) value = variable_default_expression(ec)
else: else:
value = vdef.getVariableDefaultValue() value = ''
return value return value
...@@ -856,9 +856,7 @@ class Workflow(XMLObject): ...@@ -856,9 +856,7 @@ class Workflow(XMLObject):
else: else:
expr = variable_default_expression expr = variable_default_expression
else: else:
if object_context is None: value = ''
object_context = self.getStateChangeInformation(ob, self.getSourceValue())
value = vdef.getVariableDefaultValue(object=object_context)
if expr not in (None, ''): if expr not in (None, ''):
# Evaluate an expression. # Evaluate an expression.
...@@ -1091,7 +1089,7 @@ class Workflow(XMLObject): ...@@ -1091,7 +1089,7 @@ class Workflow(XMLObject):
# 3. Variable as XML # 3. Variable as XML
variable_reference_list = [] variable_reference_list = []
variable_list = self.getVariableValueList() variable_list = self.getVariableValueList()
variable_prop_id_to_show = ['description', 'variable_default_value', 'variable_default_expression', variable_prop_id_to_show = ['description', 'variable_default_expression',
'for_catalog', 'for_status', 'automatic_update'] 'for_catalog', 'for_status', 'automatic_update']
for vdef in variable_list: for vdef in variable_list:
variable_reference_list.append(vdef.getReference()) variable_reference_list.append(vdef.getReference())
...@@ -1104,9 +1102,6 @@ class Workflow(XMLObject): ...@@ -1104,9 +1102,6 @@ class Workflow(XMLObject):
if property_id == 'automatic_update': if property_id == 'automatic_update':
property_value = vdef.getAutomaticUpdate() property_value = vdef.getAutomaticUpdate()
sub_object = SubElement(variable, property_id, attrib=dict(type='int')) sub_object = SubElement(variable, property_id, attrib=dict(type='int'))
elif property_id == 'variable_default_value':
property_value = vdef.getVariableDefaultValue()
sub_object = SubElement(variable, property_id, attrib=dict(type='string'))
else: else:
property_value = vdef.getProperty(property_id) property_value = vdef.getProperty(property_id)
property_type = vdef.getPropertyType(property_id) property_type = vdef.getPropertyType(property_id)
...@@ -1246,7 +1241,7 @@ class Workflow(XMLObject): ...@@ -1246,7 +1241,7 @@ class Workflow(XMLObject):
if variable_default_expression is not None: if variable_default_expression is not None:
expr = variable_default_expression expr = variable_default_expression
else: else:
value = vdef.getVariableDefaultValue() value = ''
if expr is not None: if expr is not None:
# Evaluate an expression. # Evaluate an expression.
if econtext is None: if econtext is None:
...@@ -1290,7 +1285,7 @@ class Workflow(XMLObject): ...@@ -1290,7 +1285,7 @@ class Workflow(XMLObject):
# convert string to expression before execute it. # convert string to expression before execute it.
value = variable_default_expression(ec) value = variable_default_expression(ec)
else: else:
value = variable.getVariableDefaultValue() value = ''
res[variable_id] = value res[variable_id] = value
......
...@@ -1131,6 +1131,13 @@ def convertToERP5Workflow(self, temp_object=False): ...@@ -1131,6 +1131,13 @@ def convertToERP5Workflow(self, temp_object=False):
variable.setVariableDefaultExpression('transition/getReference|nothing') variable.setVariableDefaultExpression('transition/getReference|nothing')
else: else:
variable.setVariableDefaultExpression(variable_definition.default_expr.text) variable.setVariableDefaultExpression(variable_definition.default_expr.text)
# default_expr has precedence over default_value if defined...
elif variable_definition.default_value:
if '/' not in variable_definition.default_value:
default_value = "python: '%s'" % variable_definition.default_value
else:
default_value = variable_definition.default_value
variable.setVariableDefaultExpression(default_value)
if variable_definition.info_guard: if variable_definition.info_guard:
variable.info_guard = variable_definition.info_guard variable.info_guard = variable_definition.info_guard
variable.setGuardRoleList(variable_definition.info_guard.roles) variable.setGuardRoleList(variable_definition.info_guard.roles)
...@@ -1141,12 +1148,6 @@ def convertToERP5Workflow(self, temp_object=False): ...@@ -1141,12 +1148,6 @@ def convertToERP5Workflow(self, temp_object=False):
variable.setGuardExpression(tdef.info_guard.expr.text) variable.setGuardExpression(tdef.info_guard.expr.text)
variable.setForCatalog(variable_definition.for_catalog) variable.setForCatalog(variable_definition.for_catalog)
variable.setStatusIncluded(variable_definition.for_status) variable.setStatusIncluded(variable_definition.for_status)
# setVariableValue sets the value to None if the parameter is an empty
# string. This change the expected behaviour.
# XXX(WORKFLOW): you need to be aware that if someone saves a variable
# without editing this field, variable_value may be None again
if variable_definition.default_value:
variable.setVariableDefaultValue(variable_definition.default_value)
variable.setDescription(variable_definition.description) variable.setDescription(variable_definition.description)
# Configure transition variable: # Configure transition variable:
if getattr(self, 'transitions', None) is not None: if getattr(self, 'transitions', None) is not None:
...@@ -1266,7 +1267,6 @@ VariableDefinition.getId = method_getId ...@@ -1266,7 +1267,6 @@ VariableDefinition.getId = method_getId
VariableDefinition.getTitle = method_getTitle VariableDefinition.getTitle = method_getTitle
VariableDefinition.getDescription = method_getDescription VariableDefinition.getDescription = method_getDescription
VariableDefinition.getVariableDefaultExpression = lambda self: self.var_expr VariableDefinition.getVariableDefaultExpression = lambda self: self.var_expr
VariableDefinition.getVariableDefaultValue = lambda self: self.default_value
VariableDefinition.checkGuard = method_checkGuard VariableDefinition.checkGuard = method_checkGuard
VariableDefinition.showDict = DCWorkflowDefinition_showDict VariableDefinition.showDict = DCWorkflowDefinition_showDict
VariableDefinition.getStatusIncluded = lambda self: self.for_status VariableDefinition.getStatusIncluded = lambda self: self.for_status
......
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