Author: jmorliaguet
Date: Sun Apr 30 11:32:28 2006
New Revision: 2989

Modified:
   cpsskins/branches/paris-sprint-2006/setup/io.py
Log:

- fixed the exporter (properties where not exported on leaf items)

- added Int and Bool field adapters



Modified: cpsskins/branches/paris-sprint-2006/setup/io.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io.py     Sun Apr 30 11:32:28 2006
@@ -73,9 +73,8 @@
         element_el = document.createElement(IType(context).resourcename)
         element_el.setAttribute(u'uri', IIdentifiable(context).getURI())
 
-        schema = IType(context).getContentType()
-
         # properties
+        schema = IType(context).getContentType()
 
         for name, field in zope.schema.getFieldsInOrder(schema):
             obj = getattr(context, name)
@@ -86,17 +85,17 @@
             else:
                 value = obj
 
-            prop = document.createElement(name)
-            prop.setAttribute(u'value', value)
+            prop_el = document.createElement(name)
+            prop_el.setAttribute(u'value', value)
 
-            element_el.appendChild(prop)
+            element_el.appendChild(prop_el)
 
-        # child nodes
+        node.appendChild(element_el)
 
+        # child nodes
         if IItemContainer.providedBy(context):
-            node_child = node.appendChild(element_el)
             for child in context:
-                exporter = getMultiAdapter((context[child], node_child),
+                exporter = getMultiAdapter((context[child], element_el),
                                             IDOMAdapter)
                 exporter.setDocument(document)
                 exporter.save()
@@ -147,9 +146,41 @@
         self.field = field
 
     def dump(self, obj):
+        # TODO escape ','
         return u','.join(obj)
 
     def load(self, text):
+        # TODO unescape ','
         return text.split(',')
 
+class IntField:
+    """An integer field.
+    """
+    adapts(zope.schema.interfaces.IInt)
+    implements(IFieldIO)
+
+    def __init__(self, field):
+        self.field = field
+
+    def dump(self, obj):
+        return unicode(obj)
+
+    def load(self, text):
+        return int(obj)
+
+class BoolField:
+    """A boolean field.
+    """
+    adapts(zope.schema.interfaces.IBool)
+    implements(IFieldIO)
+
+    def __init__(self, field):
+        self.field = field
+
+    def dump(self, obj):
+        return unicode(obj)
+
+    def load(self, text):
+        return bool(obj)
+
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to