Commit 81b19fc2 authored by Yusei Tahara's avatar Yusei Tahara

Fixed a bug that original persistent Method object is cached.

Persistent object must be cloned before cached.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16521 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b27f90df
...@@ -40,6 +40,7 @@ from urllib import quote ...@@ -40,6 +40,7 @@ from urllib import quote
from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request
from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from Acquisition import aq_base
from Products.PageTemplates.Expressions import SecureModuleImporter from Products.PageTemplates.Expressions import SecureModuleImporter
from Products.ERP5Type.Utils import UpperCase from Products.ERP5Type.Utils import UpperCase
...@@ -53,6 +54,7 @@ def purgeFieldValueCache(): ...@@ -53,6 +54,7 @@ def purgeFieldValueCache():
# Patch the fiels methods to provide improved namespace handling # Patch the fiels methods to provide improved namespace handling
from Products.Formulator.Field import Field from Products.Formulator.Field import Field
from Products.Formulator.MethodField import Method
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from zLOG import LOG, PROBLEM from zLOG import LOG, PROBLEM
...@@ -64,6 +66,8 @@ class StaticValue: ...@@ -64,6 +66,8 @@ class StaticValue:
value as is) value as is)
""" """
def __init__(self, value): def __init__(self, value):
if type(aq_base(value)) is Method:
value = Method(value.method_name)
self.value = value self.value = value
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
...@@ -143,6 +147,8 @@ class TALESValue(StaticValue): ...@@ -143,6 +147,8 @@ class TALESValue(StaticValue):
class OverrideValue(StaticValue): class OverrideValue(StaticValue):
def __init__(self, override): def __init__(self, override):
if type(aq_base(override)) is Method:
override = Method(override.method_name)
self.override = override self.override = override
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
...@@ -151,6 +157,8 @@ class OverrideValue(StaticValue): ...@@ -151,6 +157,8 @@ class OverrideValue(StaticValue):
class DefaultValue(StaticValue): class DefaultValue(StaticValue):
def __init__(self, field_id, value): def __init__(self, field_id, value):
self.key = field_id[3:] self.key = field_id[3:]
if type(aq_base(value)) is Method:
value = Method(value.method_name)
self.value = value self.value = value
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
......
...@@ -51,9 +51,12 @@ ZopeTestCase.installProduct('ERP5Form') ...@@ -51,9 +51,12 @@ ZopeTestCase.installProduct('ERP5Form')
from Products.Formulator.StandardFields import FloatField from Products.Formulator.StandardFields import FloatField
from Products.Formulator.StandardFields import StringField from Products.Formulator.StandardFields import StringField
from Products.Formulator.MethodField import Method
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Form.Form import ERP5Form, purgeFieldValueCache from Products.ERP5Form.Form import ERP5Form
from Products.ERP5Form.Form import purgeFieldValueCache
from Products.ERP5Form.Form import getFieldValue
class TestFloatField(unittest.TestCase): class TestFloatField(unittest.TestCase):
...@@ -218,10 +221,27 @@ class TestProxyField(unittest.TestCase): ...@@ -218,10 +221,27 @@ class TestProxyField(unittest.TestCase):
self.assertEquals('Base_view', proxy_field.get_value('title')) self.assertEquals('Base_view', proxy_field.get_value('title'))
class TestFieldValueCache(unittest.TestCase):
"""Tests field value caching system
"""
def setUp(self):
self.form = ERP5Form('form', 'Form')
self.form.field = StringField('test_field')
# method field
self.form.field.values['external_validator'] = Method('this_is_a_method')
def test_method_field(self):
field = self.form.field
value = getFieldValue(field, field, 'external_validator')
self.assertEqual(False, value.value is field.values['external_validator'])
self.assertEqual(True, type(value.value) is Method)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestFloatField)) suite.addTest(unittest.makeSuite(TestFloatField))
suite.addTest(unittest.makeSuite(TestStringField)) suite.addTest(unittest.makeSuite(TestStringField))
suite.addTest(unittest.makeSuite(TestProxyField)) suite.addTest(unittest.makeSuite(TestProxyField))
suite.addTest(unittest.makeSuite(TestFieldValueCache))
return suite return suite
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