Commit 77037609 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

erp5_core: unify Predicate_edit code into Base_edit.

parent 2419299d
......@@ -35,7 +35,7 @@
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Predicate_edit</string> </value>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>encoding</string> </key>
......
......@@ -35,7 +35,7 @@ import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager, newSecurityManager
from Products.ERP5Type.tests.Sequence import Sequence
REGION_FRANCE_PATH = 'region/europe/western_europe/france'
......@@ -555,11 +555,12 @@ class TestPredicates(TestPredicateMixIn):
predicate = self.createPredicate()
predicate.setCriterionPropertyList(['quantity'])
request = self.portal.REQUEST
request.AUTHENTICATED_USER = getSecurityManager().getUser()
request.set(
'listbox',
{'quantity': {'max': '', 'identity': [], 'min': ''}},
)
predicate.Predicate_edit('Predicate_view')
predicate.Base_edit('Predicate_view')
self.assertEqual(predicate._identity_criterion, {'quantity': []})
self.assertEqual(predicate._range_criterion, {})
self.assertTrue(predicate.test(movement))
......@@ -567,7 +568,7 @@ class TestPredicates(TestPredicateMixIn):
'listbox',
{'quantity': {'max': '', 'identity': [], 'min': 1.0}},
)
predicate.Predicate_edit('Predicate_view')
predicate.Base_edit('Predicate_view')
self.assertEqual(predicate._range_criterion, {'quantity': (1.0, None)})
self.assertFalse(predicate.test(movement.asContext(quantity=0.5)))
self.assertTrue(predicate.test(movement.asContext(quantity=1.0)))
......@@ -575,7 +576,7 @@ class TestPredicates(TestPredicateMixIn):
'listbox',
{'quantity': {'max': 2.0, 'identity': [], 'min': ''}},
)
predicate.Predicate_edit('Predicate_view')
predicate.Base_edit('Predicate_view')
self.assertEqual(predicate._range_criterion, {'quantity': (None, 2.0)})
self.assertFalse(predicate.test(movement.asContext(quantity=2.0)))
self.assertTrue(predicate.test(movement.asContext(quantity=1.5)))
......@@ -583,7 +584,7 @@ class TestPredicates(TestPredicateMixIn):
'listbox',
{'quantity': {'max': 2.0, 'identity': [], 'min': 1.0}},
)
predicate.Predicate_edit('Predicate_view')
predicate.Base_edit('Predicate_view')
self.assertEqual(predicate._range_criterion, {'quantity': (1.0, 2.0)})
self.assertFalse(predicate.test(movement.asContext(quantity=0.5)))
self.assertTrue(predicate.test(movement.asContext(quantity=1.0)))
......
......@@ -62,6 +62,11 @@ def editListBox(listbox_field, listbox):
if listbox is None:
return
if context.isPredicate():
predicate_listbox = set(context.getCriterionPropertyList()) == set(listbox.keys())
else:
predicate_listbox = False # extract hidden (global) attributes from request to be used in listbox's update
# extract hidden (global) attributes from request to be used in listbox's update
global_attr = {hidden_key: getattr(request, hidden_key, None)
for hidden_key, _ in listbox_field.get_value('global_attributes')} \
......@@ -69,6 +74,10 @@ def editListBox(listbox_field, listbox):
else {}
for item_url, item_value in listbox.items():
if predicate_listbox:
item_value.update(global_attr)
context.setCriterion(item_url, **item_value)
continue
item_value.update(global_attr)
# Form: '' -> ERP5: None
editor_list = []
......
......@@ -69,7 +69,7 @@
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@name='Predicate_edit:method']</td>
<td>//button[@name='Base_edit:method']</td>
<td></td>
</tr>
<tr>
......
......@@ -52,7 +52,7 @@
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@name='Predicate_edit:method']</td>
<td>//button[@name='Base_edit:method']</td>
<td></td>
</tr>
<tr>
......@@ -68,7 +68,7 @@
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@name='Predicate_edit:method']</td>
<td>//button[@name='Base_edit:method']</td>
<td></td>
</tr>
<tr>
......
......@@ -52,7 +52,7 @@
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@name='Predicate_edit:method']</td>
<td>//button[@name='Base_edit:method']</td>
<td></td>
</tr>
<tr>
......@@ -68,7 +68,7 @@
</tr>
<tr>
<td>clickAndWait</td>
<td>//button[@name='Predicate_edit:method']</td>
<td>//button[@name='Base_edit:method']</td>
<td></td>
</tr>
<tr>
......
......@@ -56,11 +56,19 @@ def editListBox(listbox_field, listbox):
"""
if listbox is not None:
global_property_dict = {}
if context.isPredicate():
predicate_listbox = set(context.getCriterionPropertyList()) == set(listbox.keys())
else:
predicate_listbox = False
if listbox_field.has_value('global_attributes'):
hidden_attribute_list = [x[0] for x in listbox_field.get_value('global_attributes')]
for hidden_attribute in hidden_attribute_list:
global_property_dict[hidden_attribute] = getattr(request, hidden_attribute, None)
for item_url, listbox_item_dict in listbox.items():
if predicate_listbox:
listbox_item_dict.update(global_property_dict)
context.setCriterion(item_url, **listbox_item_dict)
continue
listbox_item_dict.update(global_property_dict)
# Form: '' -> ERP5: None
encapsulated_editor_list = []
......
......@@ -35,7 +35,7 @@
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Predicate_edit</string> </value>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......
# Updates attributes of an Zope document
# which is in a class inheriting from ERP5 Base
#
# TODO
# - Implement validation of matrix fields
# - Implement validation of list fields
#
from Products.Formulator.Errors import FormValidationError
from ZTUtils import make_query
request=context.REQUEST
try:
# Define form basic fields
form = getattr(context,form_id)
edit_order = form.edit_order
# Validate
form.validate_all_to_request(request)
# Basic attributes
kw = {}
# Parse attributes
for f in form.get_fields():
k = f.id
v = getattr(request,k,None)
if v is not None:
if k[0:3] == 'my_':
# We only take into account
# the object attributes
k = k[3:]
kw[k] = v
# Update listbox attributes
listbox = request.get('listbox')
if listbox is not None:
listbox_field = form.get_field('listbox')
gv = {}
if listbox_field.has_value('global_attributes'):
hidden_attributes = [x[0] for x in listbox_field.get_value('global_attributes')]
for k in hidden_attributes:
gv[k] = getattr(request, k,None)
for property_, v in listbox.items():
v.update(gv)
context.setCriterion(property_, **v)
# Update basic attributes
context.edit(REQUEST=request, edit_order=edit_order, **kw)
context.reindexObject()
except FormValidationError, validation_errors:
# Pack errors into the request
field_errors = form.ErrorFields(validation_errors)
request.set('field_errors', field_errors)
return form(request)
else:
# for web mode, we should use 'view' instead of passed form_id
# after 'Save & View'.
if context.REQUEST.get('is_web_mode', False) and \
not editable_mode:
form_id = 'view'
if not selection_index:
redirect_url = '%s/%s?%s' % (
context.absolute_url(),
form_id,
make_query({'ignore_layout':ignore_layout,
'editable_mode':editable_mode,
'portal_status_message':'Data Updated.',
})
)
else:
redirect_url = '%s/%s?%s' % (
context.absolute_url(),
form_id,
make_query({'selection_index':selection_index,
'selection_name':selection_name,
'ignore_layout':ignore_layout,
'editable_mode':editable_mode,
'portal_status_message':'Data Updated.',
})
)
request[ 'RESPONSE' ].redirect( redirect_url )
# BBB: now we can use Base_edit for Predicate_view.
return context.Base_edit(
form_id=form_id,
selection_index=selection_index,
selection_name=selection_name,
ignore_layout=ignore_layout,
editable_mode=editable_mode,
)
......@@ -35,7 +35,7 @@
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Predicate_edit</string> </value>
<value> <string>Base_edit</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......
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