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 @@
</value>
</item>
<item>
<key> <string>variable_default_value</string> </key>
<key> <string>variable_default_expression</string> </key>
<value> <string>here/getPortalType</string> </value>
</item>
</dictionary>
......
......@@ -84,7 +84,6 @@
<value>
<list>
<string>my_causality</string>
<string>my_variable_default_value</string>
<string>my_variable_default_expression</string>
</list>
</value>
......
......@@ -227,6 +227,10 @@
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string>text</string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
......@@ -237,7 +241,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Expression (Override Default Value if Set)</string> </value>
<value> <string>Expression</string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
......
......@@ -87,7 +87,7 @@
<string>Causality</string>
</tuple>
<tuple>
<string>WorkflowVariable_getNonEvaluatedVariableDefault</string>
<string>variable_default_expression</string>
<string>Value</string>
</tuple>
</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 @@
<string>my_for_catalog</string>
<string>my_status_included</string>
<string>my_automatic_update</string>
<string>my_variable_default_value</string>
<string>my_variable_default_expression</string>
</list>
</value>
......
......@@ -87,7 +87,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Default Expression (Overrides Default Value)</string> </value>
<value> <string>Default Expression</string> </value>
</item>
</dictionary>
</value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="StringField" module="Products.Formulator.StandardFields"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_variable_default_value</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>too_long</string> </key>
<value> <string>Too much input was given.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_maxwidth</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>50</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>input_type</string> </key>
<value> <string>text</string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Default Value</string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -81,7 +81,7 @@
<list>
<string>listbox_for_catalog</string>
<string>listbox_automatic_update</string>
<string>listbox_title</string>
<string>listbox_variable_default_expression</string>
<string>listbox_reference</string>
</list>
</value>
......
......@@ -90,8 +90,8 @@
<string>Title</string>
</tuple>
<tuple>
<string>WorkflowVariable_getNonEvaluatedVariableDefault</string>
<string>Default Value</string>
<string>variable_default_expression</string>
<string>Default Expression</string>
</tuple>
<tuple>
<string>automatic_update</string>
......@@ -114,14 +114,14 @@
<key> <string>editable_columns</string> </key>
<value>
<list>
<tuple>
<string>title</string>
<string>Title</string>
</tuple>
<tuple>
<string>reference</string>
<string>Reference</string>
</tuple>
<tuple>
<string>variable_default_expression</string>
<string>Default Expression</string>
</tuple>
<tuple>
<string>automatic_update</string>
<string>Update on every Transition</string>
......
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_title</string> </value>
<value> <string>listbox_variable_default_expression</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......@@ -249,7 +249,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>listbox_title</string> </value>
<value> <string>Default Expression</string> </value>
</item>
<item>
<key> <string>truncate</string> </key>
......
......@@ -39,8 +39,8 @@
</value>
</item>
<item>
<key> <string>variable_default_value</string> </key>
<value> <string>edit</string> </value>
<key> <string>variable_default_expression</string> </key>
<value> <string>python: \'edit\'</string> </value>
</item>
</dictionary>
</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):
ec = createExpressionContext(StateChangeInfo(ob, self, status))
value = variable_default_expression(ec)
else:
value = vdef.getVariableDefaultValue()
value = ''
return value
......@@ -250,6 +250,7 @@ class InteractionWorkflow(Workflow):
if not vdef.getStatusIncluded():
continue
expression = None
value = ''
if not vdef.getAutomaticUpdate() and id_ in former_status:
# Preserve former value
value = former_status[id_]
......@@ -257,18 +258,16 @@ class InteractionWorkflow(Workflow):
variable_default_expression = vdef.getVariableDefaultExpression()
if variable_default_expression is not None:
expression = variable_default_expression
else:
value = vdef.getVariableDefaultValue()
if expression is not None:
# Evaluate an expression.
if econtext is None:
# Lazily create the expression context.
if sci is None:
sci = StateChangeInfo(
ob, self, former_status, tdef,
None, None, None)
econtext = createExpressionContext(sci)
value = expression(econtext)
if expression is not None:
# Evaluate an expression.
if econtext is None:
# Lazily create the expression context.
if sci is None:
sci = StateChangeInfo(
ob, self, former_status, tdef,
None, None, None)
econtext = createExpressionContext(sci)
value = expression(econtext)
status[id_] = value
sci = StateChangeInfo(
......@@ -436,7 +435,7 @@ class InteractionWorkflow(Workflow):
# 2. Variable as XML
variable_reference_list = []
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 vdef in variable_list:
variable_reference_list.append(vdef.getReference())
......@@ -449,9 +448,6 @@ class InteractionWorkflow(Workflow):
if property_id == 'automatic_update':
property_value = vdef.getAutomaticUpdate()
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:
property_value = vdef.getProperty(property_id)
property_type = vdef.getPropertyType(property_id)
......
......@@ -572,7 +572,7 @@ class Workflow(XMLObject):
ec = createExpressionContext(StateChangeInfo(ob, self, status))
value = variable_default_expression(ec)
else:
value = vdef.getVariableDefaultValue()
value = ''
return value
......@@ -856,9 +856,7 @@ class Workflow(XMLObject):
else:
expr = variable_default_expression
else:
if object_context is None:
object_context = self.getStateChangeInformation(ob, self.getSourceValue())
value = vdef.getVariableDefaultValue(object=object_context)
value = ''
if expr not in (None, ''):
# Evaluate an expression.
......@@ -1091,7 +1089,7 @@ class Workflow(XMLObject):
# 3. Variable as XML
variable_reference_list = []
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 vdef in variable_list:
variable_reference_list.append(vdef.getReference())
......@@ -1104,9 +1102,6 @@ class Workflow(XMLObject):
if property_id == 'automatic_update':
property_value = vdef.getAutomaticUpdate()
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:
property_value = vdef.getProperty(property_id)
property_type = vdef.getPropertyType(property_id)
......@@ -1246,7 +1241,7 @@ class Workflow(XMLObject):
if variable_default_expression is not None:
expr = variable_default_expression
else:
value = vdef.getVariableDefaultValue()
value = ''
if expr is not None:
# Evaluate an expression.
if econtext is None:
......@@ -1290,7 +1285,7 @@ class Workflow(XMLObject):
# convert string to expression before execute it.
value = variable_default_expression(ec)
else:
value = variable.getVariableDefaultValue()
value = ''
res[variable_id] = value
......
......@@ -1131,6 +1131,13 @@ def convertToERP5Workflow(self, temp_object=False):
variable.setVariableDefaultExpression('transition/getReference|nothing')
else:
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:
variable.info_guard = variable_definition.info_guard
variable.setGuardRoleList(variable_definition.info_guard.roles)
......@@ -1141,12 +1148,6 @@ def convertToERP5Workflow(self, temp_object=False):
variable.setGuardExpression(tdef.info_guard.expr.text)
variable.setForCatalog(variable_definition.for_catalog)
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)
# Configure transition variable:
if getattr(self, 'transitions', None) is not None:
......@@ -1266,7 +1267,6 @@ VariableDefinition.getId = method_getId
VariableDefinition.getTitle = method_getTitle
VariableDefinition.getDescription = method_getDescription
VariableDefinition.getVariableDefaultExpression = lambda self: self.var_expr
VariableDefinition.getVariableDefaultValue = lambda self: self.default_value
VariableDefinition.checkGuard = method_checkGuard
VariableDefinition.showDict = DCWorkflowDefinition_showDict
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