cw 3.6 api update
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Tue, 08 Dec 2009 16:50:36 +0100
changeset 4045 f4a52abb6f4f
parent 4044 3876c894e018
child 4046 93d69d5dd3fa
cw 3.6 api update
schema.py
view.py
web/views/ajaxedit.py
web/views/bookmark.py
web/views/csvexport.py
web/views/editcontroller.py
web/views/editforms.py
web/views/editviews.py
web/views/emailaddress.py
web/views/facets.py
web/views/magicsearch.py
web/views/management.py
web/views/navigation.py
web/views/plots.py
web/views/schema.py
web/views/sparql.py
web/views/startup.py
web/views/tableview.py
web/views/urlrewrite.py
web/views/wdoc.py
web/views/xmlrss.py
--- a/schema.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/schema.py	Tue Dec 08 16:50:36 2009 +0100
@@ -437,7 +437,7 @@
         elif subjtype:
             for tschema in self.targets(subjtype, 'subject'):
                 rdef = self.rdef(subjtype, tschema)
-                if not rdef.has_perm(action, req, **kwargs):
+                if not rdef.has_perm(session, action, **kwargs):
                     return False
         elif objtype:
             for tschema in self.targets(objtype, 'object'):
--- a/view.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/view.py	Tue Dec 08 16:50:36 2009 +0100
@@ -201,7 +201,7 @@
         return True
 
     def is_primary(self):
-        return self.extra_kwargs.get('is_primary', self.__regid__ == 'primary')
+        return self.cw_extra_kwargs.get('is_primary', self.__regid__ == 'primary')
 
     def url(self):
         """return the url associated with this view. Should not be
@@ -214,7 +214,7 @@
         coltypes = rset.column_types(0)
         if len(coltypes) == 1:
             etype = iter(coltypes).next()
-            if not self._cw.schema.eschema(etype).final:
+            if not self._cw.vreg.schema.eschema(etype).final:
                 if len(rset) == 1:
                     entity = rset.get_entity(0, 0)
                     return entity.absolute_url(vid=self.__regid__)
--- a/web/views/ajaxedit.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/ajaxedit.py	Tue Dec 08 16:50:36 2009 +0100
@@ -32,7 +32,7 @@
         self.target = target or self._cw.form['target']
         self.etype = etype or self._cw.form.get('etype')
         entity = self.cw_rset.get_entity(row, col)
-        rschema = self._cw.schema.rschema(self.rtype)
+        rschema = self._cw.vreg.schema.rschema(self.rtype)
         if not self.etype:
             if self.target == 'object':
                 etypes = rschema.objects(entity.e_schema)
--- a/web/views/bookmark.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/bookmark.py	Tue Dec 08 16:50:36 2009 +0100
@@ -70,8 +70,8 @@
             return
         box = BoxWidget(req._(self.title), self.__regid__)
         box.listing_class = 'sideBox'
-        rschema = self._cw.schema.rschema(self.rtype)
-        eschema = self._cw.schema.eschema(self.etype)
+        rschema = self._cw.vreg.schema.rschema(self.rtype)
+        eschema = self._cw.vreg.schema.eschema(self.etype)
         candelete = rschema.has_perm(req, 'delete', toeid=ueid)
         if candelete:
             req.add_js( ('cubicweb.ajax.js', 'cubicweb.bookmarks.js') )
--- a/web/views/csvexport.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/csvexport.py	Tue Dec 08 16:50:36 2009 +0100
@@ -40,7 +40,7 @@
         writer = self.csvwriter()
         writer.writerow(self.columns_labels())
         rset, descr = self.cw_rset, self.cw_rset.description
-        eschema = self._cw.schema.eschema
+        eschema = self._cw.vreg.schema.eschema
         for rowindex, row in enumerate(rset):
             csvrow = []
             for colindex, val in enumerate(row):
--- a/web/views/editcontroller.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/editcontroller.py	Tue Dec 08 16:50:36 2009 +0100
@@ -178,7 +178,7 @@
                     or
                     (field.role == 'object' and eschema.has_object_relation(field.name))):
                     continue
-                rschema = self._cw.schema.rschema(field.name)
+                rschema = self._cw.vreg.schema.rschema(field.name)
                 if rschema.is_final():
                     rqlquery.kwargs[attr] = value
                     rqlquery.edited.append('X %s %%(%s)s' % (attr, attr))
@@ -246,7 +246,7 @@
         if values is None or values == origvalues:
             return # not edited / not modified / to do later
         etype = entity.e_schema
-        rschema = self._cw.schema.rschema(field.name)
+        rschema = self._cw.vreg.schema.rschema(field.name)
         if field.role == 'subject':
             desttype = rschema.objects(etype)[0]
             card = rschema.rproperty(etype, desttype, 'cardinality')[0]
--- a/web/views/editforms.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/editforms.py	Tue Dec 08 16:50:36 2009 +0100
@@ -132,8 +132,8 @@
         """display field to edit entity's `rtype` relation on click"""
         assert rtype
         assert role in ('subject', 'object'), '%s is not an acceptable role value' % role
