Author: jmorliaguet
Date: Thu Feb  9 13:35:28 2006
New Revision: 2330

Modified:
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
Log:

- we get the schema definition directly from the zope3 schema interface.



Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     Thu Feb  9 13:35:28 2006
@@ -5,30 +5,23 @@
 from zope.app.publisher.browser import BrowserView
 from zope.app.cache.ram import RAMCache
 
+from zope.interface import Interface
+from zope.schema import Text
+from zope.schema.fieldproperty import FieldProperty
+
 from cpsskins import minjson as json
 
 cache = RAMCache()
 
-# Schema definition (resides on the server)
-# could be obtained from zope3 schema definitions
-schema = {
-    'firstname': {
-         'label': u'First name',
-         'required': True,
-    },
-    'lastname': {
-         'label': u'Last name',
-         'required': True,
-    },
-    'email': {
-         'label': u'Email address',
-         'required': False,
-         'initial_value': '[EMAIL PROTECTED]',
-         'constraint': re.compile("^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+"
-                                  "@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+"
-                                  
"[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$").match,
-    },
-}
+class DummySchema(Interface):
+
+    firstname = Text(title=u'First name', required=True)
+    lastname = Text(title=u'Last name', required=True)
+    email = Text(title=u'Email address', required=False,
+                 default=u'[EMAIL PROTECTED]', constraint = re.compile(
+                   "^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+"
+                   "@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+"
+                   "[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$").match)
 
 form_layout = ['firstname', 'lastname', 'email']
 
@@ -38,16 +31,19 @@
         self.context = context
         self.request = request
 
+        self.schema = DummySchema # for testing
+
         self.initial_form_data = self._initializeFormData()
 
     def _initializeFormData(self):
+
         fields = []
         for name in form_layout:
-            field_def = schema[name]
+            field_def = FieldProperty(self.schema[name])
             fields.append({
                 'name': name,
-                'label': field_def['label'],
-                'value': field_def.get('initial_value', u''),
+                'label': field_def.title,
+                'value': field_def.default,
                 'status': u'',
             })
         return {'fields': fields}
@@ -65,17 +61,17 @@
         for field in fields:
             name = field['name']
             value = data[name]
-            field_def = schema[name]
+            field_def = FieldProperty(self.schema[name])
 
             # validation
             valid = True
             field['status'] = u''
 
-            if field_def['required'] and not value:
+            if field_def.required and not value:
                 field['status'] = u"this field is required"
                 valid = False
 
-            constraint = field_def.get('constraint')
+            constraint = field_def.constraint
             if constraint is not None:
                 m = constraint(value)
                 if not m:
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to