some api update
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Dec 2009 12:22:21 +0100
changeset 4072 ead446e70c28
parent 4071 e19e586cc74e
child 4074 9cce43f52c61
some api update
devtools/fill.py
hooks/test/unittest_hooks.py
web/facet.py
web/test/unittest_views_searchrestriction.py
web/uicfg.py
web/views/basecontrollers.py
web/views/navigation.py
web/views/primary.py
--- a/devtools/fill.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/devtools/fill.py	Wed Dec 09 12:22:21 2009 +0100
@@ -112,7 +112,7 @@
         attrlength = get_max_length(self.e_schema, attrname)
         num_len = numlen(index)
         if num_len >= attrlength:
-            ascii = self.e_schema.rproperty(attrname, 'internationalizable')
+            ascii = self.e_schema.rdef(attrname).internationalizable
             return ('&'+decompose_b26(index, ascii))[:attrlength]
         # always use plain text when no format is specified
         attrprefix = attrname[:max(attrlength-num_len-1, 0)]
--- a/hooks/test/unittest_hooks.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/hooks/test/unittest_hooks.py	Wed Dec 09 12:22:21 2009 +0100
@@ -434,17 +434,17 @@
         sqlcursor = self.session.pool['system']
         try:
             self.execute('SET X indexed FALSE WHERE X relation_type R, R name "name"')