-        self.req.add_js('cubicweb.edition.js')
-        self.req.add_css('cubicweb.form.css')
+        self._cw.add_js('cubicweb.edition.js')
+        self._cw.add_css('cubicweb.form.css')
         if default is None:
             default = xml_escape(self._cw._('<no value>'))
         schema = self._cw.vreg.schema
--- a/web/views/editviews.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/editviews.py	Tue Dec 08 16:50:36 2009 +0100
@@ -80,7 +80,7 @@
     def cell_call(self, row, col):
         entity = self.cw_rset.get_entity(row, col)
         relname, target = self._cw.form.get('relation').rsplit('_', 1)
-        rschema = self._cw.schema.rschema(relname)
+        rschema = self._cw.vreg.schema.rschema(relname)
         hidden = 'hidden' in self._cw.form
         is_cell = 'is_cell' in self._cw.form
         self.w(self.build_unrelated_select_div(entity, rschema, target,
@@ -101,7 +101,7 @@
         options.append('<option>%s %s</option>' % (self._cw._('select a'), etypes))
         options += self._get_select_options(entity, rschema, target)
         options += self._get_search_options(entity, rschema, target, targettypes)
-        if 'Basket' in self._cw.schema: # XXX
+        if 'Basket' in self._cw.vreg.schema: # XXX
             options += self._get_basket_options(entity, rschema, target, targettypes)
         relname, target = self._cw.form.get('relation').rsplit('_', 1)
         return u"""\
--- a/web/views/emailaddress.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/emailaddress.py	Tue Dec 08 16:50:36 2009 +0100
@@ -38,7 +38,7 @@
         else:
             pemaileid = None
         try:
-            emailof = 'use_email' in self._cw.schema and entity.reverse_use_email or ()
+            emailof = 'use_email' in self._cw.vreg.schema and entity.reverse_use_email or ()
             emailof = [e for e in emailof if not e.eid == pemaileid]
         except Unauthorized:
             emailof = []
--- a/web/views/facets.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/facets.py	Tue Dec 08 16:50:36 2009 +0100
@@ -102,7 +102,7 @@
             rqlst.recover()
 
     def display_bookmark_link(self, rset):
-        eschema = self._cw.schema.eschema('Bookmark')
+        eschema = self._cw.vreg.schema.eschema('Bookmark')
         if eschema.has_perm(self._cw, 'add'):
             bk_path = 'view?rql=%s' % rset.printable_rql()
             bk_title = self._cw._('my custom search')
--- a/web/views/magicsearch.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/magicsearch.py	Tue Dec 08 16:50:36 2009 +0100
@@ -172,7 +172,7 @@
     priority = 2
     def preprocess_query(self, uquery):
         rqlst = parse(uquery, print_errors=False)
-        schema = self._cw.schema
+        schema = self._cw.vreg.schema
         # rql syntax tree will be modified in place if necessary
         translate_rql_tree(rqlst, trmap(self._cw.config, schema, self._cw.lang),
                            schema)
@@ -250,9 +250,9 @@
         searchop = ''
         if '%' in searchstr:
             if rtype:
-                possible_etypes = self._cw.schema.rschema(rtype).objects(etype)
+                possible_etypes = self._cw.vreg.schema.rschema(rtype).objects(etype)
             else:
-                possible_etypes = [self._cw.schema.eschema(etype)]
+                possible_etypes = [self._cw.vreg.schema.eschema(etype)]
             if searchattr or len(possible_etypes) == 1:
                 searchattr = searchattr or possible_etypes[0].main_attribute()
                 searchop = 'LIKE '
@@ -276,10 +276,10 @@
         """Specific process for three words query (case (3) of preprocess_rql)
         """
         etype = self._get_entity_type(word1)
-        eschema = self._cw.schema.eschema(etype)
+        eschema = self._cw.vreg.schema.eschema(etype)
         rtype = self._get_attribute_name(word2, eschema)
         # expand shortcut if rtype is a non final relation
-        if not self._cw.schema.rschema(rtype).final:
+        if not self._cw.vreg.schema.rschema(rtype).final:
             return self._expand_shortcut(etype, rtype, word3)
         if '%' in word3:
             searchop = 'LIKE '
--- a/web/views/management.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/management.py	Tue Dec 08 16:50:36 2009 +0100
@@ -91,7 +91,7 @@
         self.schema_definition(entity.e_schema)
         self.w('<h2>%s</h2>' % _('manage security'))
         # ownership information
-        if self._cw.schema.rschema('owned_by').has_perm(self._cw, 'add',
+        if self._cw.vreg.schema.rschema('owned_by').has_perm(self._cw, 'add',
                                                     fromeid=entity.eid):
             self.owned_by_edit_form(entity)
         else:
@@ -99,7 +99,7 @@
         # cwpermissions
         if 'require_permission' in entity.e_schema.subject_relations():
             w('<h3>%s</h3>' % _('permissions for this entity'))
-            reqpermschema = self._cw.schema.rschema('require_permission')
+            reqpermschema = self._cw.vreg.schema.rschema('require_permission')
             self.require_permission_information(entity, reqpermschema)
             if reqpermschema.has_perm(self._cw, 'add', fromeid=entity.eid):
                 self.require_permission_edit_form(entity)
@@ -113,7 +113,7 @@
                                          domid='ownership%s' % entity.eid,
                                          __redirectvid='security',
                                          __redirectpath=entity.rest_path())
-        field = guess_field(entity.e_schema, self._cw.schema.rschema('owned_by'))
+        field = guess_field(entity.e_schema, self._cw.vreg.schema.rschema('owned_by'))
         form.append_field(field)
         self.w(form.render(rendervalues=dict(display_progress_div=False)))
 
@@ -173,15 +173,15 @@
         permnames = getattr(entity, '__permissions__', None)
         cwpermschema = newperm.e_schema
         if permnames is not None:
-            field = guess_field(cwpermschema, self._cw.schema.rschema('name'),
+            field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('name'),
                                 widget=wdgs.Select({'size': 1}),
                                 choices=permnames)
         else:
-            field = guess_field(cwpermschema, self._cw.schema.rschema('name'))
+            field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('name'))
         form.append_field(field)
-        field = guess_field(cwpermschema, self._cw.schema.rschema('label'))
+        field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('label'))
         form.append_field(field)
-        field = guess_field(cwpermschema, self._cw.schema.rschema('require_group'))
+        field = guess_field(cwpermschema, self._cw.vreg.schema.rschema('require_group'))
         form.append_field(field)
         renderer = self._cw.vreg['formrenderers'].select(
             'htable', self._cw, rset=None, display_progress_div=False)
--- a/web/views/navigation.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/navigation.py	Tue Dec 08 16:50:36 2009 +0100
@@ -66,7 +66,7 @@
                     return u''
                 entity = rset.get_entity(row, col)
                 return entity.printable_value(attrname, format='text/plain')
-        elif self._cw.schema.eschema(rset.description[0][col]).final:
+        elif self._cw.vreg.schema.eschema(rset.description[0][col]).final:
             def index_display(row):
                 return unicode(rset[row][col])
         else:
@@ -84,7 +84,7 @@
         w = self.w
         rset = self.cw_rset
         page_size = self.page_size
-        rschema = self._cw.schema.rschema
+        rschema = self._cw.vreg.schema.rschema
         # attrname = the name of attribute according to which the sort
         # is done if any
         for sorterm in rset.syntax_tree().children[0].orderby:
--- a/web/views/plots.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/plots.py	Tue Dec 08 16:50:36 2009 +0100
@@ -179,7 +179,7 @@
 
         def _guess_vid(self, row):
             etype = self.cw_rset.description[row][0]
-            if self._cw.schema.eschema(etype).final:
+            if self._cw.vreg.schema.eschema(etype).final:
                 return 'final'
             return 'textincontext'
 
--- a/web/views/schema.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/schema.py	Tue Dec 08 16:50:36 2009 +0100
@@ -90,7 +90,7 @@
         formparams['sec'] = self.__regid__
         if not skiptypes:
             formparams['skipmeta'] = u'0'
-        schema = self._cw.schema
+        schema = self._cw.vreg.schema
         # compute entities
         entities = sorted(eschema for eschema in schema.entities()
                           if not (eschema.final or eschema in skiptypes))
@@ -139,7 +139,7 @@
                 url,  self._cw.external_resource('UP_ICON'), _('up')))
             self.w(u'</h3>')
             self.w(u'<div style="margin: 0px 1.5em">')
-            self._cw.schema_definition(eschema, link=False)
+            self._cw.vreg.schema_definition(eschema, link=False)
             # display entity attributes only if they have some permissions modified
             modified_attrs = []
             for attr, etype in  eschema.attribute_definitions():
@@ -151,7 +151,7 @@
                 self.w(u'<div style="margin: 0px 6em">')
                 for attr in  modified_attrs:
                     self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type)))
-                    self._cw.schema_definition(attr, link=False)
+                    self._cw.vreg.schema_definition(attr, link=False)
             self.w(u'</div>')
 
     def display_relations(self, relations, formparams):
@@ -175,7 +175,7 @@
                 _('object_plural:'),
                 ', '.join(str(obj) for obj in rschema.objects()),
                 ', '.join(_(str(obj)) for obj in rschema.objects())))
-            self._cw.schema_definition(rschema, link=False)
+            self._cw.vreg.schema_definition(rschema, link=False)
             self.w(u'</div>')
 
 
@@ -184,7 +184,7 @@
 
     def call(self):
         viewer = SchemaViewer(self._cw)
-        layout = viewer.visit_schema(self._cw.schema, display_relations=True,
+        layout = viewer.visit_schema(self._cw.vreg.schema, display_relations=True,
                                      skiptypes=skip_types(self._cw))
         self.w(uilib.ureport_as_html(layout))
 
@@ -384,7 +384,7 @@
     def _generate(self, tmpfile):
         """display global schema information"""
         print 'skipedtypes', skip_types(self._cw)
-        visitor = FullSchemaVisitor(self._cw, self._cw.schema,
+        visitor = FullSchemaVisitor(self._cw, self._cw.vreg.schema,
                                     skiptypes=skip_types(self._cw))
         s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
 
--- a/web/views/sparql.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/sparql.py	Tue Dec 08 16:50:36 2009 +0100
@@ -44,7 +44,7 @@
         vid = self._cw.form.get('resultvid', 'table')
         if sparql:
             try:
-                qinfo = Sparql2rqlTranslator(self._cw.schema).translate(sparql)
+                qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql)
             except rql.TypeResolverException, ex:
                 self.w(self._cw._('can not resolve entity types:') + u' ' + unicode('ex'))
             except UnsupportedQuery:
@@ -102,7 +102,7 @@
 
     def cell_binding(self, row, col, varname):
         celltype = self.cw_rset.description[row][col]
-        if self._cw.schema.eschema(celltype).final:
+        if self._cw.vreg.schema.eschema(celltype).final:
             cellcontent = self.view('cell', self.cw_rset, row=row, col=col)
             return E.binding(E.literal(cellcontent,
                                        datatype=xmlschema(celltype)),
--- a/web/views/startup.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/startup.py	Tue Dec 08 16:50:36 2009 +0100
@@ -45,7 +45,7 @@
     def _main_index(self):
         req = self._cw
         manager = req.user.matching_groups('managers')
-        if not manager and 'Card' in self._cw.schema:
+        if not manager and 'Card' in self._cw.vreg.schema:
             rset = self._cw.execute('Card X WHERE X wikiid "index"')
         else:
             rset = None
@@ -55,7 +55,7 @@
             self.entities()
             self.w(u'<div class="hr">&#160;</div>')
             self.startup_views()
-        if manager and 'Card' in self._cw.schema:
+        if manager and 'Card' in self._cw.vreg.schema:
             self.w(u'<div class="hr">&#160;</div>')
             if rset:
                 href = rset.get_entity(0, 0).absolute_url(vid='edition')
@@ -91,7 +91,7 @@
                 xml_escape(v.url()), xml_escape(self._cw._(v.title).capitalize())))
 
     def entities(self):
-        schema = self._cw.schema
+        schema = self._cw.vreg.schema
         self.w(u'<h4>%s</h4>\n' % self._cw._('The repository holds the following entities'))
         manager = self._cw.user.matching_groups('managers')
         self.w(u'<table class="startup">')
@@ -154,5 +154,5 @@
     title = _('view_index')
 
     def display_folders(self):
-        return 'Folder' in self._cw.schema and self._cw.execute('Any COUNT(X) WHERE X is Folder')[0][0]
+        return 'Folder' in self._cw.vreg.schema and self._cw.execute('Any COUNT(X) WHERE X is Folder')[0][0]
 
--- a/web/views/tableview.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/tableview.py	Tue Dec 08 16:50:36 2009 +0100
@@ -262,7 +262,7 @@
         :param cellvid: cell view (defaults to 'outofcontext')
         """
         etype, val = self.cw_rset.description[row][col], self.cw_rset[row][col]
-        if val is not None and not self._cw.schema.eschema(etype).final:
+        if val is not None and not self._cw.vreg.schema.eschema(etype).final:
             e = self.cw_rset.get_entity(row, col)
             e.view(cellvid or 'outofcontext', w=self.w)
         elif val is None:
--- a/web/views/urlrewrite.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/urlrewrite.py	Tue Dec 08 16:50:36 2009 +0100
@@ -207,9 +207,9 @@
                 continue
             if isinstance(inputurl, basestring):
                 if inputurl == uri:
-                    return callback(inputurl, uri, req, self._cw.schema)
+                    return callback(inputurl, uri, req, self._cw.vreg.schema)
             elif inputurl.match(uri): # it's a regexp
-                return callback(inputurl, uri, req, self._cw.schema)
+                return callback(inputurl, uri, req, self._cw.vreg.schema)
         else:
             self.debug("no schemabased rewrite rule found for %s", uri)
             raise KeyError(uri)
--- a/web/views/wdoc.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/wdoc.py	Tue Dec 08 16:50:36 2009 +0100
@@ -246,7 +246,7 @@
     title = _('Help')
 
     def url(self):
-        return self.req.build_url('doc/main')
+        return self._cw.build_url('doc/main')
 
 class ChangeLogAction(action.Action):
     __regid__ = 'changelog'
--- a/web/views/xmlrss.py	Tue Dec 08 16:46:56 2009 +0100
+++ b/web/views/xmlrss.py	Tue Dec 08 16:50:36 2009 +0100
@@ -76,7 +76,7 @@
     def call(self):
         w = self.w
         rset, descr = self.cw_rset, self.cw_rset.description
-        eschema = self._cw.schema.eschema
+        eschema = self._cw.vreg.schema.eschema
         labels = self.columns_labels(tr=False)
         w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding)
         w(u'<%s query="%s">\n' % (self.xml_root, xml_escape(rset.printable_rql())))