more api update
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Tue, 08 Dec 2009 07:54:51 -0800
changeset 4053 7cc66b1d9183
parent 4052 0c39ffd789ed
child 4054 03c9a539d282
more api update
devtools/fill.py
devtools/testlib.py
web/views/editcontroller.py
web/views/editforms.py
--- a/devtools/fill.py	Tue Dec 08 18:05:10 2009 +0100
+++ b/devtools/fill.py	Tue Dec 08 07:54:51 2009 -0800
@@ -30,7 +30,7 @@
     """returns possible choices for 'attrname'
     if attrname doesn't have ChoiceConstraint, return None
     """
-    for cst in eschema.constraints(attrname):
+    for cst in eschema.rdef(attrname).constraints:
         if isinstance(cst, StaticVocabularyConstraint):
             return cst.vocabulary()
     return None
@@ -38,14 +38,14 @@
 
 def get_max_length(eschema, attrname):
     """returns the maximum length allowed for 'attrname'"""
-    for cst in eschema.constraints(attrname):
+    for cst in eschema.rdef(attrname).constraints:
         if isinstance(cst, SizeConstraint) and cst.max:
             return cst.max
     return 300
     #raise AttributeError('No Size constraint on attribute "%s"' % attrname)
 
 def get_bounds(eschema, attrname):
-    for cst in eschema.constraints(attrname):
+    for cst in eschema.rdef(attrname).constraints:
         if isinstance(cst, IntervalBoundConstraint):
             return cst.minvalue, cst.maxvalue
     return None, None
@@ -340,10 +340,10 @@
 
 def composite_relation(rschema):
     for obj in rschema.objects():
-        if obj.objrproperty(rschema, 'composite') == 'subject':
+        if obj.rdef(rschema, 'object').composite == 'subject':
             return True
     for obj in rschema.subjects():
-        if obj.subjrproperty(rschema, 'composite') == 'object':
+        if obj.rdef(rschema, 'subject').composite == 'object':
             return True
     return False
 
@@ -372,11 +372,11 @@
             oedict = deepcopy(edict)
             delayed = []
             # for each couple (subjschema, objschema), insert relations
-            for subj, obj in rschema.iter_rdefs():
+            for subj, obj in rschema.rdefs:
                 sym.add( (subj, obj) )
                 if rschema.symetric and (obj, subj) in sym:
                     continue
-                subjcard, objcard = rschema.rproperty(subj, obj, 'cardinality')
+                subjcard, objcard = rschema.rdef(subj, obj).cardinality
                 # process mandatory relations first
                 if subjcard in '1+' or objcard in '1+' or composite_relation(rschema):
                     for query, args in self.make_relation_queries(sedict, oedict,
@@ -397,14 +397,15 @@
         return {'subjeid' : subjeid, 'objeid' : objeid}
 
     def make_relation_queries(self, sedict, oedict, rschema, subj, obj):
-        subjcard, objcard = rschema.rproperty(subj, obj, 'cardinality')
+        rdef = rschema.rdef(subj, obj)
+        subjcard, objcard = rdef.cardinality
         subjeids = sedict.get(subj, frozenset())
         used = self.existingrels[rschema.type]
         preexisting_subjrels = set(subj for subj, obj in used)
         preexisting_objrels = set(obj for subj, obj in used)
         # if there are constraints, only select appropriate objeids
         q = self.rql_tmpl % rschema.type
-        constraints = [c for c in rschema.rproperty(subj, obj, 'constraints')
+        constraints = [c for c in rdef.constraints
                        if isinstance(c, RQLConstraint)]
         if constraints:
             restrictions = ', '.join(c.restriction for c in constraints)
--- a/devtools/testlib.py	Tue Dec 08 18:05:10 2009 +0100
+++ b/devtools/testlib.py	Tue Dec 08 07:54:51 2009 -0800
@@ -693,8 +693,8 @@
     for rschema in schema.relations():
         if rschema.final:
             continue
-        for subj, obj in rschema.iter_rdefs():
-            card = rschema.rproperty(subj, obj, 'cardinality')
+        for subj, obj in rschema.rdefs:
+            card = rschema.rdef(subj, obj).cardinality
             if card[0] in '1?' and len(rschema.subjects(obj)) == 1:
                 relmap.setdefault((rschema, subj), []).append(str(obj))
             if card[1] in '1?' and len(rschema.objects(subj)) == 1:
--- a/web/views/editcontroller.py	Tue Dec 08 18:05:10 2009 +0100
+++ b/web/views/editcontroller.py	Tue Dec 08 07:54:51 2009 -0800
@@ -174,12 +174,12 @@
         try:
             for attr, value in field.process_posted(form):
                 if not (
-                    (field.role == 'subject' and eschema.has_subject_relation(field.name))
+                    (field.role == 'subject' and field.name in eschema.subjrels)
                     or
-                    (field.role == 'object' and eschema.has_object_relation(field.name))):
+                    (field.role == 'object' and field.name in eschema.objrels)):
                     continue
                 rschema = self._cw.vreg.schema.rschema(field.name)
-                if rschema.is_final():
+                if rschema.final:
                     rqlquery.kwargs[attr] = value
                     rqlquery.edited.append('X %s %%(%s)s' % (attr, attr))
                 elif rschema.inlined:
--- a/web/views/editforms.py	Tue Dec 08 18:05:10 2009 +0100
+++ b/web/views/editforms.py	Tue Dec 08 07:54:51 2009 -0800
@@ -205,7 +205,7 @@
         w(form.render(renderer=renderer))
         w(u'<div id="%s" class="editableField hidden" onclick="%s" title="%s">' % (
                 divid, xml_escape(self._onclick % form.event_args),
-                self.req._(self._landingzonemsg)))
+                self._cw._(self._landingzonemsg)))
         w(lzone)
         w(u'</div>')
         w(u'</div>')