use yams api
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 04 Aug 2009 17:01:00 +0200
changeset 2678 0308dc159b96
parent 2677 8df54acd6613
child 2679 3fa8c0cec760
use yams api
utils.py
web/formfields.py
web/views/editforms.py
--- a/utils.py	Tue Aug 04 17:00:14 2009 +0200
+++ b/utils.py	Tue Aug 04 17:01:00 2009 +0200
@@ -326,18 +326,3 @@
     """
     # XXX deprecated, no more necessary
 
-def get_schema_property(eschema, rschema, role, property):
-    # XXX use entity.e_schema.role_rproperty(role, rschema, property, tschemas[0]) once yams > 0.23.0 is out
-    if role == 'subject':
-        targetschema = rschema.objects(eschema)[0]
-        return rschema.rproperty(eschema, targetschema, property)
-    targetschema = rschema.subjects(eschema)[0]
-    return rschema.rproperty(targetschema, eschema, property)
-
-def compute_cardinality(eschema, rschema, role):
-    if role == 'subject':
-        targetschema = rschema.objects(eschema)[0]
-        return rschema.rproperty(eschema, targetschema, 'cardinality')[0]
-    targetschema = rschema.subjects(eschema)[0]
-    return rschema.rproperty(targetschema, eschema, 'cardinality')[1]
-
--- a/web/formfields.py	Tue Aug 04 17:00:14 2009 +0200
+++ b/web/formfields.py	Tue Aug 04 17:01:00 2009 +0200
@@ -14,7 +14,7 @@
 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
                               FormatConstraint)
 
-from cubicweb.utils import ustrftime, compute_cardinality
+from cubicweb.utils import ustrftime
 from cubicweb.common import tags, uilib
 from cubicweb.web import INTERNAL_FIELD_VALUE
 from cubicweb.web.formwidgets import (
@@ -490,9 +490,9 @@
     'subjschema rschema objschema' according to information found in the schema
     """
     fieldclass = None
+    card = eschema.cardinality(rschema, role)
     if role == 'subject':
         targetschema = rschema.objects(eschema)[0]
-        card = compute_cardinality(eschema, rschema, role)
         help = rschema.rproperty(eschema, targetschema, 'description')
         if rschema.is_final():
             if rschema.rproperty(eschema, targetschema, 'internationalizable'):
@@ -502,7 +502,6 @@
             kwargs.setdefault('initial', get_default)
     else:
         targetschema = rschema.subjects(eschema)[0]
-        card = compute_cardinality(eschema, rschema, role)
         help = rschema.rproperty(targetschema, eschema, 'description')
     kwargs['required'] = card in '1+'
     kwargs['name'] = rschema.type
--- a/web/views/editforms.py	Tue Aug 04 17:00:14 2009 +0200
+++ b/web/views/editforms.py	Tue Aug 04 17:01:00 2009 +0200
@@ -17,7 +17,7 @@
 
 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
                                 specified_etype_implements, yes)
-from cubicweb.utils import make_uid, compute_cardinality, get_schema_property
+from cubicweb.utils import make_uid
 from cubicweb.view import EntityView
 from cubicweb.common import tags
 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, eid_param, uicfg
@@ -116,10 +116,8 @@
     _one_rvid = 'incontext'
     _many_rvid = 'csv'
 
-    def _compute_best_vid(self, entity, rtype, role):
-        if compute_cardinality(entity.e_schema,
-                               entity.schema.rschema(rtype),
-                               role) in '+*':
+    def _compute_best_vid(self, eschema, rschema, role):
+        if eschema.cardinality(rschema, role) in '+*':
             return self._many_rvid
         return self._one_rvid