devtools/fill.py
changeset 4053 7cc66b1d9183
parent 3749 a84e798b99f6
child 4072 ead446e70c28
--- 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)