Commit 5a5640da authored by Yusei Tahara's avatar Yusei Tahara

Fixed a bug related to DateTime Field. (Thank you yoshinori)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16874 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0e0bfdd7
...@@ -54,11 +54,22 @@ def purgeFieldValueCache(): ...@@ -54,11 +54,22 @@ 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.MethodField import Method, BoundMethod
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from zLOG import LOG, PROBLEM from zLOG import LOG, PROBLEM
def copyMethod(value):
if type(aq_base(value)) is Method:
value = Method(value.method_name)
elif type(aq_base(value)) is TALESMethod:
value = TALESMethod(value._text)
elif type(aq_base(value)) is BoundMethod:
value = BoundMethod(value.object, value.method_name)
return value
class StaticValue: class StaticValue:
""" """
Encapsulated a static value in a class Encapsulated a static value in a class
...@@ -66,8 +77,8 @@ class StaticValue: ...@@ -66,8 +77,8 @@ class StaticValue:
value as is) value as is)
""" """
def __init__(self, value): def __init__(self, value):
if isinstance(aq_base(value), Method): if isinstance(aq_base(value), (Method, TALESMethod)):
value = Method(value.method_name) value = copyMethod(value)
self.value = value self.value = value
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
...@@ -151,8 +162,8 @@ class TALESValue(StaticValue): ...@@ -151,8 +162,8 @@ class TALESValue(StaticValue):
class OverrideValue(StaticValue): class OverrideValue(StaticValue):
def __init__(self, override): def __init__(self, override):
if isinstance(aq_base(override), Method): if isinstance(aq_base(override), (Method, TALESMethod)):
override = Method(override.method_name) override = copyMethod(override)
self.override = override self.override = override
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
...@@ -161,8 +172,8 @@ class OverrideValue(StaticValue): ...@@ -161,8 +172,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 isinstance(aq_base(value), Method): if isinstance(aq_base(value), (Method, TALESMethod)):
value = Method(value.method_name) value = copyMethod(value)
self.value = value self.value = value
def __call__(self, field, id, **kw): def __call__(self, field, id, **kw):
...@@ -755,18 +766,14 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -755,18 +766,14 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
def proxifyField(self, field_dict=None, REQUEST=None): def proxifyField(self, field_dict=None, REQUEST=None):
"""Convert fields to proxy fields""" """Convert fields to proxy fields"""
from Products.ERP5Form.ProxyField import ProxyWidget from Products.ERP5Form.ProxyField import ProxyWidget
from Products.Formulator.MethodField import Method
from Products.Formulator.TALESField import TALESMethod
def copy(_dict): def copy(_dict):
new_dict = {} new_dict = {}
for key, value in _dict.items(): for key, value in _dict.items():
if value=='': if value=='':
continue continue
if isinstance(value, Method): if isinstance(aq_base(value), (Method, TALESMethod)):
value = Method(value.method_name) value = copyMethod(value)
elif isinstance(value, TALESMethod):
value = TALESMethod(value._text)
elif value is not None and not isinstance(value, elif value is not None and not isinstance(value,
(str, unicode, int, long, bool, list, tuple, dict)): (str, unicode, int, long, bool, list, tuple, dict)):
raise ValueError, repr(value) raise ValueError, repr(value)
...@@ -778,7 +785,7 @@ class ERP5Form(ZMIForm, ZopePageTemplate): ...@@ -778,7 +785,7 @@ class ERP5Form(ZMIForm, ZopePageTemplate):
type_b = type(b) type_b = type(b)
if type_a is not type_b: if type_a is not type_b:
return False return False
elif type_a is Method: elif type_a is Method or type_a is BoundMethod:
return a.method_name==b.method_name return a.method_name==b.method_name
elif type_a is TALESMethod: elif type_a is TALESMethod:
return a._text==b._text return a._text==b._text
......
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