Commit 9dd3fcdb authored by Julien Muchembled's avatar Julien Muchembled

Render temporary ERP5 forms exactly like persistent forms

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29319 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 653fc5b7
......@@ -320,14 +320,6 @@ def get_value(self, id, **kw):
else:
field = self
# If field is not stored in zodb, then must use original get_value instead.
# Because field which is not stored in zodb must be used for editing field
# in ZMI and field value cache sometimes break these field settings at
# initialization. As the result, we will see broken field editing screen
# in ZMI.
if self._p_oid is None:
return self._original_get_value(id, **kw)
cache_id = ('Form.get_value',
self._p_oid,
field._p_oid,
......@@ -339,7 +331,11 @@ def get_value(self, id, **kw):
# either returns non callable value (ex. "Title")
# or a FieldValue instance of appropriate class
value, cacheable = getFieldValue(self, field, id, **kw)
if cacheable:
# Do not cache if the field is not stored in zodb,
# because such field must be used for editing field in ZMI
# and caching sometimes break these field settings at initialization.
# As the result, we would see broken field editing screen in ZMI.
if cacheable and self._p_oid:
_field_value_cache[cache_id] = value
if callable(value):
......@@ -376,9 +372,7 @@ def _get_default(self, key, value, REQUEST):
# Dynamic Patch
original_get_value = Field.get_value
Field.get_value = get_value
Field._original_get_value = original_get_value
Field._get_default = _get_default
Field.om_icons = om_icons
......
......@@ -510,7 +510,10 @@ class TestFieldValueCache(unittest.TestCase):
def setUp(self):
self.root = Folder('root')
self.root = self.root.__of__(self.root)
self.root.form = ERP5Form('form', 'Form')
self.root.getProperty = lambda key, d=None: \
dict(on_memory_field='123').get(key, d)
form = self.root.form
form.field = StringField('test_field')
......@@ -518,8 +521,12 @@ class TestFieldValueCache(unittest.TestCase):
# method field
form.field.values['external_validator'] = Method('this_is_a_method')
# on-memory field (not in zodb)
form.on_memory_field = StringField('test_on_memory_field')
form.on_memory_field._p_oid = None
form.my_on_memory_field = StringField('my_on_memory_field')
form.my_on_memory_field._p_oid = None
form.my_on_memory_tales_field = StringField('my_on_memory_tales_field')
form.my_on_memory_tales_field.manage_tales_xmlrpc({
'default': 'python: repr(here)'})
form.my_on_memory_field._p_oid = None
# proxy field
form.proxy_field = ProxyField.ProxyField('test_proxy_field')
form.proxy_field._p_oid = makeDummyOid()
......@@ -553,7 +560,10 @@ class TestFieldValueCache(unittest.TestCase):
# check on-memory field
# make sure that this will not use cache.
cache_size = len(Form._field_value_cache)
self.root.form.on_memory_field.get_value('title')
self.assertEqual(repr(self.root),
self.root.form.my_on_memory_tales_field.get_value('default'))
self.assertEqual('123',
self.root.form.my_on_memory_field.get_value('default'))
self.assertEqual(True, cache_size == len(Form._field_value_cache))
# check proxy 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