-            self.failUnless(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
+            self.failUnless(self.schema['name'].rdef('Workflow', 'String').indexed)
             self.failUnless(self.index_exists('Workflow', 'name'))
             self.commit()
-            self.failIf(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
+            self.failIf(self.schema['name'].rdef('Workflow', 'String').indexed)
             self.failIf(self.index_exists('Workflow', 'name'))
         finally:
             self.execute('SET X indexed TRUE WHERE X relation_type R, R name "name"')
-            self.failIf(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
+            self.failIf(self.schema['name'].rproperty('Workflow', 'String').indexed)
             self.failIf(self.index_exists('Workflow', 'name'))
             self.commit()
-            self.failUnless(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
+            self.failUnless(self.schema['name'].rdef('Workflow', 'String').indexed)
             self.failUnless(self.index_exists('Workflow', 'name'))
 
     def test_unique_change(self):
--- a/web/facet.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/facet.py	Wed Dec 09 12:22:21 2009 +0100
@@ -109,8 +109,8 @@
     if rel.optional in (opt, 'both'):
         # optional relation
         return ovar
-    if all(rschema.rproperty(s, o, 'cardinality')[cardidx] in '1+'
-           for s,o in rschema.iter_rdefs()):
+    if all(rdefs.cardinality[cardidx] in '1+'
+           for rdefs in rschema.rdefs.itervalues()):
         # mandatory relation without any restriction on the other variable
         for orel in ovar.stinfo['relations']:
             if rel is orel:
--- a/web/test/unittest_views_searchrestriction.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/test/unittest_views_searchrestriction.py	Wed Dec 09 12:22:21 2009 +0100
@@ -67,16 +67,16 @@
         select = self.parse('DISTINCT Any V,TN,L ORDERBY TN,L WHERE T nom TN, V connait T, T is Personne, V is CWUser,'
                             'NOT V in_state VS, VS name "published", V login L')
         rschema = self.schema['connait']
-        for s, o in rschema.iter_rdefs():
-            rschema.set_rproperty(s, o, 'cardinality', '++')
+        for rdefs in rschema.rdefs.values():
+            rdefs.cardinality =  '++'
         try:
             self.assertEquals(self._generate(select, 'in_state', 'subject', 'name'),
                               "DISTINCT Any A,B ORDERBY B WHERE V is CWUser, "
                               "NOT V in_state VS, VS name 'published', "
                               "V in_state A, A name B")
         finally:
-            for s, o in rschema.iter_rdefs():
-                rschema.set_rproperty(s, o, 'cardinality', '**')
+            for rdefs in rschema.rdefs.values():
+                rdefs.cardinality =  '**'
 
     def test_nonregr3(self):
         #'DISTINCT Any X,TMP,N WHERE P name TMP, X version_of P, P is Project, X is Version, not X in_state S,S name "published", X num N ORDERBY TMP,N'
--- a/web/uicfg.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/uicfg.py	Wed Dec 09 12:22:21 2009 +0100
@@ -351,6 +351,7 @@
         else:
             eid = None
             strict = False
+        cw = entity._cw
         for rschema, targetschemas, role in eschema.relation_definitions(True):
             # check category first, potentially lower cost than checking
             # permission which may imply rql queries
@@ -360,13 +361,14 @@
                     continue
                 rdef = rschema.role_rdef(eschema, tschema, role)
                 if not ((not strict and rdef.has_local_role(permission)) or
-                        rdef.has_perm(entity._cw, permission, fromeid=eid)):
+                        rdef.has_perm(cw, permission, fromeid=eid)):
                     continue
                 _targetschemas.append(tschema)
             if not _targetschemas:
                 continue
             targetschemas = _targetschemas
             if permission is not None:
+                rdef = eschema.rdef(rschema, targettype=targetschemas[0])
                 # tag allowing to hijack the permission machinery when
                 # permission is not verifiable until the entity is actually
                 # created...
@@ -374,25 +376,25 @@
                     yield (rschema, targetschemas, role)
                     continue
                 if rschema.final:
-                    if not eschema.rdef(rschema).has_perm(entity._cw, permission, fromeid=eid):
+                    if not rdef.has_perm(cw, permission, fromeid=eid):
                         continue
                 elif role == 'subject':
                     # on relation with cardinality 1 or ?, we need delete perm as well
                     # if the relation is already set
                     if (permission == 'add'
-                        and rschema.cardinality(eschema, targetschemas[0], role) in '1?'
+                        and rdef.role_cardinality(role) in '1?'
                         and eid and entity.related(rschema.type, role)
-                        and not rschema.has_perm(entity._cw, 'delete', fromeid=eid,
-                                                 toeid=entity.related(rschema.type, role)[0][0])):
+                        and not rdef.has_perm(cw, 'delete', fromeid=eid,
+                                              toeid=entity.related(rschema.type, role)[0][0])):
                         continue
                 elif role == 'object':
                     # on relation with cardinality 1 or ?, we need delete perm as well
                     # if the relation is already set
                     if (permission == 'add'
-                        and rschema.cardinality(targetschemas[0], eschema, role) in '1?'
+                        and rdef.role_cardinality(role) in '1?'
                         and eid and entity.related(rschema.type, role)
-                        and not rschema.has_perm(entity._cw, 'delete', toeid=eid,
-                                                 fromeid=entity.related(rschema.type, role)[0][0])):
+                        and not rdef.has_perm(cw, 'delete', toeid=eid,
+                                              fromeid=entity.related(rschema.type, role)[0][0])):
                         continue
             yield (rschema, targetschemas, role)
 
--- a/web/views/basecontrollers.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/views/basecontrollers.py	Wed Dec 09 12:22:21 2009 +0100
@@ -68,7 +68,7 @@
 
     def publish(self, rset=None):
         """log in the instance"""
-        if self._cw.config['auth-mode'] == 'http':
+        if self._cw.vreg.config['auth-mode'] == 'http':
             # HTTP authentication
             raise ExplicitLogin()
         else:
--- a/web/views/navigation.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/views/navigation.py	Wed Dec 09 12:22:21 2009 +0100
@@ -174,8 +174,8 @@
 
 def paginate(view, show_all_option=True, w=None, page_size=None, rset=None):
     if rset is None:
-        rset = view.rset
-    limit_rset_using_paged_nav(view, view.req, rset, w or view.w,
+        rset = view.cw_rset
+    limit_rset_using_paged_nav(view, view._cw, rset, w or view.w,
                                not view.need_navigation, show_all_option,
                                page_size=page_size)
 View.paginate = paginate
--- a/web/views/primary.py	Wed Dec 09 12:20:05 2009 +0100
+++ b/web/views/primary.py	Wed Dec 09 12:22:21 2009 +0100
@@ -255,8 +255,8 @@
         # nb: rset retreived using entity.related with limit + 1 if any
         # because of that, we known that rset.printable_rql() will return
         # rql with no limit set anyway (since it's handled manually)
-        if 'dispctrl' in self.extra_kwargs:
-            limit = self.extra_kwargs['dispctrl'].get('limit')
+        if 'dispctrl' in self.cw_extra_kwargs:
+            limit = self.cw_extra_kwargs['dispctrl'].get('limit')
         else:
             limit = None
         if limit is None or self.cw_rset.rowcount <= limit: