Author: jmorliaguet
Date: Sun Apr 30 13:31:59 2006
New Revision: 2994

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

- added a base class for FieldIO that dumps to unicode and reads from unicode
  with field.fromUnicode(text).

  that actually works with most field types, otherwise we override dump() and
  load()

  new fields: Float, Choice, ...



Modified: cpsskins/branches/paris-sprint-2006/setup/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/configure.zcml    (original)
+++ cpsskins/branches/paris-sprint-2006/setup/configure.zcml    Sun Apr 30 
13:31:59 2006
@@ -67,6 +67,10 @@
   />
 
   <adapter
+      factory="cpsskins.setup.io.TextLineField"
+  />
+
+  <adapter
       factory="cpsskins.setup.io.IntField"
   />
 
@@ -74,4 +78,12 @@
       factory="cpsskins.setup.io.BoolField"
   />
 
+  <adapter
+      factory="cpsskins.setup.io.FloatField"
+  />
+
+  <adapter
+      factory="cpsskins.setup.io.ChoiceField"
+  />
+
 </configure>

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 13:31:59 2006
@@ -147,15 +147,23 @@
     def load(text):
         """convert the string into an object"""
 
-class ListField:
+class BaseFieldIO:
+
+    def __init__(self, field):
+        self.field = field
+
+    def load(self, text):
+        return self.field.fromUnicode(text)
+
+    def dump(self, obj):
+        return unicode(obj)
+
+class ListField(BaseFieldIO):
     """A list field.
     """
     adapts(zope.schema.interfaces.IList)
     implements(IFieldIO)
 
-    def __init__(self, field):
-        self.field = field
-
     def dump(self, obj):
         # TODO escape ','
         return u','.join(obj)
@@ -164,34 +172,33 @@
         # TODO unescape ','
         return text.split(',')
 
-class IntField:
+class IntField(BaseFieldIO):
     """An integer field.
     """
     adapts(zope.schema.interfaces.IInt)
     implements(IFieldIO)
 
-    def __init__(self, field):
-        self.field = field
-
-    def dump(self, obj):
-        return unicode(obj)
+class TextLineField(BaseFieldIO):
+    """A text line field.
+    """
+    adapts(zope.schema.interfaces.ITextLine)
+    implements(IFieldIO)
 
-    def load(self, text):
-        return int(obj)
+class FloatField(BaseFieldIO):
+    """A float field.
+    """
+    adapts(zope.schema.interfaces.IFloat)
+    implements(IFieldIO)
 
-class BoolField:
+class BoolField(BaseFieldIO):
     """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)
-
+class ChoiceField(BaseFieldIO):
+    """A choice field.
+    """
+    adapts(zope.schema.interfaces.IChoice)
+    implements(IFieldIO)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to