# HG changeset patch # User Sylvain Thénault # Date 1249398060 -7200 # Node ID 0308dc159b96b536192d5a555e5afe82312e8ca7 # Parent 8df54acd6613e663389a9f0176363271d14574cd use yams api diff -r 8df54acd6613 -r 0308dc159b96 utils.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] - diff -r 8df54acd6613 -r 0308dc159b96 web/formfields.py --- 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 diff -r 8df54acd6613 -r 0308dc159b96 web/views/editforms.py --- 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