[Zope3-checkins] CVS: Zope3/lib/python/Schema - _Field.py:1.11 _Schema.py:1.9 __init__.py:1.4

Martijn Faassen m.faassen@vet.uu.nl
Wed, 4 Sep 2002 09:44:53 -0400


Update of /cvs-repository/Zope3/lib/python/Schema
In directory cvs.zope.org:/tmp/cvs-serv31848/python/Schema

Modified Files:
	_Field.py _Schema.py __init__.py 
Log Message:
Refactored Forms (and Schema).

  * A FormView now specifies a single schema explicitly as the 'schema'
    (class) attribute. A schema is simply an interface with Field attributes
    on it.

  * The FormView code now uses the Schema package more for its own
    implementation, instead of trying to reimplement things itself.

  * got rid of the 'id' attribute for fields. Fields now already know what
    name they have, because of the Interface package setting __name__.
    Use getName() to get the field name.



=== Zope3/lib/python/Schema/_Field.py 1.10 => 1.11 ===
--- Zope3/lib/python/Schema/_Field.py:1.10	Fri Jul 19 09:12:30 2002
+++ Zope3/lib/python/Schema/_Field.py	Wed Sep  4 09:44:22 2002
@@ -35,7 +35,9 @@
         """Pass in field values as keyword parameters."""
         for key, value in kw.items():
             setattr(self, key, value)
-        super(Field, self).__init__(self.title or 'no title')
+        # __name__ to '', so interface should initialize this with
+        # name of attribute
+        super(Field, self).__init__('')
 
     def validate(self, value):
         try:


=== Zope3/lib/python/Schema/_Schema.py 1.8 => 1.9 ===
--- Zope3/lib/python/Schema/_Schema.py:1.8	Thu Jul 25 18:09:30 2002
+++ Zope3/lib/python/Schema/_Schema.py	Wed Sep  4 09:44:22 2002
@@ -25,6 +25,18 @@
     this way."""
     
 
+def getFields(schema):
+    """Get all fields on a schema.
+    """
+    from IField import IField
+    fields = {}
+    for name in schema.names(1):
+        attr = schema.getDescriptionFor(name)
+        if IField.isImplementedBy(attr):
+            fields[name] = attr
+    return fields
+
+
 # validate functions either return silently, or raise a ValidationError
 # or in case of the validate*All functions, a ValidationErrosAll exception.
 # this should somehow be stated in an interface.


=== Zope3/lib/python/Schema/__init__.py 1.3 => 1.4 ===
--- Zope3/lib/python/Schema/__init__.py:1.3	Thu Jul 25 18:09:30 2002
+++ Zope3/lib/python/Schema/__init__.py	Wed Sep  4 09:44:22 2002
@@ -16,4 +16,4 @@
 $Id$
 """
 from _Field import *
-from _Schema import validateMapping, validateMappingAll
+from _Schema import validateMapping, validateMappingAll, getFields