[Zope3-checkins] CVS: Zope3/src/zope/schema - __init__.py:1.5 _schema.py:1.6

R. David Murray bitz@bitdance.com
Mon, 27 Jan 2003 21:57:17 -0500


Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv8113/zope/schema

Modified Files:
	__init__.py _schema.py 
Log Message:
zope.app.form.utility had a function, fieldNames, that returned a
list of the Fields in a schema in schema order.  This is exactly
parallel to getFieldsInOrder from the schema package itself, and
it seems to me that's where it belongs.  So I added a getFieldNamesInOrder
function to schema.  I also added a getFieldNames in parallel to
getFields, to complete the set.  Everything that used fieldNames
is converted to use getFieldNamesInOrder.

The unit tests from form was actually a little stronger than those
in schema:  it made sure that all fields were returned when using
a derived schema, which the schema tests didn't.  So I added some
subschema tests to the schema test suite in addition to the tests
for the new functions themselves.



=== Zope3/src/zope/schema/__init__.py 1.4 => 1.5 ===
--- Zope3/src/zope/schema/__init__.py:1.4	Thu Jan  9 09:13:18 2003
+++ Zope3/src/zope/schema/__init__.py	Mon Jan 27 21:56:45 2003
@@ -21,3 +21,4 @@
 from zope.schema._field import Text, TextLine, Bool, Int, Float, Tuple, List
 from zope.schema._field import Dict, Datetime
 from zope.schema._schema import getFields, getFieldsInOrder
+from zope.schema._schema import getFieldNames, getFieldNamesInOrder


=== Zope3/src/zope/schema/_schema.py 1.5 => 1.6 ===
--- Zope3/src/zope/schema/_schema.py:1.5	Mon Jan 27 20:03:51 2003
+++ Zope3/src/zope/schema/_schema.py	Mon Jan 27 21:56:45 2003
@@ -17,6 +17,12 @@
 from zope.interface import Interface
 from zope.schema.interfaces import ValidationError
 
+def getFieldNames(schema):
+    """Return a list of all the Field names in a schema.
+    """
+    from zope.schema.interfaces import IField
+    return [ name for name in schema if IField.isImplementedBy(schema[name]) ]
+
 def getFields(schema):
     """Return a dictionary containing all the Fields in a schema.
     """
@@ -30,8 +36,13 @@
 
 def getFieldsInOrder(schema,
                      _fieldsorter=lambda x, y: cmp(x[1].order, y[1].order)):
-    """Get a list of (name, value) tuples in native schema order.
+    """Return a list of (name, value) tuples in native schema order.
     """
     fields = getFields(schema).items()
     fields.sort(_fieldsorter)
     return fields
+
+def getFieldNamesInOrder(schema):
+    """Return a list of all the Field names in a schema in schema order.
+    """
+    return [ name for name, field in getFieldsInOrder(schema) ]