Commit ddeb97a9 authored by Jérome Perrin's avatar Jérome Perrin

Add an option on the proxify tool to delegate values unconditionnaly instead of

keeping values if they are different. This is useful when you proxify a form
to use a field library and want to delegate everything.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19776 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4e55e3a0
......@@ -801,8 +801,12 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
return [f for f in self.objectValues() if f.meta_type == 'ProxyField']
security.declareProtected('Change Formulator Forms', 'proxifyField')
def proxifyField(self, field_dict=None, REQUEST=None):
"""Convert fields to proxy fields"""
def proxifyField(self, field_dict=None, force_delegate=False, REQUEST=None):
"""Convert fields to proxy fields
If the field value is different from the proxyfield value, the value is
kept on the proxyfield, otherwise it is delegated. If you specify
force_delegate, values will be delegated even if they are different
"""
from Products.ERP5Form.ProxyField import ProxyWidget
def copy(_dict):
......@@ -833,7 +837,7 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
def remove_same_value(new_dict, target_dict):
for key, value in new_dict.items():
target_value = target_dict.get(key)
if is_equal(value, target_value):
if force_delegate or is_equal(value, target_value):
del new_dict[key]
return new_dict
......
......@@ -4,11 +4,17 @@
<dtml-let form_field_list=getFormFieldList>
<p class="form-help">
Proxify non-proxy fields.
Proxify non-proxy fields.<br/>
This tool will keep values on fields if they are different from the target
field.<br/>
If you don't want this behaviour, check the <em>Delegate values</em> checkbox
below and all values will be delegated to the proxy target.
</p>
<form action="proxifyField" method="POST">
Delegate values <input type="checkbox" name="force_delegate"> <br/>
<table border="2">
<tr>
<th>Id</th>
......
......@@ -141,6 +141,19 @@ class TestProxify(unittest.TestCase):
template_field.values['title'] = 'Region'
self.assertEqual(field.get_value('title'), 'Region')
def test_force_delegate(self):
self.person_view.proxifyField({'my_name':'Base_view.my_string_field'},
force_delegate=1)
field = self.person_view.my_name
self.assertEqual(field.meta_type, 'ProxyField')
self.assertEqual(field.get_value('form_id'), 'Base_view')
self.assertEqual(field.get_value('field_id'), 'my_string_field')
self.assertEqual(field.is_delegated('title'), True)
self.assertEqual(field.is_delegated('size'), True)
self.assertEqual(field.is_delegated('enabled'), True)
self.assertEqual(field.is_delegated('description'), True)
def test_unproxify(self):
#Proxify First
self.address_view.proxifyField({'my_region':'Base_view.my_list_field'})
......
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