yams api update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 09:10:16 +0100
changeset 4014 24f7d7eb4c23
parent 4013 f0d1038e5059
child 4015 4f8235204dda
yams api update
server/schemaserial.py
web/formfields.py
--- a/server/schemaserial.py	Tue Dec 08 09:09:07 2009 +0100
+++ b/server/schemaserial.py	Tue Dec 08 09:10:16 2009 +0100
@@ -399,7 +399,7 @@
     if subjtype is None:
         assert objtype is None
         assert props is None
-        targets = rschema.iter_rdefs()
+        targets = rschema.rdefs
     else:
         assert not objtype is None
         targets = [(subjtype, objtype)]
--- a/web/formfields.py	Tue Dec 08 09:09:07 2009 +0100
+++ b/web/formfields.py	Tue Dec 08 09:10:16 2009 +0100
@@ -583,27 +583,25 @@
     'subjschema rschema objschema' according to information found in the schema
     """
     fieldclass = None
-    card = eschema.cardinality(rschema, role)
+    rdef = eschema.rdef(rschema, role)
     if role == 'subject':
-        targetschema = rschema.objects(eschema)[0]
-        help = rschema.rproperty(eschema, targetschema, 'description')
+        targetschema = rdef.object
         if rschema.final:
-            if rschema.rproperty(eschema, targetschema, 'internationalizable'):
+            if rdef.internationalizable:
                 kwargs.setdefault('internationalizable', True)
             def get_default(form, es=eschema, rs=rschema):
                 return es.default(rs)
             kwargs.setdefault('initial', get_default)
     else:
-        targetschema = rschema.subjects(eschema)[0]
-        help = rschema.rproperty(targetschema, eschema, 'description')
-    kwargs['required'] = card in '1+'
+        targetschema = rdef.subject
+    kwargs['required'] = rdef.role_cardinality(role) in '1+'
     kwargs['name'] = rschema.type
     if role == 'object':
         kwargs.setdefault('label', (eschema.type, rschema.type + '_object'))
     else:
         kwargs.setdefault('label', (eschema.type, rschema.type))
     kwargs['eidparam'] = True
-    kwargs.setdefault('help', help)
+    kwargs.setdefault('help', rdef.description)
     if rschema.final:
         if skip_meta_attr and rschema in eschema.meta_attributes():
             return None
@@ -617,18 +615,16 @@
                 # use RichTextField instead of StringField if the attribute has
                 # a "format" metadata. But getting information from constraints
                 # may be useful anyway...
-                constraints = rschema.rproperty(eschema, targetschema, 'constraints')
-                for cstr in constraints:
+                for cstr in rdef.constraints:
                     if isinstance(cstr, StaticVocabularyConstraint):
                         raise Exception('rich text field with static vocabulary')
                 return RichTextField(**kwargs)
-            constraints = rschema.rproperty(eschema, targetschema, 'constraints')
             # init StringField parameters according to constraints
-            for cstr in constraints:
+            for cstr in rdef.constraints:
                 if isinstance(cstr, StaticVocabularyConstraint):
                     kwargs.setdefault('choices', cstr.vocabulary)
                     break
-            for cstr in constraints:
+            for cstr in rdef.constraints:
                 if isinstance(cstr, SizeConstraint) and cstr.max is not None:
                     kwargs['max_length'] = cstr.max
             return StringField(**kwargs)