api update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Dec 2009 16:33:32 +0100
changeset 4087 2b8bc4cfd6ee
parent 4086 9b96126e0b14
child 4088 23ce2b3fb03d
api update
schemaviewer.py
web/facet.py
web/test/test_views.py
web/views/actions.py
web/views/wdoc.py
web/views/workflow.py
--- a/schemaviewer.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/schemaviewer.py	Wed Dec 09 16:33:32 2009 +0100
@@ -9,7 +9,9 @@
 _ = unicode
 
 from logilab.common.ureports import Section, Title, Table, Link, Span, Text
+
 from yams.schema2dot import CARD_MAP
+from yams.schema import RelationDefinitionSchema
 
 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')]
 
@@ -185,7 +187,7 @@
         rschema_objects = rschema.objects()
         if rschema_objects:
             # might be empty
-            properties = [p for p in rschema.rproperty_defs(rschema_objects[0])
+            properties = [p for p in RelationDefinitionSchema.rproperty_defs(rschema_objects[0])
                           if not p in ('cardinality', 'composite', 'eid')]
         else:
             properties = []
@@ -201,8 +203,9 @@
                     done.add((objtype, subjtype))
                 data.append(Link(self.eschema_link_url(schema[subjtype]), subjtype))
                 data.append(Link(self.eschema_link_url(schema[objtype]), objtype))
+                rdef = rschema.rdef(subjtype, objtypep)
                 for prop in properties:
-                    val = rschema.rproperty(subjtype, objtype, prop)
+                    val = getattr(rdef, prop)
                     if val is None:
                         val = ''
                     elif isinstance(val, (list, tuple)):
--- a/web/facet.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/web/facet.py	Wed Dec 09 16:33:32 2009 +0100
@@ -411,20 +411,16 @@
     @cached
     def support_and(self):
         rschema = self._cw.vreg.schema.rschema(self.rtype)
-        if self.role == 'subject':
-            cardidx = 0
-        else:
-            cardidx = 1
         # XXX when called via ajax, no rset to compute possible types
         possibletypes = self.cw_rset and self.cw_rset.column_types(0)
-        for subjtype, objtype in rschema.iter_rdefs():
+        for rdef in rschema.rdefs.itervalues():
             if possibletypes is not None:
                 if self.role == 'subject':
-                    if not subjtype in possibletypes:
+                    if not rdef.subject in possibletypes:
                         continue
-                elif not objtype in possibletypes:
+                elif not rdef.object in possibletypes:
                     continue
-            if rschema.rproperty(subjtype, objtype, 'cardinality')[cardidx] in '+*':
+            if rdef.role_cardinality(role) in '+*':
                 return True
         return False
 
--- a/web/test/test_views.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/web/test/test_views.py	Wed Dec 09 16:33:32 2009 +0100
@@ -63,7 +63,7 @@
 
     def test_unrelateddivs(self):
         rset = self.execute('Any X WHERE X is CWUser, X login "admin"')
-        group = self.add_entity('CWGroup', name=u'R&D')
+        group = self.request().create_entity('CWGroup', name=u'R&D')
         req = self.request(relation='in_group_subject')
         self.view('unrelateddivs', rset, req)
 
--- a/web/views/actions.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/web/views/actions.py	Wed Dec 09 16:33:32 2009 +0100
@@ -65,7 +65,7 @@
         select = rqlst.children[0]
         if len(select.defined_vars) == 1 and len(select.solutions) == 1:
             rset._searched_etype = select.solutions[0].itervalues().next()
-            eschema = req.schema.eschema(rset._searched_etype)
+            eschema = req.vreg.schema.eschema(rset._searched_etype)
             if not (eschema.final or eschema.is_subobject(strict=True)) \
                    and eschema.has_perm(req, 'add'):
                 return 1
--- a/web/views/wdoc.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/web/views/wdoc.py	Wed Dec 09 16:33:32 2009 +0100
@@ -172,9 +172,9 @@
     def call(self):
         fid = self._cw.form['fid']
         for lang in chain((self._cw.lang, self._cw.vreg.property_value('ui.language')),
-                          self._cw.config.available_languages()):
+                          self._cw.vreg.config.available_languages()):
             rid = join('images', '%s_%s.png' % (fid, lang))
-            resourcedir = self._cw.config.locate_doc_file(rid)
+            resourcedir = self._cw.vreg.config.locate_doc_file(rid)
             if resourcedir:
                 break
         else:
--- a/web/views/workflow.py	Wed Dec 09 16:07:07 2009 +0100
+++ b/web/views/workflow.py	Wed Dec 09 16:33:32 2009 +0100
@@ -195,7 +195,7 @@
         self.w(entity.view('reledit', rtype='description'))
         self.w(u'<img src="%s" alt="%s"/>' % (
             xml_escape(entity.absolute_url(vid='wfgraph')),
-            xml_escape(self.req._('graphical workflow for %s') % entity.name)))
+            xml_escape(self._cw._('graphical workflow for %s') % entity.name)))
 
 
 class CellView(view.EntityView):
@@ -238,7 +238,7 @@
     def workflow_states_for_relation(self, targetrelation):
         eids = self.edited_entity.linked_to('transition_of', 'subject')
         if eids:
-            return workflow_items_for_relation(self.req, eids[0], 'state_of',
+            return workflow_items_for_relation(self._cw, eids[0], 'state_of',
                                                targetrelation)
         return []
 
@@ -260,7 +260,7 @@
         if not self.edited_entity.has_eid():
             eids = self.edited_entity.linked_to('state_of', 'subject')
             if eids:
-                return workflow_items_for_relation(self.req, eids[0], 'transition_of',
+                return workflow_items_for_relation(self._cw, eids[0], 'transition_of',
                                                    'allowed_transition')
         return []