[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/schemagen - typereg.py:1.2

Martijn Faassen m.faassen@vet.uu.nl
Thu, 12 Dec 2002 05:45:54 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/schemagen
In directory cvs.zope.org:/tmp/cvs-serv15636

Modified Files:
	typereg.py 
Log Message:
* Represent field constructor arguments in the order defined by their
  schema.

* Test full round trip.
  fields -> source -> schema -> fields -> source
  works now.


=== Zope3/lib/python/Zope/App/schemagen/typereg.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/schemagen/typereg.py:1.1	Wed Dec 11 11:11:14 2002
+++ Zope3/lib/python/Zope/App/schemagen/typereg.py	Thu Dec 12 05:45:53 2002
@@ -101,11 +101,23 @@
         global typeRegistry
         self.importList =  self._getImportList(field)
         arguments = []
-        # don't represent order, as that will be implicit
+        # don't represent order of this field within its schema,
+        # as that will be implicit
         if 'order' in names:
             del names['order']
-        for name in names:
-            representation = typeRegistry.represent(getattr(field, name))
+        # we want to order the field constructor arguments according to the
+        # order of the fields on the schema describing this field
+        propertysorter = lambda x, y: cmp(x[1].order, y[1].order)
+        names_items = names.items()
+        names_items.sort(propertysorter)
+        # make a representation of property value and collect necessary imports
+        # we are not interested in the property field itself, just
+        # property value
+        for name, property in names_items:
+            value = getattr(field, name)
+            if property.default == value:
+                continue
+            representation = typeRegistry.represent(value)
             arguments.append((name, representation.text))
             for import_spec in representation.importList:
                 self.importList.append(import_spec)