[CMF-checkins] SVN: CMF/trunk/CMFDefault/formlib/ - fixed some
datetime conversion issues (now ISO 8601 is used as
intermediate format)
Yvo Schubbe
y.2006_ at wcm-solutions.de
Mon Nov 13 08:57:41 EST 2006
Log message for revision 71117:
- fixed some datetime conversion issues (now ISO 8601 is used as intermediate format)
- added support for lists and tuples
Changed:
U CMF/trunk/CMFDefault/formlib/form.py
U CMF/trunk/CMFDefault/formlib/schema.py
U CMF/trunk/CMFDefault/formlib/schema.txt
-=-
Modified: CMF/trunk/CMFDefault/formlib/form.py
===================================================================
--- CMF/trunk/CMFDefault/formlib/form.py 2006-11-13 09:52:05 UTC (rev 71116)
+++ CMF/trunk/CMFDefault/formlib/form.py 2006-11-13 13:57:40 UTC (rev 71117)
@@ -21,7 +21,7 @@
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.Five.formlib.formbase import PageDisplayForm
from Products.Five.formlib.formbase import PageForm
-from Products.PluginIndexes.DateIndex.DateIndex import Local
+from zope.datetime import parseDatetimetz
from zope.formlib import form
from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.locales import LoadLocaleError
@@ -133,7 +133,7 @@
if isinstance(v, Set):
data[k] = set(v)
elif isinstance(v, datetime) and v.tzname() is None:
- data[k] = v.replace(tzinfo=Local)
+ data[k] = parseDatetimetz(str(v))
if form.applyChanges(self.context, self.form_fields, data,
self.adapters):
self.context.reindexObject()
Modified: CMF/trunk/CMFDefault/formlib/schema.py
===================================================================
--- CMF/trunk/CMFDefault/formlib/schema.py 2006-11-13 09:52:05 UTC (rev 71116)
+++ CMF/trunk/CMFDefault/formlib/schema.py 2006-11-13 13:57:40 UTC (rev 71117)
@@ -18,7 +18,7 @@
from datetime import datetime
from DateTime.DateTime import DateTime
-from Products.PluginIndexes.DateIndex.DateIndex import Local
+from zope.datetime import parseDatetimetz
from zope.interface import implements
from zope.schema import BytesLine
from zope.schema.interfaces import IBytesLine
@@ -68,12 +68,16 @@
if isinstance(attribute, str) and inst.encoding:
return attribute.decode(inst.encoding)
elif isinstance(attribute, DateTime):
- return datetime.fromtimestamp(attribute.timeTime(), Local)
+ return parseDatetimetz(attribute.ISO8601())
elif isinstance(attribute, (tuple, list)):
if inst.encoding:
attribute = [ isinstance(v, str)
and v.decode(inst.encoding) or v
for v in attribute ]
+ if self._field._type == list:
+ return attribute
+ if self._field._type == tuple:
+ return tuple(attribute)
return set(attribute)
return attribute
@@ -85,13 +89,14 @@
if isinstance(value, unicode) and inst.encoding:
value = value.encode(inst.encoding)
elif isinstance(value, datetime):
- value = DateTime(*value.astimezone(Local).timetuple()[:6])
- elif isinstance(value, set):
+ value = DateTime(value.isoformat())
+ elif isinstance(value, (set, tuple, list)):
if inst.encoding:
value = [ isinstance(v, unicode)
and v.encode(inst.encoding) or v
for v in value ]
- value = tuple(value)
+ if not self._field._type == list:
+ value = tuple(value)
if self._set_name:
getattr(inst.context, self._set_name)(value)
elif inst.context.hasProperty(self._get_name):
Modified: CMF/trunk/CMFDefault/formlib/schema.txt
===================================================================
--- CMF/trunk/CMFDefault/formlib/schema.txt 2006-11-13 09:52:05 UTC (rev 71116)
+++ CMF/trunk/CMFDefault/formlib/schema.txt 2006-11-13 13:57:40 UTC (rev 71117)
@@ -11,6 +11,8 @@
... foo_text = ''
... foo_datetime = None
... foo_set = ()
+ ... foo_list = []
+ ... foo_tuple = ()
... foo_prop = ''
>>> from zope.interface import Interface
@@ -19,6 +21,8 @@
... foo_text = schema.Text()
... foo_datetime = schema.Datetime()
... foo_set = schema.Set()
+ ... foo_list = schema.List()
+ ... foo_tuple = schema.Tuple()
... foo_prop = schema.Text()
>>> from Products.CMFDefault.formlib.schema import ProxyFieldProperty
@@ -27,6 +31,8 @@
... foo_text = ProxyFieldProperty(IFooContentView['foo_text'])
... foo_datetime = ProxyFieldProperty(IFooContentView['foo_datetime'])
... foo_set = ProxyFieldProperty(IFooContentView['foo_set'])
+ ... foo_list = ProxyFieldProperty(IFooContentView['foo_list'])
+ ... foo_tuple = ProxyFieldProperty(IFooContentView['foo_tuple'])
... foo_prop = ProxyFieldProperty(IFooContentView['foo_prop'])
...
... def __init__(self, context):
@@ -57,6 +63,15 @@
>>> adapter.foo_datetime == foo_datetime
True
+ >>> foo_zope_datetime = DateTime(1970, 0)
+ >>> content.foo_datetime = foo_zope_datetime
+ >>> foo_python_datetime = adapter.foo_datetime
+ >>> adapter.foo_datetime = foo_python_datetime
+ >>> content.foo_datetime == foo_zope_datetime
+ True
+ >>> adapter.foo_datetime == foo_python_datetime
+ True
+
set is mapped to tuple::
>>> foo_set = set([3, 1, 4])
@@ -66,6 +81,24 @@
>>> adapter.foo_set == foo_set
True
+ list with unicode is mapped to list with str::
+
+ >>> foo_list = [3, 1, u'foo']
+ >>> adapter.foo_list = foo_list
+ >>> content.foo_list
+ [3, 1, 'foo']
+ >>> adapter.foo_list == foo_list
+ True
+
+ tuple with unicode is mapped to tuple with str::
+
+ >>> foo_tuple = (3, 1, u'foo')
+ >>> adapter.foo_tuple = foo_tuple
+ >>> content.foo_tuple
+ (3, 1, 'foo')
+ >>> adapter.foo_tuple == foo_tuple
+ True
+
PropertyManager properties use _setProperty::
>>> foo_prop = u'foo'
More information about the CMF-checkins
mailing list