backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Aug 2009 12:20:50 +0200
changeset 2728 d4689ba782a4
parent 2726 03e7a6efd960 (diff)
parent 2727 5275d015834c (current diff)
child 2729 d3dbd135f319
backport stable
common/mixins.py
--- a/README	Fri Aug 07 12:20:37 2009 +0200
+++ b/README	Fri Aug 07 12:20:50 2009 +0200
@@ -1,18 +1,27 @@
-CubicWeb semantic web framework 
+CubicWeb semantic web framework
 ===============================
- 
+
 Install
 -------
-From the source distribution, extract the tarball and run ::
-  
-    python setup.py install
-  
-For deb and rpm packages, use the tools recommended by your distribution.
+
+More details at http://www.cubicweb.org/doc/en/admin/setup
+
+Getting started
+---------------
+
+Execute:
 
-  
+ apt-get install cubicweb cubicweb-dev cubicweb-blog
+ cubicweb-ctl create blog myblog
+ cubicweb-ctl start -D myblog
+ sensible-browser http://localhost:8080/
+
+Details at http://www.cubicweb.org/doc/en/intro/tutorial/blog-in-five-minutes
+
 Documentation
 -------------
-Look in the doc/ subdirectory.
+
+Look in the doc/ subdirectory or read http://www.cubicweb.org/doc/en/
 
 
 
--- a/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -100,20 +100,39 @@
                          [(etype,)])
         return self.decorate_rset(rset)
 
+    def empty_rset(self):
+        """return a result set for the given eid without doing actual query
+        (we have the eid, we can suppose it exists and user has access to the
+        entity)
+        """
+        from cubicweb.rset import ResultSet
+        return self.decorate_rset(ResultSet([], 'Any X WHERE X eid -1'))
+
     def entity_from_eid(self, eid, etype=None):
-        rset = self.eid_rset(eid, etype)
-        if rset:
-            return rset.get_entity(0, 0)
-        else:
-            return None
+        try:
+            return self.entity_cache(eid)
+        except KeyError:
+            rset = self.eid_rset(eid, etype)
+            entity = rset.get_entity(0, 0)
+            self.set_entity_cache(entity)
+            return entity
 
+    def entity_cache(self, eid):
+        raise KeyError
+    def set_entity_cache(self, entity):
+        pass
     # url generation methods ##################################################
 
-    def build_url(self, method, base_url=None, **kwargs):
+    def build_url(self, *args, **kwargs):
         """return an absolute URL using params dictionary key/values as URL
         parameters. Values are automatically URL quoted, and the
         publishing method to use may be specified or will be guessed.
         """
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+        method = args[0]
+        base_url = kwargs.pop('base_url', None)
         if base_url is None:
             base_url = self.base_url()
         if '_restpath' in kwargs:
@@ -193,7 +212,7 @@
     # abstract methods to override according to the web front-end #############
 
     def base_url(self):
-        """return the root url of the application"""
+        """return the root url of the instance"""
         raise NotImplementedError
 
     def decorate_rset(self, rset):
@@ -298,3 +317,49 @@
 def underline_title(title, car='-'):
     return title+'\n'+(car*len(title))
 
+
+class CubicWebEventManager(object):
+    """simple event / callback manager.
+
+    Typical usage to register a callback::
+
+      >>> from cubicweb import CW_EVENT_MANAGER
+      >>> CW_EVENT_MANAGER.bind('after-registry-reload', mycallback)
+
+    Typical usage to emit an event::
+
+      >>> from cubicweb import CW_EVENT_MANAGER
+      >>> CW_EVENT_MANAGER.emit('after-registry-reload')
+
+    emit() accepts an additional context parameter that will be passed
+    to the callback if specified (and only in that case)
+    """
+    def __init__(self):
+        self.callbacks = {}
+
+    def bind(self, event, callback, *args, **kwargs):
+        self.callbacks.setdefault(event, []).append( (callback, args, kwargs) )
+
+    def emit(self, event, context=None):
+        for callback, args, kwargs in self.callbacks.get(event, ()):
+            if context is None:
+                callback(*args, **kwargs)
+            else:
+                callback(context, *args, **kwargs)
+
+CW_EVENT_MANAGER = CubicWebEventManager()
+
+def onevent(event):
+    """decorator to ease event / callback binding
+
+    >>> from cubicweb import onevent
+    >>> @onevent('before-registry-reload')
+    ... def mycallback():
+    ...     print 'hello'
+    ...
+    >>>
+    """
+    def _decorator(func):
+        CW_EVENT_MANAGER.bind(event, func)
+        return func
+    return _decorator
--- a/__pkginfo__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/__pkginfo__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,7 +7,7 @@
 distname = "cubicweb"
 modname = "cubicweb"
 
-numversion = (3, 3, 5)
+numversion = (3, 4, 0)
 version = '.'.join(str(num) for num in numversion)
 
 license = 'LGPL v2'
--- a/_exceptions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/_exceptions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -129,6 +129,9 @@
 class UnknownProperty(RegistryException):
     """property found in database but unknown in registry"""
 
+class RegistryOutOfDate(RegistryException):
+    """raised when a source file modification is detected"""
+
 # query exception #############################################################
 
 class QueryError(CubicWebRuntimeError):
--- a/appobject.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/appobject.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,6 @@
-"""Base class for dynamically loaded objects manipulated in the web interface
+"""Base class for dynamically loaded objects accessible through the vregistry.
+
+You'll also find some convenience classes to build selectors.
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -7,20 +9,23 @@
 """
 __docformat__ = "restructuredtext en"
 
+import types
+from logging import getLogger
 from datetime import datetime, timedelta, time
 
 from logilab.common.decorators import classproperty
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
+from logilab.common.logging_ext import set_log_methods
 
 from rql.nodes import VariableRef, SubQuery
 from rql.stmts import Union, Select
 
 from cubicweb import Unauthorized, NoSelectableObject
-from cubicweb.vregistry import VObject, AndSelector
-from cubicweb.selectors import yes
 from cubicweb.utils import UStringIO, ustrftime, strptime, todate, todatetime
 
 ONESECOND = timedelta(0, 1, 0)
+CACHE_REGISTRY = {}
+
 
 class Cache(dict):
     def __init__(self):
@@ -29,37 +34,267 @@
         self.cache_creation_date = _now
         self.latest_cache_lookup = _now
 
-CACHE_REGISTRY = {}
+
+# selector base classes and operations ########################################
+
+def objectify_selector(selector_func):
+    """convenience decorator for simple selectors where a class definition
+    would be overkill::
+
+        @objectify_selector
+        def yes(cls, *args, **kwargs):
+            return 1
+
+    """
+    return type(selector_func.__name__, (Selector,),
+                {'__call__': lambda self, *args, **kwargs: selector_func(*args, **kwargs)})
+
+
+def _instantiate_selector(selector):
+    """ensures `selector` is a `Selector` instance
+
+    NOTE: This should only be used locally in build___select__()
+    XXX: then, why not do it ??
+    """
+    if isinstance(selector, types.FunctionType):
+        return objectify_selector(selector)()
+    if isinstance(selector, type) and issubclass(selector, Selector):
+        return selector()
+    return selector
+
+
+class Selector(object):
+    """base class for selector classes providing implementation
+    for operators ``&`` and ``|``
+
+    This class is only here to give access to binary operators, the
+    selector logic itself should be implemented in the __call__ method
+
+
+    a selector is called to help choosing the correct object for a
+    particular context by returning a score (`int`) telling how well
+    the class given as first argument apply to the given context.
+
+    0 score means that the class doesn't apply.
+    """
+
+    @property
+    def func_name(self):
+        # backward compatibility
+        return self.__class__.__name__
+
+    def search_selector(self, selector):
+        """search for the given selector or selector instance in the selectors
+        tree. Return it of None if not found
+        """
+        if self is selector:
+            return self
+        if isinstance(selector, type) and isinstance(self, selector):
+            return self
+        return None
+
+    def __str__(self):
+        return self.__class__.__name__
+
+    def __and__(self, other):
+        return AndSelector(self, other)
+    def __rand__(self, other):
+        return AndSelector(other, self)
+
+    def __or__(self, other):
+        return OrSelector(self, other)
+    def __ror__(self, other):
+        return OrSelector(other, self)
+
+    def __invert__(self):
+        return NotSelector(self)
+
+    # XXX (function | function) or (function & function) not managed yet
+
+    def __call__(self, cls, *args, **kwargs):
+        return NotImplementedError("selector %s must implement its logic "
+                                   "in its __call__ method" % self.__class__)
+
+
+class MultiSelector(Selector):
+    """base class for compound selector classes"""
+
+    def __init__(self, *selectors):
+        self.selectors = self.merge_selectors(selectors)
+
+    def __str__(self):
+        return '%s(%s)' % (self.__class__.__name__,
+                           ','.join(str(s) for s in self.selectors))
+
+    @classmethod
+    def merge_selectors(cls, selectors):
+        """deal with selector instanciation when necessary and merge
+        multi-selectors if possible:
 
-class AppRsetObject(VObject):
-    """This is the base class for CubicWeb application objects
-    which are selected according to a request and result set.
+        AndSelector(AndSelector(sel1, sel2), AndSelector(sel3, sel4))
+        ==> AndSelector(sel1, sel2, sel3, sel4)
+        """
+        merged_selectors = []
+        for selector in selectors:
+            try:
+                selector = _instantiate_selector(selector)
+            except:
+                pass
+            #assert isinstance(selector, Selector), selector
+            if isinstance(selector, cls):
+                merged_selectors += selector.selectors
+            else:
+                merged_selectors.append(selector)
+        return merged_selectors
+
+    def search_selector(self, selector):
+        """search for the given selector or selector instance in the selectors
+        tree. Return it of None if not found
+        """
+        for childselector in self.selectors:
+            if childselector is selector:
+                return childselector
+            found = childselector.search_selector(selector)
+            if found is not None:
+                return found
+        return None
+
+
+class AndSelector(MultiSelector):
+    """and-chained selectors (formerly known as chainall)"""
+    def __call__(self, cls, *args, **kwargs):
+        score = 0
+        for selector in self.selectors:
+            partscore = selector(cls, *args, **kwargs)
+            if not partscore:
+                return 0
+            score += partscore
+        return score
+
 
-    Classes are kept in the vregistry and instantiation is done at selection
-    time.
+class OrSelector(MultiSelector):
+    """or-chained selectors (formerly known as chainfirst)"""
+    def __call__(self, cls, *args, **kwargs):
+        for selector in self.selectors:
+            partscore = selector(cls, *args, **kwargs)
+            if partscore:
+                return partscore
+        return 0
+
+class NotSelector(Selector):
+    """negation selector"""
+    def __init__(self, selector):
+        self.selector = selector
+
+    def __call__(self, cls, *args, **kwargs):
+        score = self.selector(cls, *args, **kwargs)
+        return int(not score)
+
+    def __str__(self):
+        return 'NOT(%s)' % super(NotSelector, self).__str__()
+
+
+class yes(Selector):
+    """return arbitrary score
+
+    default score of 0.5 so any other selector take precedence
+    """
+    def __init__(self, score=0.5):
+        self.score = score
+
+    def __call__(self, *args, **kwargs):
+        return self.score
+
+
+# the base class for all appobjects ############################################
+
+class AppObject(object):
+    """This is the base class for CubicWeb application objects which are
+    selected according to a context (usually at least a request and a result
+    set).
+
+    Concrete application objects classes are designed to be loaded by the
+    vregistry and should be accessed through it, not by direct instantiation.
+
+    The following attributes should be set on concret appobject classes:
+    :__registry__:
+      name of the registry for this object (string like 'views',
+      'templates'...)
+    :id:
+      object's identifier in the registry (string like 'main',
+      'primary', 'folder_box')
+    :__select__:
+      class'selector
+
+    Moreover, the `__abstract__` attribute may be set to True to indicate
+    that a appobject is abstract and should not be registered.
 
     At registration time, the following attributes are set on the class:
     :vreg:
-      the application's registry
+      the instance's registry
     :schema:
-      the application's schema
+      the instance's schema
     :config:
-      the application's configuration
+      the instance's configuration
 
-    At instantiation time, the following attributes are set on the instance:
+    At selection time, the following attributes are set on the instance:
     :req:
       current request
     :rset:
-      result set on which the object is applied
+      context result set or None
+    :row:
+      if a result set is set and the context is about a particular cell in the
+      result set, and not the result set as a whole, specify the row number we
+      are interested in, else None
+    :col:
+      if a result set is set and the context is about a particular cell in the
+      result set, and not the result set as a whole, specify the col number we
+      are interested in, else None
     """
+    __registry__ = None
+    id = None
     __select__ = yes()
 
     @classmethod
-    def registered(cls, vreg):
-        super(AppRsetObject, cls).registered(vreg)
-        cls.vreg = vreg
-        cls.schema = vreg.schema
-        cls.config = vreg.config
+    def classid(cls):
+        """returns a unique identifier for the appobject"""
+        return '%s.%s' % (cls.__module__, cls.__name__)
+
+    # XXX bw compat code
+    @classmethod
+    def build___select__(cls):
+        for klass in cls.mro():
+            if klass.__name__ == 'AppObject':
+                continue # the bw compat __selector__ is there
+            klassdict = klass.__dict__
+            if ('__select__' in klassdict and '__selectors__' in klassdict
+                and '__selgenerated__' not in klassdict):
+                raise TypeError("__select__ and __selectors__ can't be used together on class %s" % cls)
+            if '__selectors__' in klassdict and '__selgenerated__' not in klassdict:
+                cls.__selgenerated__ = True
+                # case where __selectors__ is defined locally (but __select__
+                # is in a parent class)
+                selectors = klassdict['__selectors__']
+                if len(selectors) == 1:
+                    # micro optimization: don't bother with AndSelector if there's
+                    # only one selector
+                    select = _instantiate_selector(selectors[0])
+                else:
+                    select = AndSelector(*selectors)
+                cls.__select__ = select
+
+    @classmethod
+    def registered(cls, registry):
+        """called by the registry when the appobject has been registered.
+
+        It must return the object that will be actually registered (this may be
+        the right hook to create an instance for example). By default the
+        appobject is returned without any transformation.
+        """
+        cls.build___select__()
+        cls.vreg = registry.vreg
+        cls.schema = registry.schema
+        cls.config = registry.config
         cls.register_properties()
         return cls
 
@@ -67,15 +302,6 @@
     def vreg_initialization_completed(cls):
         pass
 
-    @classmethod
-    def selected(cls, *args, **kwargs):
-        """by default web app objects are usually instantiated on
-        selection according to a request, a result set, and optional
-        row and col
-        """
-        assert len(args) <= 2
-        return cls(*args, **kwargs)
-
     # Eproperties definition:
     # key: id of the property (the actual CWProperty key is build using
     #      <registry name>.<obj id>.<property id>
@@ -101,7 +327,7 @@
         return '%s.%s.%s' % (cls.__registry__, cls.id, propid)
 
     @classproperty
-    @obsolete('use __select__ and & or | operators')
+    @deprecated('use __select__ and & or | operators')
     def __selectors__(cls):
         selector = cls.__select__
         if isinstance(selector, AndSelector):
@@ -111,7 +337,7 @@
         return selector
 
     def __init__(self, req=None, rset=None, row=None, col=None, **extra):
-        super(AppRsetObject, self).__init__()
+        super(AppObject, self).__init__()
         self.req = req
         self.rset = rset
         self.row = row
@@ -151,7 +377,8 @@
         # try to get page boundaries from the navigation component
         # XXX we should probably not have a ref to this component here (eg in
         #     cubicweb.common)
-        nav = self.vreg.select_component('navigation', self.req, self.rset)
+        nav = self.vreg['components'].select_object('navigation', self.req,
+                                                    rset=self.rset)
         if nav:
             start, stop = nav.page_boundaries()
             rql = self._limit_offset_rql(stop - start, start)
@@ -187,9 +414,11 @@
             rqlst.parent = None
         return rql
 
-    def view(self, __vid, rset=None, __fallback_vid=None, **kwargs):
+    def view(self, __vid, rset=None, __fallback_oid=None, __registry='views',
+             **kwargs):
         """shortcut to self.vreg.view method avoiding to pass self.req"""
-        return self.vreg.view(__vid, self.req, rset, __fallback_vid, **kwargs)
+        return self.vreg[__registry].render(__vid, self.req, __fallback_oid,
+                                            rset=rset, **kwargs)
 
     def initialize_varmaker(self):
         varmaker = self.req.get_page_data('rql_varmaker')
@@ -202,11 +431,18 @@
 
     controller = 'view'
 
-    def build_url(self, method=None, **kwargs):
+    def build_url(self, *args, **kwargs):
         """return an absolute URL using params dictionary key/values as URL
         parameters. Values are automatically URL quoted, and the
         publishing method to use may be specified or will be guessed.
         """
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        if args:
+            assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+            method = args[0]
+        else:
+            method = None
         # XXX I (adim) think that if method is passed explicitly, we should
         #     not try to process it and directly call req.build_url()
         if method is None:
@@ -267,7 +503,7 @@
         return output.getvalue()
 
     def format_date(self, date, date_format=None, time=False):
-        """return a string for a date time according to application's
+        """return a string for a date time according to instance's
         configuration
         """
         if date:
@@ -280,7 +516,7 @@
         return u''
 
     def format_time(self, time):
-        """return a string for a time according to application's
+        """return a string for a time according to instance's
         configuration
         """
         if time:
@@ -288,7 +524,7 @@
         return u''
 
     def format_float(self, num):
-        """return a string for floating point number according to application's
+        """return a string for floating point number according to instance's
         configuration
         """
         if num:
@@ -332,22 +568,4 @@
         if first in ('insert', 'set', 'delete'):
             raise Unauthorized(self.req._('only select queries are authorized'))
 
-
-class AppObject(AppRsetObject):
-    """base class for application objects which are not selected
-    according to a result set, only by their identifier.
-
-    Those objects may not have req, rset and cursor set.
-    """
-
-    @classmethod
-    def selected(cls, *args, **kwargs):
-        """by default web app objects are usually instantiated on
-        selection
-        """
-        return cls(*args, **kwargs)
-
-    def __init__(self, req=None, rset=None, **kwargs):
-        self.req = req
-        self.rset = rset
-        self.__dict__.update(kwargs)
+set_log_methods(AppObject, getLogger('cubicweb.appobject'))
--- a/common/i18n.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/i18n.py	Fri Aug 07 12:20:50 2009 +0200
@@ -73,7 +73,7 @@
         pofiles = [pof for pof in pofiles if exists(pof)]
         mergedpo = join(destdir, '%s_merged.po' % lang)
         try:
-            # merge application messages' catalog with the stdlib's one
+            # merge instance/cubes messages catalogs with the stdlib's one
             execute('msgcat --use-first --sort-output --strict %s > %s'
                     % (' '.join(pofiles), mergedpo))
             # make sure the .mo file is writeable and compile with *msgfmt*
--- a/common/mail.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/mail.py	Fri Aug 07 12:20:50 2009 +0200
@@ -18,7 +18,7 @@
 
 def addrheader(uaddr, uname=None):
     # even if an email address should be ascii, encode it using utf8 since
-    # application tests may generate non ascii email address
+    # automatic tests may generate non ascii email address
     addr = uaddr.encode('UTF-8')
     if uname:
         return '%s <%s>' % (header(uname).encode(), addr)
--- a/common/migration.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/migration.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,5 +1,4 @@
-"""utility to ease migration of application version to newly installed
-version
+"""utilities for instances migration
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -11,11 +10,12 @@
 import sys
 import os
 import logging
-from tempfile import mktemp
+import tempfile
 from os.path import exists, join, basename, splitext
 
 from logilab.common.decorators import cached
 from logilab.common.configuration import REQUIRED, read_old_config
+from logilab.common.shellutils import ASK
 
 from cubicweb import ConfigurationError
 
@@ -70,11 +70,10 @@
     ability to show the script's content
     """
     while True:
-        confirm = raw_input('** execute %r (Y/n/s[how]) ?' % scriptpath)
-        confirm = confirm.strip().lower()
-        if confirm in ('n', 'no'):
+        answer = ASK.ask('Execute %r ?' % scriptpath, ('Y','n','show'), 'Y')
+        if answer == 'n':
             return False
-        elif confirm in ('s', 'show'):
+        elif answer == 'show':
             stream = open(scriptpath)
             scriptcontent = stream.read()
             stream.close()
@@ -153,11 +152,15 @@
                 migrdir = self.config.cube_migration_scripts_dir(cube)
             scripts = filter_scripts(self.config, migrdir, fromversion, toversion)
             if scripts:
+                prevversion = None
                 for version, script in scripts:
+                    # take care to X.Y.Z_Any.py / X.Y.Z_common.py: we've to call
+                    # cube_upgraded once all script of X.Y.Z have been executed
+                    if prevversion is not None and version != prevversion:
+                        self.cube_upgraded(cube, version)
+                    prevversion = version
                     self.process_script(script)
-                    self.cube_upgraded(cube, version)
-                if version != toversion:
-                    self.cube_upgraded(cube, toversion)
+                self.cube_upgraded(cube, toversion)
             else:
                 self.cube_upgraded(cube, toversion)
 
@@ -169,7 +172,7 @@
 
     def interact(self, args, kwargs, meth):
         """execute the given method according to user's confirmation"""
-        msg = 'execute command: %s(%s) ?' % (
+        msg = 'Execute command: %s(%s) ?' % (
             meth.__name__[4:],
             ', '.join([repr(arg) for arg in args] +
                       ['%s=%r' % (n,v) for n,v in kwargs.items()]))
@@ -185,26 +188,24 @@
 
         if `retry` is true the r[etry] answer may return 2
         """
-        print question,
-        possibleanswers = 'Y/n'
+        possibleanswers = ['Y','n']
         if abort:
-            possibleanswers += '/a[bort]'
+            possibleanswers.append('abort')
         if shell:
-            possibleanswers += '/s[hell]'
+            possibleanswers.append('shell')
         if retry:
-            possibleanswers += '/r[etry]'
+            possibleanswers.append('retry')
         try:
-            confirm = raw_input('(%s): ' % ( possibleanswers, ))
-            answer = confirm.strip().lower()
+            answer = ASK.ask(question, possibleanswers, 'Y')
         except (EOFError, KeyboardInterrupt):
             answer = 'abort'
-        if answer in ('n', 'no'):
+        if answer == 'n':
             return False
-        if answer in ('r', 'retry'):
+        if answer == 'retry':
             return 2
-        if answer in ('a', 'abort'):
+        if answer == 'abort':
             raise SystemExit(1)
-        if shell and answer in ('s', 'shell'):
+        if shell and answer == 'shell':
             self.interactive_shell()
             return self.confirm(question)
         return True
@@ -337,7 +338,7 @@
         configfile = self.config.main_config_file()
         if self._option_changes:
             read_old_config(self.config, self._option_changes, configfile)
-        newconfig = mktemp()
+        _, newconfig = tempfile.mkstemp()
         for optdescr in self._option_changes:
             if optdescr[0] == 'added':
                 optdict = self.config.get_option_def(optdescr[1])
--- a/common/mixins.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/mixins.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,7 +8,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 from logilab.common.decorators import cached
 
 from cubicweb import typed_eid
@@ -155,7 +155,7 @@
 
     def root(self):
         """return the root object"""
-        return self.req.eid_rset(self.path()[0]).get_entity(0, 0)
+        return self.req.entity_from_eid(self.path()[0])
 
 
 class WorkflowableMixIn(object):
@@ -242,9 +242,9 @@
 
     # specific vocabulary methods #############################################
 
-    @obsolete('use EntityFieldsForm.subject_in_state_vocabulary')
+    @deprecated('use EntityFieldsForm.subject_in_state_vocabulary')
     def subject_in_state_vocabulary(self, rschema, limit=None):
-        form = self.vreg.select_object('forms', 'edition', self.req, entity=self)
+        form = self.vreg.select('forms', 'edition', self.req, entity=self)
         return form.subject_in_state_vocabulary(rschema, limit)
 
 
--- a/common/mttransforms.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/mttransforms.py	Fri Aug 07 12:20:50 2009 +0200
@@ -46,8 +46,8 @@
     from cubicweb.ext.tal import compile_template
 except ImportError:
     HAS_TAL = False
-    from cubicweb.schema import FormatConstraint
-    FormatConstraint.need_perm_formats.remove('text/cubicweb-page-template')
+    from cubicweb import schema
+    schema.NEED_PERM_FORMATS.remove('text/cubicweb-page-template')
 
 else:
     HAS_TAL = True
--- a/common/tags.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/tags.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,7 +7,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from cubicweb.common.uilib import simple_sgml_tag
+from cubicweb.common.uilib import simple_sgml_tag, sgml_attributes
 
 class tag(object):
     def __init__(self, name, escapecontent=True):
@@ -38,8 +38,7 @@
     if id:
         attrs['id'] = id
     attrs['name'] = name
-    html = [u'<select %s>' % ' '.join('%s="%s"' % kv
-                                      for kv in sorted(attrs.items()))]
+    html = [u'<select %s>' % sgml_attributes(attrs)]
     html += options
     html.append(u'</select>')
     return u'\n'.join(html)
--- a/common/test/unittest_migration.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/test/unittest_migration.py	Fri Aug 07 12:20:50 2009 +0200
@@ -37,8 +37,8 @@
         self.config = MigrTestConfig('data')
         from yams.schema import Schema
         self.config.load_schema = lambda expand_cubes=False: Schema('test')
-        self.config.__class__.cubicweb_vobject_path = frozenset()
-        self.config.__class__.cube_vobject_path = frozenset()
+        self.config.__class__.cubicweb_appobject_path = frozenset()
+        self.config.__class__.cube_appobject_path = frozenset()
 
     def test_filter_scripts_base(self):
         self.assertListEquals(filter_scripts(self.config, SMIGRDIR, (2,3,0), (2,4,0)),
--- a/common/uilib.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/common/uilib.py	Fri Aug 07 12:20:50 2009 +0200
@@ -212,10 +212,15 @@
 HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param',
                               'img', 'area', 'input', 'col'))
 
+def sgml_attributes(attrs):
+    return u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
+                     for attr, value in sorted(attrs.items())
+                     if value is not None)
+
 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs):
     """generation of a simple sgml tag (eg without children tags) easier
 
-    content and attributes will be escaped
+    content and attri butes will be escaped
     """
     value = u'<%s' % tag
     if attrs:
@@ -223,9 +228,7 @@
             attrs['class'] = attrs.pop('klass')
         except KeyError:
             pass
-        value += u' ' + u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
-                                  for attr, value in sorted(attrs.items())
-                                  if value is not None)
+        value += u' ' + sgml_attributes(attrs)
     if content:
         if escapecontent:
             content = xml_escape(unicode(content))
--- a/cwconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/cwconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -22,6 +22,7 @@
 from os.path import exists, join, expanduser, abspath, normpath, basename, isdir
 
 from logilab.common.decorators import cached
+from logilab.common.deprecation import deprecated
 from logilab.common.logging_ext import set_log_methods, init_log
 from logilab.common.configuration import (Configuration, Method,
                                           ConfigurationMixIn, merge_options)
@@ -141,7 +142,7 @@
     name = None
     # log messages format (see logging module documentation for available keys)
     log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s'
-    # nor remove vobjects based on unused interface
+    # nor remove appobjects based on unused interface
     cleanup_interface_sobjects = True
 
     if os.environ.get('APYCOT_ROOT'):
@@ -149,7 +150,7 @@
         CUBES_DIR = '%(APYCOT_ROOT)s/local/share/cubicweb/cubes/' % os.environ
         # create __init__ file
         file(join(CUBES_DIR, '__init__.py'), 'w').close()
-    elif exists(join(CW_SOFTWARE_ROOT, '.hg')):
+    elif exists(join(CW_SOFTWARE_ROOT, '.hg')) or os.environ.get('CW_MODE') == 'user':
         mode = 'dev'
         CUBES_DIR = abspath(normpath(join(CW_SOFTWARE_ROOT, '../cubes')))
     else:
@@ -168,14 +169,7 @@
          {'type' : 'string',
           'default': '',
           'help': 'Pyro name server\'s host. If not set, will be detected by a \
-broadcast query',
-          'group': 'pyro-name-server', 'inputlevel': 1,
-          }),
-        ('pyro-ns-port',
-         {'type' : 'int',
-          'default': None,
-          'help': 'Pyro name server\'s listening port. If not set, default \
-port will be used.',
+broadcast query. It may contains port information using <host>:<port> notation.',
           'group': 'pyro-name-server', 'inputlevel': 1,
           }),
         ('pyro-ns-group',
@@ -221,7 +215,7 @@
           'group': 'appobjects', 'inputlevel': 2,
           }),
         )
-    # static and class methods used to get application independant resources ##
+    # static and class methods used to get instance independant resources ##
 
     @staticmethod
     def cubicweb_version():
@@ -247,7 +241,7 @@
 
     @classmethod
     def i18n_lib_dir(cls):
-        """return application's i18n directory"""
+        """return instance's i18n directory"""
         if cls.mode in ('dev', 'test') and not os.environ.get('APYCOT_ROOT'):
             return join(CW_SOFTWARE_ROOT, 'i18n')
         return join(cls.shared_dir(), 'i18n')
@@ -418,24 +412,24 @@
             except Exception, ex:
                 cls.warning("can't init cube %s: %s", cube, ex)
 
-    cubicweb_vobject_path = set(['entities'])
-    cube_vobject_path = set(['entities'])
+    cubicweb_appobject_path = set(['entities'])
+    cube_appobject_path = set(['entities'])
 
     @classmethod
     def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None):
         """given a list of directories, return a list of sub files and
-        directories that should be loaded by the application objects registry.
+        directories that should be loaded by the instance objects registry.
 
         :param evobjpath:
           optional list of sub-directories (or files without the .py ext) of
           the cubicweb library that should be tested and added to the output list
-          if they exists. If not give, default to `cubicweb_vobject_path` class
+          if they exists. If not give, default to `cubicweb_appobject_path` class
           attribute.
         :param tvobjpath:
           optional list of sub-directories (or files without the .py ext) of
           directories given in `templpath` that should be tested and added to
           the output list if they exists. If not give, default to
-          `cube_vobject_path` class attribute.
+          `cube_appobject_path` class attribute.
         """
         vregpath = cls.build_vregistry_cubicweb_path(evobjpath)
         vregpath += cls.build_vregistry_cube_path(templpath, tvobjpath)
@@ -445,7 +439,7 @@
     def build_vregistry_cubicweb_path(cls, evobjpath=None):
         vregpath = []
         if evobjpath is None:
-            evobjpath = cls.cubicweb_vobject_path
+            evobjpath = cls.cubicweb_appobject_path
         for subdir in evobjpath:
             path = join(CW_SOFTWARE_ROOT, subdir)
             if exists(path):
@@ -456,7 +450,7 @@
     def build_vregistry_cube_path(cls, templpath, tvobjpath=None):
         vregpath = []
         if tvobjpath is None:
-            tvobjpath = cls.cube_vobject_path
+            tvobjpath = cls.cube_appobject_path
         for directory in templpath:
             for subdir in tvobjpath:
                 path = join(directory, subdir)
@@ -539,8 +533,10 @@
 
     # for some commands (creation...) we don't want to initialize gettext
     set_language = True
-    # set this to true to avoid false error message while creating an application
+    # set this to true to avoid false error message while creating an instance
     creating = False
+    # set this to true to allow somethings which would'nt be possible
+    repairing = False
 
     options = CubicWebNoAppConfiguration.options + (
         ('log-file',
@@ -564,7 +560,7 @@
           }),
         ('sender-name',
          {'type' : 'string',
-          'default': Method('default_application_id'),
+          'default': Method('default_instance_id'),
           'help': 'name used as HELO name for outgoing emails from the \
 repository.',
           'group': 'email', 'inputlevel': 2,
@@ -581,49 +577,49 @@
     @classmethod
     def runtime_dir(cls):
         """run time directory for pid file..."""
-        return env_path('CW_RUNTIME', cls.RUNTIME_DIR, 'run time')
+        return env_path('CW_RUNTIME_DIR', cls.RUNTIME_DIR, 'run time')
 
     @classmethod
     def registry_dir(cls):
         """return the control directory"""
-        return env_path('CW_REGISTRY', cls.REGISTRY_DIR, 'registry')
+        return env_path('CW_INSTANCES_DIR', cls.REGISTRY_DIR, 'registry')
 
     @classmethod
     def instance_data_dir(cls):
         """return the instance data directory"""
-        return env_path('CW_INSTANCE_DATA',
+        return env_path('CW_INSTANCES_DATA_DIR',
                         cls.INSTANCE_DATA_DIR or cls.REGISTRY_DIR,
                         'additional data')
 
     @classmethod
     def migration_scripts_dir(cls):
         """cubicweb migration scripts directory"""
-        return env_path('CW_MIGRATION', cls.MIGRATION_DIR, 'migration')
+        return env_path('CW_MIGRATION_DIR', cls.MIGRATION_DIR, 'migration')
 
     @classmethod
     def config_for(cls, appid, config=None):
-        """return a configuration instance for the given application identifier
+        """return a configuration instance for the given instance identifier
         """
-        config = config or guess_configuration(cls.application_home(appid))
+        config = config or guess_configuration(cls.instance_home(appid))
         configcls = configuration_cls(config)
         return configcls(appid)
 
     @classmethod
     def possible_configurations(cls, appid):
         """return the name of possible configurations for the given
-        application id
+        instance id
         """
-        home = cls.application_home(appid)
+        home = cls.instance_home(appid)
         return possible_configurations(home)
 
     @classmethod
-    def application_home(cls, appid):
-        """return the home directory of the application with the given
-        application id
+    def instance_home(cls, appid):
+        """return the home directory of the instance with the given
+        instance id
         """
         home = join(cls.registry_dir(), appid)
         if not exists(home):
-            raise ConfigurationError('no such application %s (check it exists with "cubicweb-ctl list")' % appid)
+            raise ConfigurationError('no such instance %s (check it exists with "cubicweb-ctl list")' % appid)
         return home
 
     MODES = ('common', 'repository', 'Any', 'web')
@@ -637,14 +633,14 @@
 
     # default configuration methods ###########################################
 
-    def default_application_id(self):
-        """return the application identifier, useful for option which need this
+    def default_instance_id(self):
+        """return the instance identifier, useful for option which need this
         as default value
         """
         return self.appid
 
     def default_log_file(self):
-        """return default path to the log file of the application'server"""
+        """return default path to the log file of the instance'server"""
         if self.mode == 'dev':
             basepath = '/tmp/%s-%s' % (basename(self.appid), self.name)
             path = basepath + '.log'
@@ -660,10 +656,10 @@
         return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name)
 
     def default_pid_file(self):
-        """return default path to the pid file of the application'server"""
+        """return default path to the pid file of the instance'server"""
         return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name))
 
-    # instance methods used to get application specific resources #############
+    # instance methods used to get instance specific resources #############
 
     def __init__(self, appid):
         self.appid = appid
@@ -722,7 +718,7 @@
         self._cubes = self.reorder_cubes(list(self._cubes) + cubes)
 
     def main_config_file(self):
-        """return application's control configuration file"""
+        """return instance's control configuration file"""
         return join(self.apphome, '%s.conf' % self.name)
 
     def save(self):
@@ -739,7 +735,7 @@
         return md5.new(';'.join(infos)).hexdigest()
 
     def load_site_cubicweb(self):
-        """load (web?) application's specific site_cubicweb file"""
+        """load instance's specific site_cubicweb file"""
         for path in reversed([self.apphome] + self.cubes_path()):
             sitefile = join(path, 'site_cubicweb.py')
             if exists(sitefile) and not sitefile in self._site_loaded:
@@ -762,7 +758,7 @@
             self.load_defaults()
 
     def load_configuration(self):
-        """load application's configuration files"""
+        """load instance's configuration files"""
         super(CubicWebConfiguration, self).load_configuration()
         if self.apphome and self.set_language:
             # init gettext
@@ -774,14 +770,14 @@
             return
         self._logging_initialized = True
         CubicWebNoAppConfiguration.init_log(self, logthreshold, debug,
-                                         logfile=self.get('log-file'))
+                                            logfile=self.get('log-file'))
         # read a config file if it exists
         logconfig = join(self.apphome, 'logging.conf')
         if exists(logconfig):
             logging.fileConfig(logconfig)
 
     def available_languages(self, *args):
-        """return available translation for an application, by looking for
+        """return available translation for an instance, by looking for
         compiled catalog
 
         take *args to be usable as a vocabulary method
@@ -861,6 +857,6 @@
 
 set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration'))
 
-# alias to get a configuration instance from an application id
-application_configuration = CubicWebConfiguration.config_for
-
+# alias to get a configuration instance from an instance id
+instance_configuration = CubicWebConfiguration.config_for
+application_configuration = deprecated('use instance_configuration')(instance_configuration)
--- a/cwctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/cwctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,6 +1,6 @@
 """%%prog %s [options] %s
 
-CubicWeb main applications controller.
+CubicWeb main instances controller.
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 %s"""
 
@@ -9,10 +9,11 @@
 from os.path import exists, join, isfile, isdir
 
 from logilab.common.clcommands import register_commands, pop_arg
+from logilab.common.shellutils import ASK
 
 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, underline_title
 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
-from cubicweb.toolsutils import Command, main_run,  rm, create_dir, confirm
+from cubicweb.toolsutils import Command, main_run,  rm, create_dir
 
 def wait_process_end(pid, maxtry=10, waittime=1):
     """wait for a process to actually die"""
@@ -45,11 +46,11 @@
     return modes
 
 
-class ApplicationCommand(Command):
-    """base class for command taking 0 to n application id as arguments
-    (0 meaning all registered applications)
+class InstanceCommand(Command):
+    """base class for command taking 0 to n instance id as arguments
+    (0 meaning all registered instances)
     """
-    arguments = '[<application>...]'
+    arguments = '[<instance>...]'
     options = (
         ("force",
          {'short': 'f', 'action' : 'store_true',
@@ -84,7 +85,7 @@
         return allinstances
 
     def run(self, args):
-        """run the <command>_method on each argument (a list of application
+        """run the <command>_method on each argument (a list of instance
         identifiers)
         """
         if not args:
@@ -102,29 +103,29 @@
         for appid in args:
             if askconfirm:
                 print '*'*72
-                if not confirm('%s application %r ?' % (self.name, appid)):
+                if not confirm('%s instance %r ?' % (self.name, appid)):
                     continue
             self.run_arg(appid)
 
     def run_arg(self, appid):
-        cmdmeth = getattr(self, '%s_application' % self.name)
+        cmdmeth = getattr(self, '%s_instance' % self.name)
         try:
             cmdmeth(appid)
         except (KeyboardInterrupt, SystemExit):
             print >> sys.stderr, '%s aborted' % self.name
             sys.exit(2) # specific error code
         except (ExecutionError, ConfigurationError), ex:
-            print >> sys.stderr, 'application %s not %s: %s' % (
+            print >> sys.stderr, 'instance %s not %s: %s' % (
                 appid, self.actionverb, ex)
         except Exception, ex:
             import traceback
             traceback.print_exc()
-            print >> sys.stderr, 'application %s not %s: %s' % (
+            print >> sys.stderr, 'instance %s not %s: %s' % (
                 appid, self.actionverb, ex)
 
 
-class ApplicationCommandFork(ApplicationCommand):
-    """Same as `ApplicationCommand`, but command is forked in a new environment
+class InstanceCommandFork(InstanceCommand):
+    """Same as `InstanceCommand`, but command is forked in a new environment
     for each argument
     """
 
@@ -136,7 +137,7 @@
         for appid in args:
             if askconfirm:
                 print '*'*72
-                if not confirm('%s application %r ?' % (self.name, appid)):
+                if not confirm('%s instance %r ?' % (self.name, appid)):
                     continue
             if forkcmd:
                 status = system('%s %s' % (forkcmd, appid))
@@ -148,10 +149,9 @@
 # base commands ###############################################################
 
 class ListCommand(Command):
-    """List configurations, componants and applications.
+    """List configurations, cubes and instances.
 
-    list available configurations, installed web and server componants, and
-    registered applications
+    list available configurations, installed cubes, and registered instances
     """
     name = 'list'
     options = (
@@ -206,30 +206,30 @@
         try:
             regdir = cwcfg.registry_dir()
         except ConfigurationError, ex:
-            print 'No application available:', ex
+            print 'No instance available:', ex
             print
             return
         instances = list_instances(regdir)
         if instances:
-            print 'Available applications (%s):' % regdir
+            print 'Available instances (%s):' % regdir
             for appid in instances:
                 modes = cwcfg.possible_configurations(appid)
                 if not modes:
-                    print '* %s (BROKEN application, no configuration found)' % appid
+                    print '* %s (BROKEN instance, no configuration found)' % appid
                     continue
                 print '* %s (%s)' % (appid, ', '.join(modes))
                 try:
                     config = cwcfg.config_for(appid, modes[0])
                 except Exception, exc:
-                    print '    (BROKEN application, %s)' % exc
+                    print '    (BROKEN instance, %s)' % exc
                     continue
         else:
-            print 'No application available in %s' % regdir
+            print 'No instance available in %s' % regdir
         print
 
 
-class CreateApplicationCommand(Command):
-    """Create an application from a cube. This is an unified
+class CreateInstanceCommand(Command):
+    """Create an instance from a cube. This is an unified
     command which can handle web / server / all-in-one installation
     according to available parts of the software library and of the
     desired cube.
@@ -238,11 +238,11 @@
       the name of cube to use (list available cube names using
       the "list" command). You can use several cubes by separating
       them using comma (e.g. 'jpl,eemail')
-    <application>
-      an identifier for the application to create
+    <instance>
+      an identifier for the instance to create
     """
     name = 'create'
-    arguments = '<cube> <application>'
+    arguments = '<cube> <instance>'
     options = (
         ("config-level",
          {'short': 'l', 'type' : 'int', 'metavar': '<level>',
@@ -255,7 +255,7 @@
          {'short': 'c', 'type' : 'choice', 'metavar': '<install type>',
           'choices': ('all-in-one', 'repository', 'twisted'),
           'default': 'all-in-one',
-          'help': 'installation type, telling which part of an application \
+          'help': 'installation type, telling which part of an instance \
 should be installed. You can list available configurations using the "list" \
 command. Default to "all-in-one", e.g. an installation embedding both the RQL \
 repository and the web server.',
@@ -265,9 +265,9 @@
 
     def run(self, args):
         """run the command with its specific arguments"""
-        from logilab.common.textutils import get_csv
+        from logilab.common.textutils import splitstrip
         configname = self.config.config
-        cubes = get_csv(pop_arg(args, 1))
+        cubes = splitstrip(pop_arg(args, 1))
         appid = pop_arg(args)
         # get the configuration and helper
         cwcfg.creating = True
@@ -285,13 +285,13 @@
             print '\navailable cubes:',
             print ', '.join(cwcfg.available_cubes())
             return
-        # create the registry directory for this application
-        print '\n'+underline_title('Creating the application %s' % appid)
+        # create the registry directory for this instance
+        print '\n'+underline_title('Creating the instance %s' % appid)
         create_dir(config.apphome)
         # load site_cubicweb from the cubes dir (if any)
         config.load_site_cubicweb()
         # cubicweb-ctl configuration
-        print '\n'+underline_title('Configuring the application (%s.conf)' % configname)
+        print '\n'+underline_title('Configuring the instance (%s.conf)' % configname)
         config.input_config('main', self.config.config_level)
         # configuration'specific stuff
         print
@@ -311,9 +311,10 @@
                            'continue anyway ?'):
                 print 'creation not completed'
                 return
-        # create the additional data directory for this application
+        # create the additional data directory for this instance
         if config.appdatahome != config.apphome: # true in dev mode
             create_dir(config.appdatahome)
+        create_dir(join(config.appdatahome, 'backup'))
         if config['uid']:
             from logilab.common.shellutils import chown
             # this directory should be owned by the uid of the server process
@@ -323,18 +324,18 @@
         helper.postcreate()
 
 
-class DeleteApplicationCommand(Command):
-    """Delete an application. Will remove application's files and
+class DeleteInstanceCommand(Command):
+    """Delete an instance. Will remove instance's files and
     unregister it.
     """
     name = 'delete'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = ()
 
     def run(self, args):
         """run the command with its specific arguments"""
-        appid = pop_arg(args, msg="No application specified !")
+        appid = pop_arg(args, msg="No instance specified !")
         configs = [cwcfg.config_for(appid, configname)
                    for configname in cwcfg.possible_configurations(appid)]
         if not configs:
@@ -353,16 +354,16 @@
             if ex.errno != errno.ENOENT:
                 raise
         confignames = ', '.join([config.name for config in configs])
-        print 'application %s (%s) deleted' % (appid, confignames)
+        print '-> instance %s (%s) deleted.' % (appid, confignames)
 
 
-# application commands ########################################################
+# instance commands ########################################################
 
-class StartApplicationCommand(ApplicationCommand):
-    """Start the given applications. If no application is given, start them all.
+class StartInstanceCommand(InstanceCommand):
+    """Start the given instances. If no instance is given, start them all.
 
-    <application>...
-      identifiers of the applications to start. If no application is
+    <instance>...
+      identifiers of the instances to start. If no instance is
       given, start them all.
     """
     name = 'start'
@@ -374,22 +375,32 @@
         ("force",
          {'short': 'f', 'action' : 'store_true',
           'default': False,
-          'help': 'start the application even if it seems to be already \
+          'help': 'start the instance even if it seems to be already \
 running.'}),
         ('profile',
          {'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
           'default': None,
           'help': 'profile code and use the specified file to store stats',
           }),
+        ('loglevel',
+         {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
+          'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
+          'help': 'debug if -D is set, error otherwise',
+          }),
         )
 
-    def start_application(self, appid):
-        """start the application's server"""
+    def start_instance(self, appid):
+        """start the instance's server"""
         # use get() since start may be used from other commands (eg upgrade)
         # without all options defined
         debug = self.get('debug')
         force = self.get('force')
+        loglevel = self.get('loglevel')
         config = cwcfg.config_for(appid)
+        if loglevel is not None:
+            loglevel = 'LOG_%s' % loglevel.upper()
+            config.global_set_option('log-threshold', loglevel)
+            config.init_log(loglevel, debug=debug, force=True)
         if self.get('profile'):
             config.global_set_option('profile', self.config.profile)
         helper = self.config_helper(config, cmdname='start')
@@ -398,36 +409,27 @@
             msg = "%s seems to be running. Remove %s by hand if necessary or use \
 the --force option."
             raise ExecutionError(msg % (appid, pidf))
-        command = helper.start_command(config, debug)
-        if debug:
-            print "starting server with command :"
-            print command
-        if system(command):
-            print 'an error occured while starting the application, not started'
-            print
-            return False
-        if not debug:
-            print 'application %s started' % appid
+        helper.start_command(config, debug)
         return True
 
 
-class StopApplicationCommand(ApplicationCommand):
-    """Stop the given applications.
+class StopInstanceCommand(InstanceCommand):
+    """Stop the given instances.
 
-    <application>...
-      identifiers of the applications to stop. If no application is
+    <instance>...
+      identifiers of the instances to stop. If no instance is
       given, stop them all.
     """
     name = 'stop'
     actionverb = 'stopped'
 
     def ordered_instances(self):
-        instances = super(StopApplicationCommand, self).ordered_instances()
+        instances = super(StopInstanceCommand, self).ordered_instances()
         instances.reverse()
         return instances
 
-    def stop_application(self, appid):
-        """stop the application's server"""
+    def stop_instance(self, appid):
+        """stop the instance's server"""
         config = cwcfg.config_for(appid)
         helper = self.config_helper(config, cmdname='stop')
         helper.poststop() # do this anyway
@@ -458,15 +460,15 @@
         except OSError:
             # already removed by twistd
             pass
-        print 'application %s stopped' % appid
+        print 'instance %s stopped' % appid
 
 
-class RestartApplicationCommand(StartApplicationCommand,
-                                StopApplicationCommand):
-    """Restart the given applications.
+class RestartInstanceCommand(StartInstanceCommand,
+                                StopInstanceCommand):
+    """Restart the given instances.
 
-    <application>...
-      identifiers of the applications to restart. If no application is
+    <instance>...
+      identifiers of the instances to restart. If no instance is
       given, restart them all.
     """
     name = 'restart'
@@ -476,18 +478,18 @@
         regdir = cwcfg.registry_dir()
         if not isfile(join(regdir, 'startorder')) or len(args) <= 1:
             # no specific startorder
-            super(RestartApplicationCommand, self).run_args(args, askconfirm)
+            super(RestartInstanceCommand, self).run_args(args, askconfirm)
             return
         print ('some specific start order is specified, will first stop all '
-               'applications then restart them.')
+               'instances then restart them.')
         # get instances in startorder
         stopped = []
         for appid in args:
             if askconfirm:
                 print '*'*72
-                if not confirm('%s application %r ?' % (self.name, appid)):
+                if not confirm('%s instance %r ?' % (self.name, appid)):
                     continue
-            self.stop_application(appid)
+            self.stop_instance(appid)
             stopped.append(appid)
         forkcmd = [w for w in sys.argv if not w in args]
         forkcmd[1] = 'start'
@@ -497,46 +499,46 @@
             if status:
                 sys.exit(status)
 
-    def restart_application(self, appid):
-        self.stop_application(appid)
-        if self.start_application(appid):
-            print 'application %s %s' % (appid, self.actionverb)
+    def restart_instance(self, appid):
+        self.stop_instance(appid)
+        if self.start_instance(appid):
+            print 'instance %s %s' % (appid, self.actionverb)
 
 
-class ReloadConfigurationCommand(RestartApplicationCommand):
-    """Reload the given applications. This command is equivalent to a
+class ReloadConfigurationCommand(RestartInstanceCommand):
+    """Reload the given instances. This command is equivalent to a
     restart for now.
 
-    <application>...
-      identifiers of the applications to reload. If no application is
+    <instance>...
+      identifiers of the instances to reload. If no instance is
       given, reload them all.
     """
     name = 'reload'
 
-    def reload_application(self, appid):
-        self.restart_application(appid)
+    def reload_instance(self, appid):
+        self.restart_instance(appid)
 
 
-class StatusCommand(ApplicationCommand):
-    """Display status information about the given applications.
+class StatusCommand(InstanceCommand):
+    """Display status information about the given instances.
 
-    <application>...
-      identifiers of the applications to status. If no application is
-      given, get status information about all registered applications.
+    <instance>...
+      identifiers of the instances to status. If no instance is
+      given, get status information about all registered instances.
     """
     name = 'status'
     options = ()
 
     @staticmethod
-    def status_application(appid):
-        """print running status information for an application"""
+    def status_instance(appid):
+        """print running status information for an instance"""
         for mode in cwcfg.possible_configurations(appid):
             config = cwcfg.config_for(appid, mode)
             print '[%s-%s]' % (appid, mode),
             try:
                 pidf = config['pid-file']
             except KeyError:
-                print 'buggy application, pid file not specified'
+                print 'buggy instance, pid file not specified'
                 continue
             if not exists(pidf):
                 print "doesn't seem to be running"
@@ -551,22 +553,22 @@
             print "running with pid %s" % (pid)
 
 
-class UpgradeApplicationCommand(ApplicationCommandFork,
-                                StartApplicationCommand,
-                                StopApplicationCommand):
-    """Upgrade an application after cubicweb and/or component(s) upgrade.
+class UpgradeInstanceCommand(InstanceCommandFork,
+                                StartInstanceCommand,
+                                StopInstanceCommand):
+    """Upgrade an instance after cubicweb and/or component(s) upgrade.
 
     For repository update, you will be prompted for a login / password to use
     to connect to the system database.  For some upgrades, the given user
     should have create or alter table permissions.
 
-    <application>...
-      identifiers of the applications to upgrade. If no application is
+    <instance>...
+      identifiers of the instances to upgrade. If no instance is
       given, upgrade them all.
     """
     name = 'upgrade'
     actionverb = 'upgraded'
-    options = ApplicationCommand.options + (
+    options = InstanceCommand.options + (
         ('force-componant-version',
          {'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z',
           'default': None,
@@ -584,7 +586,7 @@
         ('nostartstop',
          {'short': 'n', 'action' : 'store_true',
           'default': False,
-          'help': 'don\'t try to stop application before migration and to restart it after.'}),
+          'help': 'don\'t try to stop instance before migration and to restart it after.'}),
 
         ('verbosity',
          {'short': 'v', 'type' : 'int', 'metavar': '<0..2>',
@@ -595,7 +597,7 @@
         ('backup-db',
          {'short': 'b', 'type' : 'yn', 'metavar': '<y or n>',
           'default': None,
-          'help': "Backup the application database before upgrade.\n"\
+          'help': "Backup the instance database before upgrade.\n"\
           "If the option is ommitted, confirmation will be ask.",
           }),
 
@@ -610,25 +612,24 @@
         )
 
     def ordered_instances(self):
-        # need this since mro return StopApplicationCommand implementation
-        return ApplicationCommand.ordered_instances(self)
+        # need this since mro return StopInstanceCommand implementation
+        return InstanceCommand.ordered_instances(self)
 
-    def upgrade_application(self, appid):
+    def upgrade_instance(self, appid):
+        print '\n' + underline_title('Upgrading the instance %s' % appid)
         from logilab.common.changelog import Version
         config = cwcfg.config_for(appid)
-        config.creating = True # notice we're not starting the server
+        config.repairing = True # notice we're not starting the server
         config.verbosity = self.config.verbosity
         try:
             config.set_sources_mode(self.config.ext_sources or ('migration',))
         except AttributeError:
             # not a server config
             pass
-        # get application and installed versions for the server and the componants
-        print 'getting versions configuration from the repository...'
+        # get instance and installed versions for the server and the componants
         mih = config.migration_handler()
         repo = mih.repo_connect()
         vcconf = repo.get_versions()
-        print 'done'
         if self.config.force_componant_version:
             packversions = {}
             for vdef in self.config.force_componant_version:
@@ -654,13 +655,13 @@
         if cubicwebversion > applcubicwebversion:
             toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
         if not self.config.fs_only and not toupgrade:
-            print 'no software migration needed for application %s' % appid
+            print '-> no software migration needed for instance %s.' % appid
             return
         for cube, fromversion, toversion in toupgrade:
-            print '**** %s migration %s -> %s' % (cube, fromversion, toversion)
+            print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
         # only stop once we're sure we have something to do
         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
-            self.stop_application(appid)
+            self.stop_instance(appid)
         # run cubicweb/componants migration scripts
         mih.migrate(vcconf, reversed(toupgrade), self.config)
         # rewrite main configuration file
@@ -675,15 +676,15 @@
         errors = config.i18ncompile(langs)
         if errors:
             print '\n'.join(errors)
-            if not confirm('error while compiling message catalogs, '
+            if not confirm('Error while compiling message catalogs, '
                            'continue anyway ?'):
-                print 'migration not completed'
+                print '-> migration not completed.'
                 return
         mih.shutdown()
         print
-        print 'application migrated'
+        print '-> instance migrated.'
         if not (cwcfg.mode == 'dev' or self.config.nostartstop):
-            self.start_application(appid)
+            self.start_instance(appid)
         print
 
 
@@ -693,11 +694,11 @@
     argument may be given corresponding to a file containing commands to
     execute in batch mode.
 
-    <application>
-      the identifier of the application to connect.
+    <instance>
+      the identifier of the instance to connect.
     """
     name = 'shell'
-    arguments = '<application> [batch command file]'
+    arguments = '<instance> [batch command file]'
     options = (
         ('system-only',
          {'short': 'S', 'action' : 'store_true',
@@ -717,7 +718,7 @@
 
         )
     def run(self, args):
-        appid = pop_arg(args, 99, msg="No application specified !")
+        appid = pop_arg(args, 99, msg="No instance specified !")
         config = cwcfg.config_for(appid)
         if self.config.ext_sources:
             assert not self.config.system_only
@@ -736,18 +737,18 @@
         mih.shutdown()
 
 
-class RecompileApplicationCatalogsCommand(ApplicationCommand):
-    """Recompile i18n catalogs for applications.
+class RecompileInstanceCatalogsCommand(InstanceCommand):
+    """Recompile i18n catalogs for instances.
 
-    <application>...
-      identifiers of the applications to consider. If no application is
-      given, recompile for all registered applications.
+    <instance>...
+      identifiers of the instances to consider. If no instance is
+      given, recompile for all registered instances.
     """
     name = 'i18ninstance'
 
     @staticmethod
-    def i18ninstance_application(appid):
-        """recompile application's messages catalogs"""
+    def i18ninstance_instance(appid):
+        """recompile instance's messages catalogs"""
         config = cwcfg.config_for(appid)
         try:
             config.bootstrap_cubes()
@@ -756,8 +757,8 @@
             if ex.errno != errno.ENOENT:
                 raise
             # bootstrap_cubes files doesn't exist
-            # set creating to notify this is not a regular start
-            config.creating = True
+            # notify this is not a regular start
+            config.repairing = True
             # create an in-memory repository, will call config.init_cubes()
             config.repository()
         except AttributeError:
@@ -791,16 +792,16 @@
             print cube
 
 register_commands((ListCommand,
-                   CreateApplicationCommand,
-                   DeleteApplicationCommand,
-                   StartApplicationCommand,
-                   StopApplicationCommand,
-                   RestartApplicationCommand,
+                   CreateInstanceCommand,
+                   DeleteInstanceCommand,
+                   StartInstanceCommand,
+                   StopInstanceCommand,
+                   RestartInstanceCommand,
                    ReloadConfigurationCommand,
                    StatusCommand,
-                   UpgradeApplicationCommand,
+                   UpgradeInstanceCommand,
                    ShellCommand,
-                   RecompileApplicationCatalogsCommand,
+                   RecompileInstanceCatalogsCommand,
                    ListInstancesCommand, ListCubesCommand,
                    ))
 
--- a/cwvreg.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/cwvreg.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,12 +8,17 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
-from logilab.common.decorators import cached, clear_cache
+from logilab.common.decorators import cached, clear_cache, monkeypatch
+from logilab.common.deprecation import  deprecated
+from logilab.common.modutils import cleanup_sys_modules
 
 from rql import RQLHelper
 
-from cubicweb import ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid
-from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject
+from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid,
+                      ObjectNotFound, NoSelectableObject, RegistryNotFound,
+                      RegistryOutOfDate, CW_EVENT_MANAGER)
+from cubicweb.utils import dump_class
+from cubicweb.vregistry import VRegistry, Registry
 from cubicweb.rtags import RTAGS
 
 
@@ -31,47 +36,233 @@
             if impl:
                 return sorted(impl.expected_ifaces)
         except AttributeError:
-            pass # old-style vobject classes with no accepts_interfaces
+            pass # old-style appobject classes with no accepts_interfaces
         except:
             print 'bad selector %s on %s' % (obj.__select__, obj)
             raise
         return ()
 
 
-class CubicWebRegistry(VRegistry):
-    """extend the generic VRegistry with some cubicweb specific stuff"""
+class CWRegistry(Registry):
+    def __init__(self, vreg):
+        super(CWRegistry, self).__init__(vreg.config)
+        self.vreg = vreg
+        self.schema = vreg.schema
+
+    def initialization_completed(self):
+        # call vreg_initialization_completed on appobjects and print
+        # registry content
+        for appobjects in self.itervalues():
+            for appobject in appobjects:
+                appobject.vreg_initialization_completed()
+
+    def render(self, __oid, req, __fallback_oid=None, rset=None, **kwargs):
+        """select object, or fallback object if specified and the first one
+        isn't selectable, then render it
+        """
+        try:
+            obj = self.select(__oid, req, rset=rset, **kwargs)
+        except NoSelectableObject:
+            if __fallback_oid is None:
+                raise
+            obj = self.select(__fallback_oid, req, **kwargs)
+        return obj.render(**kwargs)
+
+    def select_vobject(self, oid, *args, **kwargs):
+        selected = self.select_object(oid, *args, **kwargs)
+        if selected and selected.propval('visible'):
+            return selected
+        return None
+
+    def possible_vobjects(self, *args, **kwargs):
+        """return an ordered list of possible app objects in a given registry,
+        supposing they support the 'visible' and 'order' properties (as most
+        visualizable objects)
+        """
+        return sorted([x for x in self.possible_objects(*args, **kwargs)
+                       if x.propval('visible')],
+                      key=lambda x: x.propval('order'))
+
+
+VRegistry.REGISTRY_FACTORY[None] = CWRegistry
+
+
+class ETypeRegistry(CWRegistry):
+
+    def initialization_completed(self):
+        """on registration completed, clear etype_class internal cache
+        """
+        super(ETypeRegistry, self).initialization_completed()
+        # clear etype cache if you don't want to run into deep weirdness
+        clear_cache(self, 'etype_class')
+
+    def register(self, obj, **kwargs):
+        oid = kwargs.get('oid') or obj.id
+        if oid != 'Any' and not oid in self.schema:
+            self.error('don\'t register %s, %s type not defined in the '
+                       'schema', obj, obj.id)
+            return
+        kwargs['clear'] = True
+        super(ETypeRegistry, self).register(obj, **kwargs)
+
+    @cached
+    def etype_class(self, etype):
+        """return an entity class for the given entity type.
+
+        Try to find out a specific class for this kind of entity or default to a
+        dump of the nearest parent class (in yams inheritance) registered.
+
+        Fall back to 'Any' if not yams parent class found.
+        """
+        etype = str(etype)
+        if etype == 'Any':
+            return self.select('Any', 'Any')
+        eschema = self.schema.eschema(etype)
+        baseschemas = [eschema] + eschema.ancestors()
+        # browse ancestors from most specific to most generic and try to find an
+        # associated custom entity class
+        for baseschema in baseschemas:
+            try:
+                btype = ETYPE_NAME_MAP[baseschema]
+            except KeyError:
+                btype = str(baseschema)
+            try:
+                objects = self[btype]
+                assert len(objects) == 1, objects
+                cls = objects[0]
+                break
+            except ObjectNotFound:
+                pass
+        else:
+            # no entity class for any of the ancestors, fallback to the default
+            # one
+            objects = self['Any']
+            assert len(objects) == 1, objects
+            cls = objects[0]
+        if cls.id == etype:
+            cls.__initialize__()
+            return cls
+        cls = dump_class(cls, etype)
+        cls.id = etype
+        cls.__initialize__()
+        return cls
+
+VRegistry.REGISTRY_FACTORY['etypes'] = ETypeRegistry
+
+
+class ViewsRegistry(CWRegistry):
+
+    def main_template(self, req, oid='main-template', **kwargs):
+        """display query by calling the given template (default to main),
+        and returning the output as a string instead of requiring the [w]rite
+        method as argument
+        """
+        res = self.render(oid, req, **kwargs)
+        if isinstance(res, unicode):
+            return res.encode(req.encoding)
+        assert isinstance(res, str)
+        return res
+
+    def possible_views(self, req, rset=None, **kwargs):
+        """return an iterator on possible views for this result set
+
+        views returned are classes, not instances
+        """
+        for vid, views in self.items():
+            if vid[0] == '_':
+                continue
+            try:
+                view = self.select_best(views, req, rset=rset, **kwargs)
+                if view.linkable():
+                    yield view
+            except NoSelectableObject:
+                continue
+            except Exception:
+                self.exception('error while trying to select %s view for %s',
+                               vid, rset)
+
+VRegistry.REGISTRY_FACTORY['views'] = ViewsRegistry
+
+
+class ActionsRegistry(CWRegistry):
+
+    def possible_actions(self, req, rset=None, **kwargs):
+        if rset is None:
+            actions = self.possible_vobjects(req, rset=rset, **kwargs)
+        else:
+            actions = rset.possible_actions(**kwargs) # cached implementation
+        result = {}
+        for action in actions:
+            result.setdefault(action.category, []).append(action)
+        return result
+
+VRegistry.REGISTRY_FACTORY['actions'] = ActionsRegistry
+
+
+
+class CubicWebVRegistry(VRegistry):
+    """Central registry for the cubicweb instance, extending the generic
+    VRegistry with some cubicweb specific stuff.
+
+    This is one of the central object in cubicweb instance, coupling
+    dynamically loaded objects with the schema and the configuration objects.
+
+    It specializes the VRegistry by adding some convenience methods to access to
+    stored objects. Currently we have the following registries of objects known
+    by the web instance (library may use some others additional registries):
+
+    * etypes
+    * views
+    * components
+    * actions
+    * forms
+    * formrenderers
+    * controllers, which are directly plugged into the application
+      object to handle request publishing XXX to merge with views
+    * contentnavigation XXX to merge with components? to kill?
+    """
 
     def __init__(self, config, debug=None, initlog=True):
         if initlog:
             # first init log service
             config.init_log(debug=debug)
-        super(CubicWebRegistry, self).__init__(config)
+        super(CubicWebVRegistry, self).__init__(config)
         self.schema = None
         self.reset()
         self.initialized = False
 
+    def setdefault(self, regid):
+        try:
+            return self[regid]
+        except RegistryNotFound:
+            self[regid] = self.registry_class(regid)(self)
+            return self[regid]
+
     def items(self):
-        return [item for item in self._registries.items()
+        return [item for item in super(CubicWebVRegistry, self).items()
                 if not item[0] in ('propertydefs', 'propertyvalues')]
+    def iteritems(self):
+        return (item for item in super(CubicWebVRegistry, self).iteritems()
+                if not item[0] in ('propertydefs', 'propertyvalues'))
 
     def values(self):
-        return [value for key, value in self._registries.items()
-                if not key in ('propertydefs', 'propertyvalues')]
+        return [value for key, value in self.items()]
+    def itervalues(self):
+        return (value for key, value in self.items())
 
     def reset(self):
-        self._registries = {}
-        self._lastmodifs = {}
+        super(CubicWebVRegistry, self).reset()
         self._needs_iface = {}
         # two special registries, propertydefs which care all the property
         # definitions, and propertyvals which contains values for those
         # properties
-        self._registries['propertydefs'] = {}
-        self._registries['propertyvalues'] = self.eprop_values = {}
+        self['propertydefs'] = {}
+        self['propertyvalues'] = self.eprop_values = {}
         for key, propdef in self.config.eproperty_definitions():
             self.register_property(key, **propdef)
 
     def set_schema(self, schema):
-        """set application'schema and load application objects"""
+        """set instance'schema and load application objects"""
         self.schema = schema
         clear_cache(self, 'rqlhelper')
         # now we can load application's web objects
@@ -87,9 +278,7 @@
         tests
         """
         self.schema = schema
-        for registry, regcontent in self._registries.items():
-            if registry in ('propertydefs', 'propertyvalues'):
-                continue
+        for registry, regcontent in self.items():
             for objects in regcontent.values():
                 for obj in objects:
                     obj.schema = schema
@@ -105,13 +294,7 @@
             self._needs_iface[obj] = ifaces
 
     def register(self, obj, **kwargs):
-        if kwargs.get('registryname', obj.__registry__) == 'etypes':
-            if obj.id != 'Any' and not obj.id in self.schema:
-                self.error('don\'t register %s, %s type not defined in the '
-                           'schema', obj, obj.id)
-                return
-            kwargs['clear'] = True
-        super(CubicWebRegistry, self).register(obj, **kwargs)
+        super(CubicWebVRegistry, self).register(obj, **kwargs)
         # XXX bw compat
         ifaces = use_interfaces(obj)
         if ifaces:
@@ -119,181 +302,108 @@
 
     def register_objects(self, path, force_reload=None):
         """overriden to remove objects requiring a missing interface"""
+        try:
+            self._register_objects(path, force_reload)
+        except RegistryOutOfDate:
+            CW_EVENT_MANAGER.emit('before-registry-reload')
+            # modification detected, reset and reload
+            self.reset()
+            cleanup_sys_modules(path)
+            self._register_objects(path, force_reload)
+            CW_EVENT_MANAGER.emit('after-registry-reload')
+
+    def _register_objects(self, path, force_reload=None):
+        """overriden to remove objects requiring a missing interface"""
         extrapath = {}
         for cubesdir in self.config.cubes_search_path():
             if cubesdir != self.config.CUBES_DIR:
                 extrapath[cubesdir] = 'cubes'
-        if super(CubicWebRegistry, self).register_objects(path, force_reload,
+        if super(CubicWebVRegistry, self).register_objects(path, force_reload,
                                                           extrapath):
             self.initialization_completed()
-            # call vreg_initialization_completed on appobjects and print
-            # registry content
-            for registry, objects in self.items():
-                self.debug('available in registry %s: %s', registry,
-                           sorted(objects))
-                for appobjects in objects.itervalues():
-                    for appobject in appobjects:
-                        appobject.vreg_initialization_completed()
             # don't check rtags if we don't want to cleanup_interface_sobjects
             for rtag in RTAGS:
                 rtag.init(self.schema,
                           check=self.config.cleanup_interface_sobjects)
 
     def initialization_completed(self):
-        # clear etype cache if you don't want to run into deep weirdness
-        clear_cache(self, 'etype_class')
+        for regname, reg in self.items():
+            self.debug('available in registry %s: %s', regname, sorted(reg))
+            reg.initialization_completed()
         # we may want to keep interface dependent objects (e.g.for i18n
         # catalog generation)
         if self.config.cleanup_interface_sobjects:
-            # remove vobjects that don't support any available interface
+            # remove appobjects that don't support any available interface
             implemented_interfaces = set()
             if 'Any' in self.get('etypes', ()):
                 for etype in self.schema.entities():
-                    cls = self.etype_class(etype)
+                    cls = self['etypes'].etype_class(etype)
                     for iface in cls.__implements__:
                         implemented_interfaces.update(iface.__mro__)
                     implemented_interfaces.update(cls.__mro__)
             for obj, ifaces in self._needs_iface.items():
                 ifaces = frozenset(isinstance(iface, basestring)
                                    and iface in self.schema
-                                   and self.etype_class(iface)
+                                   and self['etypes'].etype_class(iface)
                                    or iface
                                    for iface in ifaces)
                 if not ('Any' in ifaces or ifaces & implemented_interfaces):
-                    self.debug('kicking vobject %s (no implemented '
+                    self.debug('kicking appobject %s (no implemented '
                                'interface among %s)', obj, ifaces)
                     self.unregister(obj)
         # clear needs_iface so we don't try to remove some not-anymore-in
         # objects on automatic reloading
         self._needs_iface.clear()
 
-    @cached
-    def etype_class(self, etype):
-        """return an entity class for the given entity type.
-        Try to find out a specific class for this kind of entity or
-        default to a dump of the class registered for 'Any'
-        """
-        etype = str(etype)
-        if etype == 'Any':
-            return self.select(self.registry_objects('etypes', 'Any'), 'Any')
-        eschema = self.schema.eschema(etype)
-        baseschemas = [eschema] + eschema.ancestors()
-        # browse ancestors from most specific to most generic and
-        # try to find an associated custom entity class
-        for baseschema in baseschemas:
-            try:
-                btype = ETYPE_NAME_MAP[baseschema]
-            except KeyError:
-                btype = str(baseschema)
-            try:
-                cls = self.select(self.registry_objects('etypes', btype), etype)
-                break
-            except ObjectNotFound:
-                pass
-        else:
-            # no entity class for any of the ancestors, fallback to the default
-            # one
-            cls = self.select(self.registry_objects('etypes', 'Any'), etype)
-        return cls
-
-    def render(self, registry, oid, req, **context):
-        """select an object in a given registry and render it
+    def parse(self, session, rql, args=None):
+        rqlst = self.rqlhelper.parse(rql)
+        def type_from_eid(eid, session=session):
+            return session.describe(eid)[0]
+        try:
+            self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
+        except UnknownEid:
+            for select in rqlst.children:
+                select.solutions = []
+        return rqlst
 
-        - registry: the registry's name
-        - oid : the view to call
-        - req : the HTTP request
-        """
-        objclss = self.registry_objects(registry, oid)
-        try:
-            rset = context.pop('rset')
-        except KeyError:
-            rset = None
-        selected = self.select(objclss, req, rset, **context)
-        return selected.render(**context)
+    @property
+    @cached
+    def rqlhelper(self):
+        return RQLHelper(self.schema,
+                         special_relations={'eid': 'uid', 'has_text': 'fti'})
 
-    def main_template(self, req, oid='main-template', **context):
-        """display query by calling the given template (default to main),
-        and returning the output as a string instead of requiring the [w]rite
-        method as argument
-        """
-        res = self.render('views', oid, req, **context)
-        if isinstance(res, unicode):
-            return res.encode(req.encoding)
-        assert isinstance(res, str)
-        return res
 
-    def possible_vobjects(self, registry, *args, **kwargs):
-        """return an ordered list of possible app objects in a given registry,
-        supposing they support the 'visible' and 'order' properties (as most
-        visualizable objects)
-        """
-        return [x for x in sorted(self.possible_objects(registry, *args, **kwargs),
-                                  key=lambda x: x.propval('order'))
-                if x.propval('visible')]
+    @deprecated('use vreg["etypes"].etype_class(etype)')
+    def etype_class(self, etype):
+        return self["etypes"].etype_class(etype)
 
-    def possible_actions(self, req, rset, **kwargs):
-        if rset is None:
-            actions = self.possible_vobjects('actions', req, rset, **kwargs)
-        else:
-            actions = rset.possible_actions(**kwargs) # cached implementation
-        result = {}
-        for action in actions:
-            result.setdefault(action.category, []).append(action)
-        return result
-
-    def possible_views(self, req, rset, **kwargs):
-        """return an iterator on possible views for this result set
+    @deprecated('use vreg["views"].main_template(*args, **kwargs)')
+    def main_template(self, req, oid='main-template', **context):
+        return self["views"].main_template(req, oid, **context)
 
-        views returned are classes, not instances
-        """
-        for vid, views in self.registry('views').items():
-            if vid[0] == '_':
-                continue
-            try:
-                view = self.select(views, req, rset, **kwargs)
-                if view.linkable():
-                    yield view
-            except NoSelectableObject:
-                continue
-            except Exception:
-                self.exception('error while trying to list possible %s views for %s',
-                               vid, rset)
+    @deprecated('use vreg[registry].possible_vobjects(*args, **kwargs)')
+    def possible_vobjects(self, registry, *args, **kwargs):
+        return self[registry].possible_vobjects(*args, **kwargs)
+
+    @deprecated('use vreg["actions"].possible_actions(*args, **kwargs)')
+    def possible_actions(self, req, rset=None, **kwargs):
+        return self["actions"].possible_actions(req, rest=rset, **kwargs)
 
-    def view(self, __vid, req, rset=None, __fallback_vid=None, **kwargs):
-        """shortcut to self.vreg.render method avoiding to pass self.req"""
-        try:
-            view = self.select_view(__vid, req, rset, **kwargs)
-        except NoSelectableObject:
-            if __fallback_vid is None:
-                raise
-            view = self.select_view(__fallback_vid, req, rset, **kwargs)
-        return view.render(**kwargs)
+    @deprecated("use vreg['boxes'].select_object(...)")
+    def select_box(self, oid, *args, **kwargs):
+        return self['boxes'].select_object(oid, *args, **kwargs)
 
-    def select_box(self, oid, *args, **kwargs):
-        """return the most specific view according to the result set"""
-        try:
-            return self.select_object('boxes', oid, *args, **kwargs)
-        except NoSelectableObject:
-            return
+    @deprecated("use vreg['components'].select_object(...)")
+    def select_component(self, cid, *args, **kwargs):
+        return self['components'].select_object(cid, *args, **kwargs)
 
+    @deprecated("use vreg['actions'].select_object(...)")
     def select_action(self, oid, *args, **kwargs):
-        """return the most specific view according to the result set"""
-        try:
-            return self.select_object('actions', oid, *args, **kwargs)
-        except NoSelectableObject:
-            return
+        return self['actions'].select_object(oid, *args, **kwargs)
 
-    def select_component(self, cid, *args, **kwargs):
-        """return the most specific component according to the result set"""
-        try:
-            return self.select_object('components', cid, *args, **kwargs)
-        except (NoSelectableObject, ObjectNotFound):
-            return
-
+    @deprecated("use vreg['views'].select(...)")
     def select_view(self, __vid, req, rset=None, **kwargs):
-        """return the most specific view according to the result set"""
-        views = self.registry_objects('views', __vid)
-        return self.select(views, req, rset, **kwargs)
+        return self['views'].select(__vid, req, rset=rset, **kwargs)
 
     # properties handling #####################################################
 
@@ -307,7 +417,7 @@
     def register_property(self, key, type, help, default=None, vocabulary=None,
                           sitewide=False):
         """register a given property"""
-        properties = self._registries['propertydefs']
+        properties = self['propertydefs']
         assert type in YAMS_TO_PY
         properties[key] = {'type': type, 'vocabulary': vocabulary,
                            'default': default, 'help': help,
@@ -319,7 +429,7 @@
         boolean)
         """
         try:
-            return self._registries['propertydefs'][key]
+            return self['propertydefs'][key]
         except KeyError:
             if key.startswith('system.version.'):
                 soft = key.split('.')[-1]
@@ -330,9 +440,9 @@
 
     def property_value(self, key):
         try:
-            return self._registries['propertyvalues'][key]
+            return self['propertyvalues'][key]
         except KeyError:
-            return self._registries['propertydefs'][key]['default']
+            return self['propertydefs'][key]['default']
 
     def typed_value(self, key, value):
         """value is an unicode string, return it correctly typed. Let potential
@@ -355,7 +465,7 @@
         """init the property values registry using the given set of couple (key, value)
         """
         self.initialized = True
-        values = self._registries['propertyvalues']
+        values = self['propertyvalues']
         for key, val in propvalues:
             try:
                 values[key] = self.typed_value(key, val)
@@ -366,59 +476,6 @@
                 self.warning('%s (you should probably delete that property '
                              'from the database)', ex)
 
-    def parse(self, session, rql, args=None):
-        rqlst = self.rqlhelper.parse(rql)
-        def type_from_eid(eid, session=session):
-            return session.describe(eid)[0]
-        try:
-            self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
-        except UnknownEid:
-            for select in rqlst.children:
-                select.solutions = []
-        return rqlst
-
-    @property
-    @cached
-    def rqlhelper(self):
-        return RQLHelper(self.schema,
-                         special_relations={'eid': 'uid', 'has_text': 'fti'})
-
-
-class MulCnxCubicWebRegistry(CubicWebRegistry):
-    """special registry to be used when an application has to deal with
-    connections to differents repository. This class add some additional wrapper
-    trying to hide buggy class attributes since classes are not designed to be
-    shared.
-    """
-    def etype_class(self, etype):
-        """return an entity class for the given entity type.
-        Try to find out a specific class for this kind of entity or
-        default to a dump of the class registered for 'Any'
-        """
-        usercls = super(MulCnxCubicWebRegistry, self).etype_class(etype)
-        if etype == 'Any':
-            return usercls
-        usercls.e_schema = self.schema.eschema(etype)
-        return usercls
-
-    def select(self, vobjects, *args, **kwargs):
-        """return an instance of the most specific object according
-        to parameters
-
-        raise NoSelectableObject if not object apply
-        """
-        for vobject in vobjects:
-            vobject.vreg = self
-            vobject.schema = self.schema
-            vobject.config = self.config
-        selected = super(MulCnxCubicWebRegistry, self).select(vobjects, *args,
-                                                              **kwargs)
-        # redo the same thing on the instance so it won't use equivalent class
-        # attributes (which may change)
-        selected.vreg = self
-        selected.schema = self.schema
-        selected.config = self.config
-        return selected
 
 from datetime import datetime, date, time, timedelta
 
--- a/dbapi.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/dbapi.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,14 +13,71 @@
 
 from logging import getLogger
 from time import time, clock
+from itertools import count
 
 from logilab.common.logging_ext import set_log_methods
+from logilab.common.decorators import monkeypatch
+from logilab.common.deprecation import deprecated
+
 from cubicweb import ETYPE_NAME_MAP, ConnectionError, RequestSessionMixIn
-from cubicweb.cwvreg import CubicWebRegistry, MulCnxCubicWebRegistry
-from cubicweb.cwconfig import CubicWebNoAppConfiguration
+from cubicweb import cwvreg, cwconfig
 
 _MARKER = object()
 
+def _fake_property_value(self, name):
+    try:
+        return super(dbapi.DBAPIRequest, self).property_value(name)
+    except KeyError:
+        return ''
+
+def _fix_cls_attrs(reg, appobject):
+    appobject.vreg = reg.vreg
+    appobject.schema = reg.schema
+    appobject.config = reg.config
+
+def multiple_connections_fix():
+    """some monkey patching necessary when an application has to deal with
+    several connections to different repositories. It tries to hide buggy class
+    attributes since classes are not designed to be shared among multiple
+    registries.
+    """
+    defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
+    orig_select_best = defaultcls.orig_select_best = defaultcls.select_best
+    @monkeypatch(defaultcls)
+    def select_best(self, appobjects, *args, **kwargs):
+        """return an instance of the most specific object according
+        to parameters
+
+        raise NoSelectableObject if no object apply
+        """
+        for appobjectcls in appobjects:
+            _fix_cls_attrs(self, appobjectcls)
+        selected = orig_select_best(self, appobjects, *args, **kwargs)
+        # redo the same thing on the instance so it won't use equivalent class
+        # attributes (which may change)
+        _fix_cls_attrs(self, selected)
+        return selected
+
+    etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
+    orig_etype_class = etypescls.orig_etype_class = etypescls.etype_class
+    @monkeypatch(defaultcls)
+    def etype_class(self, etype):
+        """return an entity class for the given entity type.
+        Try to find out a specific class for this kind of entity or
+        default to a dump of the class registered for 'Any'
+        """
+        usercls = orig_etype_class(self, etype)
+        if etype == 'Any':
+            return usercls
+        usercls.e_schema = self.schema.eschema(etype)
+        return usercls
+
+def multiple_connections_unfix():
+    defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
+    defaultcls.select_best = defaultcls.orig_select_best
+    etypescls = cwvreg.VRegistry.REGISTRY_FACTORY['etypes']
+    etypescls.etype_class = etypescls.orig_etype_class
+
 class ConnectionProperties(object):
     def __init__(self, cnxtype=None, lang=None, close=True, log=False):
         self.cnxtype = cnxtype or 'pyro'
@@ -44,24 +101,14 @@
         from cubicweb.server.repository import Repository
         return Repository(config, vreg=vreg)
     else: # method == 'pyro'
-        from Pyro import core, naming
-        from Pyro.errors import NamingError, ProtocolError
-        core.initClient(banner=0)
-        nsid = ':%s.%s' % (config['pyro-ns-group'], database)
-        locator = naming.NameServerLocator()
         # resolve the Pyro object
+        from logilab.common.pyro_ext import ns_get_proxy
         try:
-            nshost, nsport = config['pyro-ns-host'], config['pyro-ns-port']
-            uri = locator.getNS(nshost, nsport).resolve(nsid)
-        except ProtocolError:
-            raise ConnectionError('Could not connect to the Pyro name server '
-                                  '(host: %s:%i)' % (nshost, nsport))
-        except NamingError:
-            raise ConnectionError('Could not get repository for %s '
-                                  '(not registered in Pyro), '
-                                  'you may have to restart your server-side '
-                                  'application' % nsid)
-        return core.getProxyForURI(uri)
+            return ns_get_proxy(database,
+                                defaultnsgroup=config['pyro-ns-group'],
+                                nshost=config['pyro-ns-host'])
+        except Exception, ex:
+            raise ConnectionError(str(ex))
 
 def repo_connect(repo, login, password, cnxprops=None):
     """Constructor to create a new connection to the CubicWeb repository.
@@ -75,22 +122,18 @@
         cnx.vreg = repo.vreg
     return cnx
 
-def connect(database=None, login=None, password=None, host=None,
-            group=None, cnxprops=None, port=None, setvreg=True, mulcnx=True,
-            initlog=True):
+def connect(database=None, login=None, password=None, host=None, group=None,
+            cnxprops=None, setvreg=True, mulcnx=True, initlog=True):
     """Constructor for creating a connection to the CubicWeb repository.
     Returns a Connection object.
 
-    When method is 'pyro' and setvreg is True, use a special registry class
-    (MulCnxCubicWebRegistry) made to deal with connections to differents instances
-    in the same process unless specified otherwise by setting the mulcnx to
-    False.
+    When method is 'pyro', setvreg is True, try to deal with connections to
+    differents instances in the same process unless specified otherwise by
+    setting the mulcnx to False.
     """
-    config = CubicWebNoAppConfiguration()
+    config = cwconfig.CubicWebNoAppConfiguration()
     if host:
         config.global_set_option('pyro-ns-host', host)
-    if port:
-        config.global_set_option('pyro-ns-port', port)
     if group:
         config.global_set_option('pyro-ns-group', group)
     cnxprops = cnxprops or ConnectionProperties()
@@ -100,9 +143,8 @@
         vreg = repo.vreg
     elif setvreg:
         if mulcnx:
-            vreg = MulCnxCubicWebRegistry(config, initlog=initlog)
-        else:
-            vreg = CubicWebRegistry(config, initlog=initlog)
+            multiple_connections_fix()
+        vreg = cwvreg.CubicWebVRegistry(config, initlog=initlog)
         schema = repo.get_schema()
         for oldetype, newetype in ETYPE_NAME_MAP.items():
             if oldetype in schema:
@@ -119,7 +161,7 @@
     """usefull method for testing and scripting to get a dbapi.Connection
     object connected to an in-memory repository instance
     """
-    if isinstance(config, CubicWebRegistry):
+    if isinstance(config, cwvreg.CubicWebVRegistry):
         vreg = config
         config = None
     else:
@@ -394,7 +436,8 @@
             raise ProgrammingError('Closed connection')
         return self._repo.get_schema()
 
-    def load_vobjects(self, cubes=_MARKER, subpath=None, expand=True, force_reload=None):
+    def load_appobjects(self, cubes=_MARKER, subpath=None, expand=True,
+                      force_reload=None):
         config = self.vreg.config
         if cubes is _MARKER:
             cubes = self._repo.get_cubes()
@@ -422,10 +465,37 @@
             hm, config = self._repo.hm, self._repo.config
             hm.set_schema(hm.schema) # reset structure
             hm.register_system_hooks(config)
-            # application specific hooks
-            if self._repo.config.application_hooks:
+            # instance specific hooks
+            if self._repo.config.instance_hooks:
                 hm.register_hooks(config.load_hooks(self.vreg))
 
+    load_vobjects = deprecated()(load_appobjects)
+
+    def use_web_compatible_requests(self, baseurl, sitetitle=None):
+        """monkey patch DBAPIRequest to fake a cw.web.request, so you should
+        able to call html views using rset from a simple dbapi connection.
+
+        You should call `load_appobjects` at some point to register those views.
+        """
+        from cubicweb.web.request import CubicWebRequestBase as cwrb
+        DBAPIRequest.build_ajax_replace_url = cwrb.build_ajax_replace_url.im_func
+        DBAPIRequest.list_form_param = cwrb.list_form_param.im_func
+        DBAPIRequest.property_value = _fake_property_value
+        DBAPIRequest.next_tabindex = count().next
+        DBAPIRequest.form = {}
+        DBAPIRequest.data = {}
+        fake = lambda *args, **kwargs: None
+        DBAPIRequest.relative_path = fake
+        DBAPIRequest.url = fake
+        DBAPIRequest.next_tabindex = fake
+        DBAPIRequest.add_js = fake #cwrb.add_js.im_func
+        DBAPIRequest.add_css = fake #cwrb.add_css.im_func
+        # XXX could ask the repo for it's base-url configuration
+        self.vreg.config.set_option('base-url', baseurl)
+        # XXX why is this needed? if really needed, could be fetched by a query
+        if sitetitle is not None:
+            self.vreg['propertydefs']['ui.site-title'] = {'default': sitetitle}
+
     def source_defs(self):
         """Return the definition of sources used by the repository.
 
@@ -443,8 +513,9 @@
         if req is None:
             req = self.request()
         rset = req.eid_rset(eid, 'CWUser')
-        user = self.vreg.etype_class('CWUser')(req, rset, row=0, groups=groups,
-                                               properties=properties)
+        user = self.vreg['etypes'].etype_class('CWUser')(req, rset, row=0,
+                                                         groups=groups,
+                                                         properties=properties)
         user['login'] = login # cache login
         return user
 
--- a/debian/changelog	Fri Aug 07 12:20:37 2009 +0200
+++ b/debian/changelog	Fri Aug 07 12:20:50 2009 +0200
@@ -1,3 +1,9 @@
+cubicweb (3.4.0-1) unstable; urgency=low
+
+  * new upstream release
+
+ -- Sylvain Thénault <sylvain.thenault@logilab.fr>  Fri, 07 Aug 2009 10:43:21 +0200
+
 cubicweb (3.3.5-1) unstable; urgency=low
 
   * new upstream release
--- a/debian/control	Fri Aug 07 12:20:37 2009 +0200
+++ b/debian/control	Fri Aug 07 12:20:50 2009 +0200
@@ -62,7 +62,7 @@
 Architecture: all
 XB-Python-Version: ${python:Versions}
 Depends: ${python:Depends}, cubicweb-common (= ${source:Version}), python-simplejson (>= 1.3), python-elementtree
-Recommends: python-docutils, python-vobject, fckeditor
+Recommends: python-docutils, python-vobject, fckeditor, python-fyzz
 Description: web interface library for the CubicWeb framework
  CubicWeb is a semantic web application framework.
  .
@@ -76,8 +76,8 @@
 Package: cubicweb-common
 Architecture: all
 XB-Python-Version: ${python:Versions}
-Depends: ${python:Depends}, graphviz, gettext, python-logilab-mtconverter (>= 0.6.0), python-logilab-common (>= 0.43.0), python-yams (>= 0.23.0), python-rql (>= 0.22.1)
-Recommends: python-simpletal (>= 4.0), python-lxml
+Depends: ${python:Depends}, graphviz, gettext, python-logilab-mtconverter (>= 0.6.0), python-logilab-common (>= 0.44.0), python-yams (>= 0.24.0), python-rql (>= 0.22.1), python-lxml
+Recommends: python-simpletal (>= 4.0)
 Conflicts: cubicweb-core
 Replaces: cubicweb-core
 Description: common library for the CubicWeb framework
--- a/devtools/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -43,7 +43,7 @@
 class TestServerConfiguration(ServerConfiguration):
     mode = 'test'
     set_language = False
-    read_application_schema = False
+    read_instance_schema = False
     bootstrap_schema = False
     init_repository = True
     options = merge_options(ServerConfiguration.options + (
@@ -77,12 +77,12 @@
     def apphome(self):
         if exists(self.appid):
             return abspath(self.appid)
-        # application cube test
+        # cube test
         return abspath('..')
     appdatahome = apphome
 
     def main_config_file(self):
-        """return application's control configuration file"""
+        """return instance's control configuration file"""
         return join(self.apphome, '%s.conf' % self.name)
 
     def instance_md5_version(self):
@@ -142,14 +142,14 @@
 class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration):
     repo_method = 'inmemory'
     options = merge_options(TestServerConfiguration.options + TwistedConfiguration.options)
-    cubicweb_vobject_path = TestServerConfiguration.cubicweb_vobject_path | TwistedConfiguration.cubicweb_vobject_path
-    cube_vobject_path = TestServerConfiguration.cube_vobject_path | TwistedConfiguration.cube_vobject_path
+    cubicweb_appobject_path = TestServerConfiguration.cubicweb_appobject_path | TwistedConfiguration.cubicweb_appobject_path
+    cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path
 
     def available_languages(self, *args):
         return ('en', 'fr', 'de')
 
     def ext_resources_file(self):
-        """return application's external resources file"""
+        """return instance's external resources file"""
         return join(self.apphome, 'data', 'external_resources')
 
     def pyro_enabled(self):
@@ -235,14 +235,14 @@
         # XXX I'm afraid this test will prevent to run test from a production
         # environment
         self._sources = None
-        # application cube test
+        # instance cube test
         if cube is not None:
             self.apphome = self.cube_dir(cube)
         elif 'web' in os.getcwd().split(os.sep):
             # web test
             self.apphome = join(normpath(join(dirname(__file__), '..')), 'web')
         else:
-            # application cube test
+            # cube test
             self.apphome = abspath('..')
         self.sourcefile = sourcefile
         self.global_set_option('realm', '')
--- a/devtools/_apptest.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/_apptest.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 import yams.schema
 
 from cubicweb.dbapi import repo_connect, ConnectionProperties, ProgrammingError
-from cubicweb.cwvreg import CubicWebRegistry
+from cubicweb.cwvreg import CubicWebVRegistry
 
 from cubicweb.web.application import CubicWebPublisher
 from cubicweb.web import Redirect
@@ -79,7 +79,7 @@
         source = config.sources()['system']
         if verbose:
             print "init test database ..."
-        self.vreg = vreg = CubicWebRegistry(config)
+        self.vreg = vreg = CubicWebVRegistry(config)
         self.admlogin = source['db-user']
         # restore database <=> init database
         self.restore_database()
@@ -177,7 +177,7 @@
                 self.create_request(rql=rql, **optional_args or {}))
 
     def check_view(self, rql, vid, optional_args, template='main'):
-        """checks if vreg.view() raises an exception in this environment
+        """checks if rendering view raises an exception in this environment
 
         If any exception is raised in this method, it will be considered
         as a TestFailure
@@ -186,17 +186,16 @@
                               template=template, optional_args=optional_args)
 
     def call_view(self, vid, rql, template='main', optional_args=None):
-        """shortcut for self.vreg.view()"""
         assert template
         if optional_args is None:
             optional_args = {}
         optional_args['vid'] = vid
         req = self.create_request(rql=rql, **optional_args)
-        return self.vreg.main_template(req, template)
+        return self.vreg['views'].main_template(req, template)
 
     def call_edit(self, req):
         """shortcut for self.app.edit()"""
-        controller = self.app.select_controller('edit', req)
+        controller = self.vreg.select('controllers', 'edit', req)
         try:
             controller.publish()
         except Redirect:
@@ -208,7 +207,7 @@
 
     def iter_possible_views(self, req, rset):
         """returns a list of possible vids for <rql>"""
-        for view in self.vreg.possible_views(req, rset):
+        for view in self.vreg['views'].possible_views(req, rset):
             if view.category == 'startupview':
                 continue
             yield view.id
@@ -217,14 +216,14 @@
 
     def iter_startup_views(self, req):
         """returns the list of startup views"""
-        for view in self.vreg.possible_views(req, None):
+        for view in self.vreg['views'].possible_views(req, None):
             if view.category != 'startupview':
                 continue
             yield view.id
 
     def iter_possible_actions(self, req, rset):
         """returns a list of possible vids for <rql>"""
-        for action in self.vreg.possible_vobjects('actions', req, rset):
+        for action in self.vreg.possible_vobjects('actions', req, rset=rset):
             yield action
 
 class ExistingTestEnvironment(TestEnvironment):
@@ -234,7 +233,7 @@
         if verbose:
             print "init test database ..."
         source = config.sources()['system']
-        self.vreg = CubicWebRegistry(config)
+        self.vreg = CubicWebVRegistry(config)
         self.cnx = init_test_database(driver=source['db-driver'],
                                       vreg=self.vreg)[1]
         if verbose:
--- a/devtools/apptest.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/apptest.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-"""This module provides misc utilities to test applications
+"""This module provides misc utilities to test instances
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -15,7 +15,7 @@
 from logilab.common.pytest import nocoverage
 from logilab.common.umessage import message_from_string
 
-from logilab.common.deprecation import deprecated_function
+from logilab.common.deprecation import deprecated
 
 from cubicweb.devtools import init_test_database, TestServerConfiguration, ApptestConfiguration
 from cubicweb.devtools._apptest import TestEnvironment
@@ -34,6 +34,14 @@
     def message(self):
         return message_from_string(self.msg)
 
+    @property
+    def subject(self):
+        return self.message.get('Subject')
+
+    @property
+    def content(self):
+        return self.message.get_payload(decode=True)
+
     def __repr__(self):
         return '<Email to %s with subject %s>' % (','.join(self.recipients),
                                                   self.message.get('Subject'))
@@ -51,7 +59,7 @@
 
 
 def get_versions(self, checkversions=False):
-    """return the a dictionary containing cubes used by this application
+    """return the a dictionary containing cubes used by this instance
     as key with their version as value, including cubicweb version. This is a
     public method, not requiring a session id.
 
@@ -167,7 +175,7 @@
 
     def etype_instance(self, etype, req=None):
         req = req or self.request()
-        e = self.env.vreg.etype_class(etype)(req, None, None)
+        e = self.env.vreg['etypes'].etype_class(etype)(req)
         e.eid = None
         return e
 
@@ -216,21 +224,21 @@
         self.vreg.config.global_set_option(optname, value)
 
     def pviews(self, req, rset):
-        return sorted((a.id, a.__class__) for a in self.vreg.possible_views(req, rset))
+        return sorted((a.id, a.__class__) for a in self.vreg['views'].possible_views(req, rset=rset))
 
     def pactions(self, req, rset, skipcategories=('addrelated', 'siteactions', 'useractions')):
-        return [(a.id, a.__class__) for a in self.vreg.possible_vobjects('actions', req, rset)
+        return [(a.id, a.__class__) for a in self.vreg['actions'].possible_vobjects(req, rset=rset)
                 if a.category not in skipcategories]
 
     def pactions_by_cats(self, req, rset, categories=('addrelated',)):
-        return [(a.id, a.__class__) for a in self.vreg.possible_vobjects('actions', req, rset)
+        return [(a.id, a.__class__) for a in self.vreg['actions'].possible_vobjects(req, rset=rset)
                 if a.category in categories]
 
-    paddrelactions = deprecated_function(pactions_by_cats)
+    paddrelactions = deprecated()(pactions_by_cats)
 
     def pactionsdict(self, req, rset, skipcategories=('addrelated', 'siteactions', 'useractions')):
         res = {}
-        for a in self.vreg.possible_vobjects('actions', req, rset):
+        for a in self.vreg['actions'].possible_vobjects(req, rset=rset):
             if a.category not in skipcategories:
                 res.setdefault(a.category, []).append(a.__class__)
         return res
@@ -241,7 +249,7 @@
         dump = simplejson.dumps
         args = [dump(arg) for arg in args]
         req = self.request(fname=fname, pageid='123', arg=args)
-        ctrl = self.env.app.select_controller('json', req)
+        ctrl = self.vreg['controllers'].select('json', req)
         return ctrl.publish(), req
 
     # default test setup and teardown #########################################
@@ -286,7 +294,7 @@
         def setUp(self):
             super(ControllerTC, self).setUp()
             self.req = self.request()
-            self.ctrl = self.env.app.select_controller('edit', self.req)
+            self.ctrl = self.vreg['controllers'].select('edit', self.req)
 
         def publish(self, req):
             assert req is self.ctrl.req
@@ -300,7 +308,7 @@
 
         def expect_redirect_publish(self, req=None):
             if req is not None:
-                self.ctrl = self.env.app.select_controller('edit', req)
+                self.ctrl = self.vreg['controllers'].select('edit', req)
             else:
                 req = self.req
             try:
@@ -398,7 +406,7 @@
         rset.vreg = self.vreg
         rset.req = self.session
         # call to set_pool is necessary to avoid pb when using
-        # application entities for convenience
+        # instance entities for convenience
         self.session.set_pool()
         return rset
 
@@ -449,7 +457,6 @@
     pactionsdict = EnvBasedTC.pactionsdict.im_func
 
     # default test setup and teardown #########################################
-    copy_schema = False
 
     def _prepare(self):
         MAILBOX[:] = [] # reset mailbox
@@ -462,16 +469,6 @@
         self.__close = repo.close
         self.cnxid = self.cnx.sessionid
         self.session = repo._sessions[self.cnxid]
-        if self.copy_schema:
-            # XXX copy schema since hooks may alter it and it may be not fully
-            #     cleaned (missing some schema synchronization support)
-            try:
-                origschema = repo.__schema
-            except AttributeError:
-                repo.__schema = origschema = repo.schema
-            repo.schema = deepcopy(origschema)
-            repo.set_schema(repo.schema) # reset hooks
-            repo.vreg.update_schema(repo.schema)
         self.cnxs = []
         # reset caches, they may introduce bugs among tests
         repo._type_source_cache = {}
--- a/devtools/devctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/devctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -12,25 +12,25 @@
 from datetime import datetime
 from os import mkdir, chdir
 from os.path import join, exists, abspath, basename, normpath, split, isdir
-
+from warnings import warn
 
 from logilab.common import STD_BLACKLIST
 from logilab.common.modutils import get_module_files
-from logilab.common.textutils import get_csv
+from logilab.common.textutils import splitstrip
+from logilab.common.shellutils import ASK
 from logilab.common.clcommands import register_commands
 
 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, underline_title
 from cubicweb.__pkginfo__ import version as cubicwebversion
-from cubicweb.toolsutils import Command, confirm, copy_skeleton
+from cubicweb.toolsutils import Command, copy_skeleton
 from cubicweb.web.webconfig import WebConfiguration
 from cubicweb.server.serverconfig import ServerConfiguration
 
-
 class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
     """dummy config to get full library schema and entities"""
     creating = True
-    cubicweb_vobject_path = ServerConfiguration.cubicweb_vobject_path | WebConfiguration.cubicweb_vobject_path
-    cube_vobject_path = ServerConfiguration.cube_vobject_path | WebConfiguration.cube_vobject_path
+    cubicweb_appobject_path = ServerConfiguration.cubicweb_appobject_path | WebConfiguration.cubicweb_appobject_path
+    cube_appobject_path = ServerConfiguration.cube_appobject_path | WebConfiguration.cube_appobject_path
 
     def __init__(self, cube):
         super(DevCubeConfiguration, self).__init__(cube)
@@ -90,7 +90,7 @@
     notice that relation definitions description and static vocabulary
     should be marked using '_' and extracted using xgettext
     """
-    from cubicweb.cwvreg import CubicWebRegistry
+    from cubicweb.cwvreg import CubicWebVRegistry
     cube = cubedir and split(cubedir)[-1]
     libconfig = DevDepConfiguration(cube)
     libconfig.cleanup_interface_sobjects = False
@@ -102,7 +102,7 @@
         config = libconfig
         libconfig = None
     schema = config.load_schema(remove_unused_rtypes=False)
-    vreg = CubicWebRegistry(config)
+    vreg = CubicWebVRegistry(config)
     # set_schema triggers objects registrations
     vreg.set_schema(schema)
     w(DEFAULT_POT_HEAD)
@@ -187,8 +187,8 @@
     #cube = (cube and 'cubes.%s.' % cube or 'cubicweb.')
     done = set()
     if libconfig is not None:
-        from cubicweb.cwvreg import CubicWebRegistry
-        libvreg = CubicWebRegistry(libconfig)
+        from cubicweb.cwvreg import CubicWebVRegistry
+        libvreg = CubicWebVRegistry(libconfig)
         libvreg.set_schema(libschema) # trigger objects registration
         # prefill done set
         list(_iter_vreg_objids(libvreg, done))
@@ -254,14 +254,13 @@
         if args:
             raise BadCommandUsage('Too much arguments')
         import shutil
-        from tempfile import mktemp
+        import tempfile
         import yams
         from logilab.common.fileutils import ensure_fs_mode
         from logilab.common.shellutils import globfind, find, rm
         from cubicweb.common.i18n import extract_from_tal, execute
-        tempdir = mktemp()
-        mkdir(tempdir)
-        potfiles = [join(I18NDIR, 'entities.pot')]
+        tempdir = tempfile.mkdtemp()
+        potfiles = [join(I18NDIR, 'static-messages.pot')]
         print '-> extract schema messages.'
         schemapot = join(tempdir, 'schema.pot')
         potfiles.append(schemapot)
@@ -328,8 +327,8 @@
 
 
 def update_cubes_catalogs(cubes):
-    toedit = []
     for cubedir in cubes:
+        toedit = []
         if not isdir(cubedir):
             print '-> ignoring %s that is not a directory.' % cubedir
             continue
@@ -338,27 +337,34 @@
         except Exception:
             import traceback
             traceback.print_exc()
-            print '-> Error while updating catalogs for cube', cubedir
-    # instructions pour la suite
-    print '-> regenerated this cube\'s .po catalogs.'
-    print '\nYou can now edit the following files:'
-    print '* ' + '\n* '.join(toedit)
-    print 'when you are done, run "cubicweb-ctl i18ninstance yourinstance".'
+            print '-> error while updating catalogs for cube', cubedir
+        else:
+            # instructions pour la suite
+            print '-> regenerated .po catalogs for cube %s.' % cubedir
+            print '\nYou can now edit the following files:'
+            print '* ' + '\n* '.join(toedit)
+            print ('When you are done, run "cubicweb-ctl i18ninstance '
+                   '<yourinstance>" to see changes in your instances.')
 
 def update_cube_catalogs(cubedir):
     import shutil
-    from tempfile import mktemp
+    import tempfile
     from logilab.common.fileutils import ensure_fs_mode
     from logilab.common.shellutils import find, rm
     from cubicweb.common.i18n import extract_from_tal, execute
     toedit = []
     cube = basename(normpath(cubedir))
-    tempdir = mktemp()
-    mkdir(tempdir)
+    tempdir = tempfile.mkdtemp()
     print underline_title('Updating i18n catalogs for cube %s' % cube)
     chdir(cubedir)
-    potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
-                if exists(join('i18n', scfile))]
+    if exists(join('i18n', 'entities.pot')):
+        warn('entities.pot is deprecated, rename file to static-messages.pot (%s)'
+             % join('i18n', 'entities.pot'), DeprecationWarning)
+        potfiles = [join('i18n', 'entities.pot')]
+    elif exists(join('i18n', 'static-messages.pot')):
+        potfiles = [join('i18n', 'static-messages.pot')]
+    else:
+        potfiles = []
     print '-> extract schema messages'
     schemapot = join(tempdir, 'schema.pot')
     potfiles.append(schemapot)
@@ -477,7 +483,7 @@
                                       " Please specify it using the --directory option")
             cubesdir = cubespath[0]
         if not isdir(cubesdir):
-            print "creating cubes directory", cubesdir
+            print "-> creating cubes directory", cubesdir
             try:
                 mkdir(cubesdir)
             except OSError, err:
@@ -486,19 +492,20 @@
         if exists(cubedir):
             self.fail("%s already exists !" % (cubedir))
         skeldir = join(BASEDIR, 'skeleton')
+        default_name = 'cubicweb-%s' % cubename.lower()
         if verbose:
-            distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip()
+            distname = raw_input('Debian name for your cube ? [%s]): ' % default_name).strip()
             if not distname:
-                distname = 'cubicweb-%s' % cubename.lower()
+                distname = default_name
             elif not distname.startswith('cubicweb-'):
-                if confirm('do you mean cubicweb-%s ?' % distname):
+                if ASK.confirm('Do you mean cubicweb-%s ?' % distname):
                     distname = 'cubicweb-' + distname
         else:
-            distname = 'cubicweb-%s' % cubename.lower()
+            distname = default_name
 
         longdesc = shortdesc = raw_input('Enter a short description for your cube: ')
         if verbose:
-            longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ')
+            longdesc = raw_input('Enter a long description (leave empty to reuse the short one): ')
         if verbose:
             includes = self._ask_for_dependancies()
             if len(includes) == 1:
@@ -523,14 +530,14 @@
     def _ask_for_dependancies(self):
         includes = []
         for stdtype in ServerConfiguration.available_cubes():
-            ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)"
-                            % stdtype).lower().strip()
-            if ans == 'y':
+            answer = ASK.ask("Depends on cube %s? " % stdtype,
+                             ('N','y','skip','type'), 'N')
+            if answer == 'y':
                 includes.append(stdtype)
-            if ans == 't':
-                includes = get_csv(raw_input('type dependancies: '))
+            if answer == 'type':
+                includes = splitstrip(raw_input('type dependancies: '))
                 break
-            elif ans == 's':
+            elif answer == 'skip':
                 break
         return includes
 
--- a/devtools/fake.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/fake.py	Fri Aug 07 12:20:50 2009 +0200
@@ -35,27 +35,21 @@
     def sources(self):
         return {}
 
-class FakeVReg(object):
+class FakeVReg(dict):
     def __init__(self, schema=None, config=None):
         self.schema = schema
         self.config = config or FakeConfig()
         self.properties = {'ui.encoding': 'UTF8',
                            'ui.language': 'en',
                            }
+        self.update({
+            'controllers' : {'login': []},
+            'views' : {},
+            })
 
     def property_value(self, key):
         return self.properties[key]
 
-    _registries = {
-        'controllers' : [Mock(id='view'), Mock(id='login'),
-                         Mock(id='logout'), Mock(id='edit')],
-        'views' : [Mock(id='primary'), Mock(id='secondary'),
-                         Mock(id='oneline'), Mock(id='list')],
-        }
-
-    def registry_objects(self, name, oid=None):
-        return self._registries[name]
-
     def etype_class(self, etype):
         class Entity(dict):
             e_schema = self.schema[etype]
@@ -88,12 +82,12 @@
         return None
 
     def base_url(self):
-        """return the root url of the application"""
+        """return the root url of the instance"""
         return BASE_URL
 
     def relative_path(self, includeparams=True):
         """return the normalized path of the request (ie at least relative
-        to the application's root, but some other normalization may be needed
+        to the instance's root, but some other normalization may be needed
         so that the returned path may be used to compare to generated urls
         """
         if self._url.startswith(BASE_URL):
@@ -154,6 +148,25 @@
         return self.execute(*args, **kwargs)
 
 
+# class FakeRequestNoCnx(FakeRequest):
+#     def get_session_data(self, key, default=None, pop=False):
+#         """return value associated to `key` in session data"""
+#         if pop:
+#             return self._session_data.pop(key, default)
+#         else:
+#             return self._session_data.get(key, default)
+
+#     def set_session_data(self, key, value):
+#         """set value associated to `key` in session data"""
+#         self._session_data[key] = value
+
+#     def del_session_data(self, key):
+#         try:
+#             del self._session_data[key]
+#         except KeyError:
+#             pass
+
+
 class FakeUser(object):
     login = 'toto'
     eid = 0
@@ -174,7 +187,7 @@
     def execute(self, *args):
         pass
     unsafe_execute = execute
-    
+
     def commit(self, *args):
         self.transaction_data.clear()
     def close(self, *args):
--- a/devtools/fill.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/fill.py	Fri Aug 07 12:20:50 2009 +0200
@@ -225,7 +225,7 @@
     :param etype: the entity's type
 
     :type schema: cubicweb.schema.Schema
-    :param schema: the application schema
+    :param schema: the instance schema
 
     :type entity_num: int
     :param entity_num: the number of entities to insert
@@ -325,7 +325,7 @@
 def make_relations_queries(schema, edict, cursor, ignored_relations=(),
                            existingrels=None):
     """returns a list of generated RQL queries for relations
-    :param schema: The application schema
+    :param schema: The instance schema
 
     :param e_dict: mapping between etypes and eids
 
--- a/devtools/pkginfo.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-"""distutils / __pkginfo__ helpers for cubicweb applications
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-import os
-from os.path import isdir, join
-
-
-def get_distutils_datafiles(cube, i18n=True, recursive=False):
-    """
-    :param cube: application cube's name
-    """
-    data_files = []
-    data_files += get_basepyfiles(cube)
-    data_files += get_webdatafiles(cube)
-    if i18n:
-        data_files += get_i18nfiles(cube)
-    data_files += get_viewsfiles(cube, recursive=recursive)
-    data_files += get_migrationfiles(cube)
-    data_files += get_schemafiles(cube)
-    return data_files
-
-
-
-## listdir filter funcs ################################################
-def nopyc_and_nodir(fname):
-    if isdir(fname) or fname.endswith('.pyc') or fname.endswith('~'):
-        return False
-    return True
-
-def no_version_control(fname):
-    if fname in ('CVS', '.svn', '.hg'):
-        return False
-    if fname.endswith('~'):
-        return False
-    return True
-
-def basepy_files(fname):
-    if fname.endswith('.py') and fname != 'setup.py':
-        return True
-    return False
-
-def chain(*filters):
-    def newfilter(fname):
-        for filterfunc in filters:
-            if not filterfunc(fname):
-                return False
-        return True
-    return newfilter
-
-def listdir_with_path(path='.', filterfunc=None):
-    if filterfunc:
-        return [join(path, fname) for fname in os.listdir(path) if filterfunc(join(path, fname))]
-    else:
-        return [join(path, fname) for fname in os.listdir(path)]
-
-
-## data_files helpers ##################################################
-CUBES_DIR = join('share', 'cubicweb', 'cubes')
-
-def get_i18nfiles(cube):
-    """returns i18n files in a suitable format for distutils's
-    data_files parameter
-    """
-    i18ndir = join(CUBES_DIR, cube, 'i18n')
-    potfiles = [(i18ndir, listdir_with_path('i18n', chain(no_version_control, nopyc_and_nodir)))]
-    return potfiles
-
-
-def get_viewsfiles(cube, recursive=False):
-    """returns views files in a suitable format for distutils's
-    data_files parameter
-
-    :param recursive: include views' subdirs recursively if True
-    """
-    if recursive:
-        datafiles = []
-        for dirpath, dirnames, filenames in os.walk('views'):
-            filenames = [join(dirpath, fname) for fname in filenames
-                         if nopyc_and_nodir(join(dirpath, fname))]
-            dirpath = join(CUBES_DIR, cube, dirpath)
-            datafiles.append((dirpath, filenames))
-        return datafiles
-    else:
-        viewsdir = join(CUBES_DIR, cube, 'views')
-        return [(viewsdir,
-                 listdir_with_path('views', filterfunc=nopyc_and_nodir))]
-
-
-def get_basepyfiles(cube):
-    """returns cube's base python scripts (tali18n.py, etc.)
-    in a suitable format for distutils's data_files parameter
-    """
-    return [(join(CUBES_DIR, cube),
-             [fname for fname in os.listdir('.')
-              if fname.endswith('.py') and fname != 'setup.py'])]
-
-
-def get_webdatafiles(cube):
-    """returns web's data files (css, png, js, etc.) in a suitable
-    format for distutils's data_files parameter
-    """
-    return [(join(CUBES_DIR, cube, 'data'),
-             listdir_with_path('data', filterfunc=no_version_control))]
-
-
-def get_migrationfiles(cube):
-    """returns cube's migration scripts
-    in a suitable format for distutils's data_files parameter
-    """
-    return [(join(CUBES_DIR, cube, 'migration'),
-             listdir_with_path('migration', no_version_control))]
-
-
-def get_schemafiles(cube):
-    """returns cube's schema files
-    in a suitable format for distutils's data_files parameter
-    """
-    return [(join(CUBES_DIR, cube, 'schema'),
-             listdir_with_path('schema', no_version_control))]
-
-
--- a/devtools/stresstester.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/stresstester.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-""" Usage: %s [OPTIONS] <application id> <queries file>
+""" Usage: %s [OPTIONS] <instance id> <queries file>
 
 Stress test a CubicWeb repository
 
@@ -151,8 +151,8 @@
         user = raw_input('login: ')
     if password is None:
         password = getpass('password: ')
-    from cubicweb.cwconfig import application_configuration
-    config = application_configuration(args[0])
+    from cubicweb.cwconfig import instance_configuration
+    config = instance_configuration(args[0])
     # get local access to the repository
     print "Creating repo", prof_file
     repo = Repository(config, prof_file)
--- a/devtools/test/data/bootstrap_cubes	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/test/data/bootstrap_cubes	Fri Aug 07 12:20:50 2009 +0200
@@ -1,1 +1,1 @@
-person, comment
+person
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/devtools/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,20 @@
+"""
+
+:organization: Logilab
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+from yams.buildobjs import EntityType, SubjectRelation, String, Int, Date
+
+from cubes.person.schema import Person
+
+Person.add_relation(Date(), 'birthday')
+
+class Bug(EntityType):
+    title = String(maxsize=64, required=True, fulltextindexed=True)
+    severity = String(vocabulary=('important', 'normal', 'minor'), default='normal')
+    cost = Int()
+    description	= String(maxsize=4096, fulltextindexed=True)
+    identical_to = SubjectRelation('Bug', symetric=True)
+
--- a/devtools/test/data/schema/Bug.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-title		ivarchar(64) not null
-state		CHOICE('open', 'rejected', 'validation pending', 'resolved') default 'open'
-severity	CHOICE('important', 'normal', 'minor') default 'normal'
-cost 		integer
-description	ivarchar(4096)
--- a/devtools/test/data/schema/Project.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-name		ivarchar(64) not null
-summary		ivarchar(128)	
-vcsurl		varchar(256)
-reporturl	varchar(256)
-description	ivarchar(1024)
-url		varchar(128)
--- a/devtools/test/data/schema/Story.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-title		ivarchar(64) not null
-state		CHOICE('open', 'rejected', 'validation pending', 'resolved') default 'open'
-priority	CHOICE('minor', 'normal', 'important') default 'normal'
-cost	        integer
-description	ivarchar(4096)
--- a/devtools/test/data/schema/Version.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-num	varchar(16) not null
-diem	date	
-status 	CHOICE('planned', 'dev', 'published') default 'planned'
--- a/devtools/test/data/schema/custom.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-Person = import_erschema('Person')
-Person.add_relation(Date(), 'birthday')
--- a/devtools/test/data/schema/relations.rel	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-Bug concerns Project inline
-Story concerns Project inline
-
-Bug corrected_in Version inline CONSTRAINT E concerns P, X version_of P
-Story done_in Version inline CONSTRAINT E concerns P, X version_of P
-
-Bug   identical_to Bug   symetric
-Bug   identical_to Story symetric
-Story identical_to Story symetric
-
-Story depends_on Story
-Story depends_on Bug
-Bug   depends_on Story
-Bug   depends_on Bug
-
-Bug     see_also Bug	 symetric
-Bug	see_also Story	 symetric
-Bug	see_also Project symetric
-Story	see_also Story	 symetric
-Story	see_also Project symetric
-Project see_also Project symetric
-
-Project uses Project
-
-Version version_of Project inline
-Version todo_by CWUser
-
-Comment about Bug inline
-Comment about Story inline
-Comment about Comment inline
-
-CWUser interested_in Project
-
--- a/devtools/testlib.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/devtools/testlib.py	Fri Aug 07 12:20:50 2009 +0200
@@ -44,7 +44,7 @@
     # compute how many entities by type we need to be able to satisfy relation constraint
     relmap = {}
     for rschema in schema.relations():
-        if rschema.meta or rschema.is_final(): # skip meta relations
+        if rschema.is_final():
             continue
         for subj, obj in rschema.iter_rdefs():
             card = rschema.rproperty(subj, obj, 'cardinality')
@@ -172,7 +172,8 @@
         return validator.parse_string(output.strip())
 
 
-    def view(self, vid, rset, req=None, template='main-template', **kwargs):
+    def view(self, vid, rset=None, req=None, template='main-template',
+             **kwargs):
         """This method tests the view `vid` on `rset` using `template`
 
         If no error occured while rendering the view, the HTML is analyzed
@@ -183,7 +184,9 @@
         """
         req = req or rset and rset.req or self.request()
         req.form['vid'] = vid
-        view = self.vreg.select_view(vid, req, rset, **kwargs)
+        kwargs['rset'] = rset
+        viewsreg = self.vreg['views']
+        view = viewsreg.select(vid, req, **kwargs)
         # set explicit test description
         if rset is not None:
             self.set_description("testing %s, mod=%s (%s)" % (
@@ -194,9 +197,11 @@
         if template is None: # raw view testing, no template
             viewfunc = view.render
         else:
-            templateview = self.vreg.select_view(template, req, rset, view=view, **kwargs)
             kwargs['view'] = view
-            viewfunc = lambda **k: self.vreg.main_template(req, template, **kwargs)
+            templateview = viewsreg.select(template, req, **kwargs)
+            viewfunc = lambda **k: viewsreg.main_template(req, template,
+                                                          **kwargs)
+        kwargs.pop('rset')
         return self._test_view(viewfunc, view, template, kwargs)
 
 
@@ -268,7 +273,8 @@
         req = rset.req
         only_once_vids = ('primary', 'secondary', 'text')
         req.data['ex'] = ValueError("whatever")
-        for vid, views in self.vreg.registry('views').items():
+        viewsvreg = self.vreg['views']
+        for vid, views in viewsvreg.items():
             if vid[0] == '_':
                 continue
             if rset.rowcount > 1 and vid in only_once_vids:
@@ -278,7 +284,7 @@
                      and not issubclass(view, NotificationView)]
             if views:
                 try:
-                    view = self.vreg.select(views, req, rset)
+                    view = viewsvreg.select_best(views, req, rset=rset)
                     if view.linkable():
                         yield view
                     else:
@@ -291,19 +297,19 @@
     def list_actions_for(self, rset):
         """returns the list of actions that can be applied on `rset`"""
         req = rset.req
-        for action in self.vreg.possible_objects('actions', req, rset):
+        for action in self.vreg['actions'].possible_objects(req, rset=rset):
             yield action
 
     def list_boxes_for(self, rset):
         """returns the list of boxes that can be applied on `rset`"""
         req = rset.req
-        for box in self.vreg.possible_objects('boxes', req, rset):
+        for box in self.vreg['boxes'].possible_objects(req, rset=rset):
             yield box
 
     def list_startup_views(self):
         """returns the list of startup views"""
         req = self.request()
-        for view in self.vreg.possible_views(req, None):
+        for view in self.vreg['views'].possible_views(req, None):
             if view.category == 'startupview':
                 yield view.id
             else:
@@ -371,9 +377,9 @@
                 rset2 = rset.limit(limit=1, offset=row)
                 yield rset2
 
-def not_selected(vreg, vobject):
+def not_selected(vreg, appobject):
     try:
-        vreg._selected[vobject.__class__] -= 1
+        vreg._selected[appobject.__class__] -= 1
     except (KeyError, AttributeError):
         pass
 
@@ -381,26 +387,29 @@
     from cubicweb.devtools.apptest import TestEnvironment
     env = testclass._env = TestEnvironment('data', configcls=testclass.configcls,
                                            requestcls=testclass.requestcls)
-    vreg = env.vreg
-    vreg._selected = {}
-    orig_select = vreg.__class__.select
-    def instr_select(self, *args, **kwargs):
-        selected = orig_select(self, *args, **kwargs)
+    for reg in env.vreg.values():
+        reg._selected = {}
         try:
-            self._selected[selected.__class__] += 1
-        except KeyError:
-            self._selected[selected.__class__] = 1
-        except AttributeError:
-            pass # occurs on vreg used to restore database
-        return selected
-    vreg.__class__.select = instr_select
+            orig_select_best = reg.__class__.__orig_select_best
+        except:
+            orig_select_best = reg.__class__.select_best
+        def instr_select_best(self, *args, **kwargs):
+            selected = orig_select_best(self, *args, **kwargs)
+            try:
+                self._selected[selected.__class__] += 1
+            except KeyError:
+                self._selected[selected.__class__] = 1
+            except AttributeError:
+                pass # occurs on reg used to restore database
+            return selected
+        reg.__class__.select_best = instr_select_best
+        reg.__class__.__orig_select_best = orig_select_best
 
 def print_untested_objects(testclass, skipregs=('hooks', 'etypes')):
-    vreg = testclass._env.vreg
-    for registry, vobjectsdict in vreg.items():
-        if registry in skipregs:
+    for regname, reg in testclass._env.vreg.iteritems():
+        if regname in skipregs:
             continue
-        for vobjects in vobjectsdict.values():
-            for vobject in vobjects:
-                if not vreg._selected.get(vobject):
-                    print 'not tested', registry, vobject
+        for appobjects in reg.itervalues():
+            for appobject in appobjects:
+                if not reg._selected.get(appobject):
+                    print 'not tested', regname, appobject
--- a/doc/book/en/.templates/layout.html	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/.templates/layout.html	Fri Aug 07 12:20:50 2009 +0200
@@ -4,7 +4,7 @@
 {%- endblock %}
 {%- set reldelim1 = reldelim1 is not defined and ' &raquo;' or reldelim1 %}
 {%- set reldelim2 = reldelim2 is not defined and ' |' or reldelim2 %}
-{%- macro relbar %}
+{%- macro relbar() %}
     <div class="related">
       <h3>Navigation</h3>
       <ul>
@@ -24,7 +24,7 @@
       </ul>
     </div>
 {%- endmacro %}
-{%- macro sidebar %}
+{%- macro sidebar() %}
       {%- if builder != 'htmlhelp' %}
       <div class="sphinxsidebar">
         <div class="sphinxsidebarwrapper">
--- a/doc/book/en/Z012-create-instance.en.txt	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/Z012-create-instance.en.txt	Fri Aug 07 12:20:50 2009 +0200
@@ -8,14 +8,14 @@
 --------------------
 
 A *CubicWeb* instance is a container that
-refers to cubes and configuration parameters for your web application.
+refers to cubes and configuration parameters for your web instance.
 Each instance is stored as a directory in ``~/etc/cubicweb.d`` which enables 
-us to run your application.
+us to run your instance.
 
 What is a cube?
 ---------------
 
-Cubes represent data and basic building bricks of your web applications :
+Cubes represent data and basic building bricks of your web instances :
 blogs, person, date, addressbook and a lot more.
 
 .. XXX They related to each other by a 'Schema' which is also the PostGres representation.
@@ -35,7 +35,7 @@
 ------------------------------------
 
 We can create an instance to view our
-application in a web browser. ::
+instance in a web browser. ::
 
   cubicweb-ctl create blog myblog
 
@@ -52,17 +52,17 @@
 sufficient. You can allways modify the parameters later by editing
 configuration files. When a user/psswd is requested to access the database
 please use the login you create at the time you configured the database
-(:ref:`ConfigurationPostgres`).
+(:ref:`ConfigurationPostgresql`).
 
 It is important to distinguish here the user used to access the database and
-the user used to login to the cubicweb application. When a *CubicWeb* application
+the user used to login to the cubicweb instance. When a *CubicWeb* instance
 starts, it uses the login/psswd for the database to get the schema and handle
 low level transaction. But, when ``cubicweb-ctl create`` asks for
-a manager login/psswd of *CubicWeb*, it refers to an application user
-to administrate your web application. 
+a manager login/psswd of *CubicWeb*, it refers to an instance user
+to administrate your web instance. 
 The configuration files are stored in *~/etc/cubicweb.d/myblog/*. 
 
-To launch the web application, you just type ::
+To launch the web instance, you just type ::
 
   cubicweb-ctl start myblog
 
--- a/doc/book/en/admin/create-instance.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/create-instance.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -6,9 +6,8 @@
 Instance creation
 -----------------
 
-Now that we created our cube, we can create an instance to view our
-application in a web browser. To do so we will use a `all-in-one`
-configuration to simplify things ::
+Now that we created a cube, we can create an instance and access it via a web
+browser. We will use a `all-in-one` configuration to simplify things ::
 
   cubicweb-ctl create -c all-in-one mycube myinstance
 
@@ -21,15 +20,15 @@
 sufficient. You can anyway modify the configuration later on by editing
 configuration files. When a user/psswd is requested to access the database
 please use the login you create at the time you configured the database
-(:ref:`ConfigurationPostgres`).
+(:ref:`ConfigurationPostgresql`).
 
 It is important to distinguish here the user used to access the database and the
-user used to login to the cubicweb application. When an instance starts, it uses
+user used to login to the cubicweb instance. When an instance starts, it uses
 the login/psswd for the database to get the schema and handle low level
 transaction. But, when :command:`cubicweb-ctl create` asks for a manager
 login/psswd of *CubicWeb*, it refers to the user you will use during the
-development to administrate your web application. It will be possible, later on,
-to use this user to create others users for your final web application.
+development to administrate your web instance. It will be possible, later on,
+to use this user to create others users for your final web instance.
 
 
 Instance administration
@@ -60,5 +59,9 @@
 upgrade
 ~~~~~~~
 
+The command is::
+
+  cubicweb-ctl upgrade myinstance
+
 XXX write me
 
--- a/doc/book/en/admin/gae.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/gae.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,5 +1,7 @@
 .. -*- coding: utf-8 -*-
 
+.. _GoogleAppEngineSource:
+
 CubicWeb in Google AppEngine
 ============================
 
@@ -26,7 +28,7 @@
 
 
 Please follow instructions on how to install *CubicWeb* framework
-(:ref:`CubicWebInstallation`).
+(:ref:`SetUpEnv`).
 
 Installation
 ------------
@@ -126,14 +128,14 @@
 'cubicweb'". They disappear after the first run of i18ninstance.
 
 .. note:: The command  myapp/bin/laxctl i18ncube needs to be executed
-   only if your application is using cubes from cubicweb-apps.
+   only if your instance is using cubes from cubicweb-apps.
    Otherwise, please skip it.
 
-You will never need to add new entries in the translation catalog. Instead we would
-recommand you to use ``self.req._("msgId")`` in your application code
-to flag new message id to add to the catalog, where ``_`` refers to
-xgettext that is used to collect new strings to translate.
-While running ``laxctl i18ncube``, new string will be added to the catalogs.
+You will never need to add new entries in the translation catalog. Instead we
+would recommand you to use ``self.req._("msgId")`` in your code to flag new
+message id to add to the catalog, where ``_`` refers to xgettext that is used to
+collect new strings to translate.  While running ``laxctl i18ncube``, new string
+will be added to the catalogs.
 
 Generating the data directory
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -152,18 +154,18 @@
 
   $ python myapp/bin/laxctl genschema
 
-Application configuration
+Instance configuration
 -------------------------
 
 Authentication
 ~~~~~~~~~~~~~~
 
-You have the option of using or not google authentication for your application.
+You have the option of using or not google authentication for your instance.
 This has to be define in ``app.conf`` and ``app.yaml``.
 
 In ``app.conf`` modify the following variable::
  
-  # does this application rely on google authentication service or not.
+  # does this instance rely on google authentication service or not.
   use-google-auth=no
 
 In ``app.yaml`` comment the `login: required` set by default in the handler::
@@ -177,7 +179,7 @@
 
 
 
-Quickstart : launch the application
+Quickstart : launch the instance
 -----------------------------------
 
 On Mac OS X platforms, drag that directory on the
@@ -189,7 +191,7 @@
 
 Once the local server is started, visit `http://MYAPP_URL/_load <http://localhost:8080/_load>`_ and sign in as administrator.
 This will initialize the repository and enable you to log in into
-the application and continue the installation.
+the instance and continue the installation.
 
 You should be redirected to a page displaying a message `content initialized`.
 
--- a/doc/book/en/admin/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -7,7 +7,7 @@
 -------------------------
 
 This part is for installation and administration of the *CubicWeb* framework and
-applications based on that framework.
+instances based on that framework.
 
 .. toctree::
    :maxdepth: 1
@@ -25,11 +25,11 @@
 RQL logs
 --------
 
-You can configure the *CubicWeb* application to keep a log
+You can configure the *CubicWeb* instance to keep a log
 of the queries executed against your database. To do so,
-edit the configuration file of your application
+edit the configuration file of your instance
 ``.../etc/cubicweb.d/myapp/all-in-one.conf`` and uncomment the
 variable ``query-log-file``::
 
-  # web application query log file
+  # web instance query log file
   query-log-file=/tmp/rql-myapp.log
--- a/doc/book/en/admin/instance-config.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/instance-config.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -6,11 +6,11 @@
 
 While creating an instance, a configuration file is generated in::
 
-    $ (CW_REGISTRY) / <instance> / <configuration name>.conf
+    $ (CW_INSTANCES_DIR) / <instance> / <configuration name>.conf
 
 For example::
 
-    /etc/cubicweb.d/JPL/all-in-one.conf
+    /etc/cubicweb.d/myblog/all-in-one.conf
 
 It is a simple text file format INI. In the following description,
 each option name is prefixed with its own section and followed by its
@@ -22,7 +22,7 @@
 :`web.auth-model` [cookie]:
     authentication mode, cookie or http
 :`web.realm`:
-    realm of the application in http authentication mode
+    realm of the instance in http authentication mode
 :`web.http-session-time` [0]:
     period of inactivity of an HTTP session before it closes automatically.
     Duration in seconds, 0 meaning no expiration (or more exactly at the
@@ -70,7 +70,7 @@
     regular expression matching sites which could be "embedded" in
     the site (controllers 'embed')
 :`web.submit-url`:
-    url where the bugs encountered in the application can be mailed to
+    url where the bugs encountered in the instance can be mailed to
 
 
 RQL server configuration
@@ -92,7 +92,7 @@
 -----------------------------------
 Web server side:
 
-:`pyro-client.pyro-application-id`:
+:`pyro-client.pyro-instance-id`:
     pyro identifier of RQL server (e.g. the instance name)
 
 RQL server side:
@@ -107,7 +107,7 @@
     hostname hosting pyro server name. If no value is
     specified, it is located by a request from broadcast
 :`pyro-name-server.pyro-ns-group` [cubicweb]:
-    pyro group in which to save the application
+    pyro group in which to save the instance
 
 
 Configuring e-mail
@@ -125,9 +125,9 @@
 :`email.smtp-port [25]`:
     SMTP server port to use for outgoing mail
 :`email.sender-name`:
-    name to use for outgoing mail of the application
+    name to use for outgoing mail of the instance
 :`email.sender-addr`:
-    address for outgoing mail of the application
+    address for outgoing mail of the instance
 :`email.default dest-addrs`:
     destination addresses by default, if used by the configuration of the
     dissemination of the model (separated by commas)
--- a/doc/book/en/admin/multisources.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/multisources.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,6 @@
-Integrating some data from another instance
-===========================================
+Multiple sources of data
+========================
 
-XXX feed me
\ No newline at end of file
+Data sources include SQL, LDAP, RQL, mercurial and subversion.
+
+XXX feed me
--- a/doc/book/en/admin/setup.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/setup.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -39,7 +39,7 @@
   apt-get install cubicweb cubicweb-dev
 
 `cubicweb` installs the framework itself, allowing you to create
-new applications.
+new instances.
 
 `cubicweb-dev` installs the development environment allowing you to
 develop new cubes.
@@ -69,22 +69,29 @@
   hg fclone http://www.logilab.org/hg/forests/cubicweb
 
 See :ref:`MercurialPresentation` for more details about Mercurial.
+When cloning a repository, you might be set in a development branch
+(the 'default' branch). You should check that the branches of the
+repositories are set to 'stable' (using `hg up stable` for each one)
+if you do not intend to develop the framework itself.
 
 In both cases, make sure you have installed the dependencies (see appendixes for
 the list).
 
-Postgres installation
-`````````````````````
+PostgreSQL installation
+```````````````````````
 
-Please refer to the `Postgresql project online documentation`_.
+Please refer to the `PostgreSQL project online documentation`_.
 
-.. _`Postgresql project online documentation`: http://www.postgresql.org/
+.. _`PostgreSQL project online documentation`: http://www.postgresql.org/
 
-You need to install the three following packages: `postgres-8.3`,
-`postgres-contrib-8.3` and `postgresql-plpython-8.3`.
+You need to install the three following packages: `postgresql-8.3`,
+`postgresql-contrib-8.3` and `postgresql-plpython-8.3`.
 
 
-Then you can install:
+Other dependencies
+``````````````````
+
+You can also install:
 
 * `pyro` if you wish the repository to be accessible through Pyro
   or if the client and the server are not running on the same machine
@@ -105,19 +112,20 @@
 Add the following lines to either `.bashrc` or `.bash_profile` to configure
 your development environment ::
 
-  export PYTHONPATH=/full/path/to/cubicweb-forest
+    export PYTHONPATH=/full/path/to/cubicweb-forest
 
-If you installed the debian packages, no configuration is required.
-Your new cubes will be placed in `/usr/share/cubicweb/cubes` and
-your applications will be placed in `/etc/cubicweb.d`.
+If you installed *CubicWeb* with packages, no configuration is required and your
+new cubes will be placed in `/usr/share/cubicweb/cubes` and your instances
+will be placed in `/etc/cubicweb.d`.
 
-To use others directories then you will have to configure the
-following environment variables as follows::
+You may run a system-wide install of *CubicWeb* in "user mode" and use it for
+development by setting the following environment variable::
 
+    export CW_MODE=user
     export CW_CUBES_PATH=~/lib/cubes
-    export CW_REGISTRY=~/etc/cubicweb.d/
-    export CW_INSTANCE_DATA=$CW_REGISTRY
-    export CW_RUNTIME=/tmp
+    export CW_INSTANCES_DIR=~/etc/cubicweb.d/
+    export CW_INSTANCES_DATA_DIR=$CW_INSTANCES_DIR
+    export CW_RUNTIME_DIR=/tmp
 
 .. note::
     The values given above are our suggestions but of course
@@ -129,22 +137,22 @@
 
 
 
-.. _ConfigurationPostgres:
+.. _ConfigurationPostgresql:
 
-Postgres configuration
-``````````````````````
+PostgreSQL configuration
+````````````````````````
 
 .. note::
-    If you already have an existing cluster and postgres server
+    If you already have an existing cluster and PostgreSQL server
     running, you do not need to execute the initilization step
-    of your Postgres database.
+    of your PostgreSQL database.
 
-* First, initialize the database Postgres with the command ``initdb``.
+* First, initialize the database PostgreSQL with the command ``initdb``.
   ::
 
     $ initdb -D /path/to/pgsql
 
-  Once initialized, start the database server Postgres
+  Once initialized, start the database server PostgreSQL
   with the command::
 
     $ postgres -D /path/to/psql
@@ -176,7 +184,7 @@
 
   This login/password will be requested when you will create an
   instance with `cubicweb-ctl create` to initialize the database of
-  your application.
+  your instance.
 
 .. note::
     The authentication method can be configured in ``pg_hba.conf``.
@@ -194,13 +202,17 @@
 
 MySql configuration
 ```````````````````
-Yout must add the following lines in /etc/mysql/my.cnf file::
+Yout must add the following lines in ``/etc/mysql/my.cnf`` file::
 
     transaction-isolation = READ-COMMITTED
     default-storage-engine=INNODB
     default-character-set=utf8
     max_allowed_packet = 128M
 
+.. note::
+    It is unclear whether mysql supports indexed string of arbitrary lenght or
+    not.
+
 Pyro configuration
 ------------------
 
--- a/doc/book/en/admin/site-config.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/admin/site-config.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,7 @@
 
 .. image:: ../images/lax-book.03-site-config-panel.en.png
 
-This panel allows you to configure the appearance of your application site.
+This panel allows you to configure the appearance of your instance site.
 Six menus are available and we will go through each of them to explain how
 to use them.
 
@@ -65,9 +65,9 @@
 
 Boxes
 ~~~~~
-The application has already a pre-defined set of boxes you can use right away.
+The instance has already a pre-defined set of boxes you can use right away.
 This configuration section allows you to place those boxes where you want in the
-application interface to customize it.
+instance interface to customize it.
 
 The available boxes are :
 
@@ -82,7 +82,7 @@
 * search box : search box
 
 * startup views box : box listing the configuration options available for
-  the application site, such as `Preferences` and `Site Configuration`
+  the instance site, such as `Preferences` and `Site Configuration`
 
 Components
 ~~~~~~~~~~
--- a/doc/book/en/annexes/cookbook.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/cookbook.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -9,9 +9,12 @@
 
 * How to import LDAP users in *CubicWeb*?
 
+  [XXX distribute this script with cubicweb instead]
+
   Here is a very useful script which enables you to import LDAP users
-  into your *CubicWeb* application by running the following: ::
+  into your *CubicWeb* instance by running the following:
 
+.. sourcecode:: python
 
     import os
     import pwd
@@ -66,8 +69,10 @@
 * How to load data from a script?
 
   The following script aims at loading data within a script assuming pyro-nsd is
-  running and your application is configured with ``pyro-server=yes``, otherwise
-  you would not be able to use dbapi. ::
+  running and your instance is configured with ``pyro-server=yes``, otherwise
+  you would not be able to use dbapi.
+
+.. sourcecode:: python
 
     from cubicweb import dbapi
 
--- a/doc/book/en/annexes/cubicweb-ctl.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/cubicweb-ctl.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -26,8 +26,8 @@
 ------------------------
 
 * ``newcube``, create a new cube on the file system based on the name
-  given in the parameters. This command create a cube from an application
-  skeleton that includes default files required for debian packaging.
+  given in the parameters. This command create a cube from a skeleton
+  that includes default files required for debian packaging.
 
 
 Command to create an instance
@@ -69,7 +69,7 @@
 * ``db-check``, checks data integrity of an instance. If the automatic correction
   is activated, it is recommanded to create a dump before this operation.
 * ``schema-sync``, synchronizes the persistent schema of an instance with
-  the application schema. It is recommanded to create a dump before this operation.
+  the instance schema. It is recommanded to create a dump before this operation.
 
 Commands to maintain i18n catalogs
 ----------------------------------
--- a/doc/book/en/annexes/depends.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/depends.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -44,5 +44,8 @@
 * indexer - http://www.logilab.org/project/indexer -
   http://pypi.python.org/pypi/indexer - included in the forest
 
+* fyzz - http://www.logilab.org/project/fyzz - http://pypi.python.org/pypi/fyzz
+  - included in the forest
+
 Any help with the packaging of CubicWeb for more than Debian/Ubuntu (including
 eggs, buildouts, etc) will be greatly appreciated.
--- a/doc/book/en/annexes/faq.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/faq.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -14,80 +14,79 @@
 Why does not CubicWeb have a template language ?
 ------------------------------------------------
 
-  There are enough template languages out there. You can use your
-  preferred template language if you want. [explain how to use a
-  template language]
+There are enough template languages out there. You can use your
+preferred template language if you want. [explain how to use a
+template language]
 
-  *CubicWeb* does not define its own templating language as this was
-  not our goal. Based on our experience, we realized that
-  we could gain productivity by letting designers use design tools
-  and developpers develop without the use of the templating language
-  as an intermediary that could not be anyway efficient for both parties.
-  Python is the templating language that we use in *CubicWeb*, but again,
-  it does not prevent you from using a templating language.
+*CubicWeb* does not define its own templating language as this was
+not our goal. Based on our experience, we realized that
+we could gain productivity by letting designers use design tools
+and developpers develop without the use of the templating language
+as an intermediary that could not be anyway efficient for both parties.
+Python is the templating language that we use in *CubicWeb*, but again,
+it does not prevent you from using a templating language.
 
-  The reason template languages are not used in this book is that
-  experience has proved us that using pure python was less cumbersome.
+The reason template languages are not used in this book is that
+experience has proved us that using pure python was less cumbersome.
 
 Why do you think using pure python is better than using a template language ?
 -----------------------------------------------------------------------------
 
-  Python is an Object Oriented Programming language and as such it
-  already provides a consistent and strong architecture and syntax
-  a templating language would not reach.
+Python is an Object Oriented Programming language and as such it
+already provides a consistent and strong architecture and syntax
+a templating language would not reach.
 
-  When doing development, you need a real language and template
-  languages are not real languages.
+When doing development, you need a real language and template
+languages are not real languages.
 
-  Using Python enables developing applications for which code is
-  easier to maintain with real functions/classes/contexts
-  without the need of learning a new dialect. By using Python,
-  we use standard OOP techniques and this is a key factor in a
-  robust application.
+Using Python instead of a template langage for describing the user interface
+makes it to maintain with real functions/classes/contexts without the need of
+learning a new dialect. By using Python, we use standard OOP techniques and
+this is a key factor in a robust application.
 
 Why do you use the LGPL license to prevent me from doing X ?
 ------------------------------------------------------------
 
-  LGPL means that *if* you redistribute your application, you need to
-  redistribute the changes you made to CubicWeb under the LGPL licence.
+LGPL means that *if* you redistribute your application, you need to
+redistribute the changes you made to CubicWeb under the LGPL licence.
 
-  Publishing a web site has nothing to do with redistributing
-  source code. A fair amount of companies use modified LGPL code
-  for internal use. And someone could publish a *CubicWeb* component
-  under a BSD licence for others to plug into a LGPL framework without
-  any problem. The only thing we are trying to prevent here is someone
-  taking the framework and packaging it as closed source to his own
-  clients.
+Publishing a web site has nothing to do with redistributing
+source code. A fair amount of companies use modified LGPL code
+for internal use. And someone could publish a *CubicWeb* component
+under a BSD licence for others to plug into a LGPL framework without
+any problem. The only thing we are trying to prevent here is someone
+taking the framework and packaging it as closed source to his own
+clients.
 
 
 CubicWeb looks pretty recent. Is it stable ?
 --------------------------------------------
 
-  It is constantly evolving, piece by piece.  The framework has evolved since
-  2001 and data has been migrated from one schema to the other ever since. There
-  is a well-defined way to handle data and schema migration.
+It is constantly evolving, piece by piece.  The framework has evolved since
+2001 and data has been migrated from one schema to the other ever since. There
+is a well-defined way to handle data and schema migration.
 
 Why is the RQL query language looking similar to X ?
 -----------------------------------------------------
 
-  It may remind you of SQL but it is higher level than SQL, more like
-  SPARQL. Except that SPARQL did not exist when we started the project.
-  Having SPARQL as a query language has been in our backlog for years.
+It may remind you of SQL but it is higher level than SQL, more like
+SPARQL. Except that SPARQL did not exist when we started the project.
+With version 3.4, CubicWeb has support for SPARQL.
 
-  That RQL language is what is going to make a difference with django-
-  like frameworks for several reasons.
+That RQL language is what is going to make a difference with django-
+like frameworks for several reasons.
 
-  1. accessing data is *much* easier with it. One can write complex
-     queries with RQL that would be tedious to define and hard to maintain
-     using an object/filter suite of method calls.
+1. accessing data is *much* easier with it. One can write complex
+   queries with RQL that would be tedious to define and hard to maintain
+   using an object/filter suite of method calls.
 
-  2. it offers an abstraction layer allowing your applications to run
-     on multiple back-ends. That means not only various SQL backends
-     (postgresql, sqlite, mysql), but also multiple databases at the
-     same time, and also non-SQL data stores like LDAP directories and
-     subversion/mercurial repositories (see the `vcsfile`
-     component). Google App Engine is yet another supported target for
-     RQL.
+2. it offers an abstraction layer allowing your applications to run
+   on multiple back-ends. That means not only various SQL backends
+   (postgresql, sqlite, mysql), but also multiple databases at the
+   same time, and also non-SQL data stores like LDAP directories and
+   subversion/mercurial repositories (see the `vcsfile`
+   component). Google App Engine is yet another supported target for
+   RQL.
 
 [copy answer from forum, explain why similar to sparql and why better
   than django and SQL]
@@ -101,7 +100,9 @@
 How is security implemented ?
 ------------------------------
 
-  This is an example of how it works in our framework::
+This is an example of how it works in our framework:
+
+.. sourcecode:: python
 
     class Version(EntityType):
         """a version is defining the content of a particular project's
@@ -111,16 +112,17 @@
                        'update': ('managers', 'logilab', 'owners',),
                        'delete': ('managers', ),
                        'add': ('managers', 'logilab',
-                           ERQLExpression('X version_of PROJ, U in_group G, '
-                                          'PROJ require_permission P, '
-                                          'P name "add_version", P require_group G'),)}
+                               ERQLExpression('X version_of PROJ, U in_group G, '
+                                              'PROJ require_permission P, '
+                                              'P name "add_version", P require_group G'),)}
 
-  The above means that permission to read a Version is granted to any
-  user that is part of one of the groups 'managers', 'users', 'guests'.
-  The 'add' permission is granted to users in group 'managers' or
-  'logilab' and to users in group G, if G is linked by a permission
-  entity named "add_version" to the version's project.
-  ::
+The above means that permission to read a Version is granted to any
+user that is part of one of the groups 'managers', 'users', 'guests'.
+The 'add' permission is granted to users in group 'managers' or
+'logilab' and to users in group G, if G is linked by a permission
+entity named "add_version" to the version's project.
+
+.. sourcecode:: python
 
     class version_of(RelationType):
         """link a version to its project. A version is necessarily linked
@@ -129,20 +131,20 @@
         permissions = {'read': ('managers', 'users', 'guests',),
                        'delete': ('managers', ),
                        'add': ('managers', 'logilab',
-                            RRQLExpression('O require_permission P, P name "add_version",
-                            'U in_group G, P require_group G'),) }
+                               RRQLExpression('O require_permission P, P name "add_version", '
+                               'U in_group G, P require_group G'),) }
 
-  You can find additional information in the section :ref:`security`.
+You can find additional information in the section :ref:`security`.
 
-  [XXX what does the second example means in addition to the first one?]
+[XXX what does the second example means in addition to the first one?]
 
 
 What is `Error while publishing rest text ...` ?
 ------------------------------------------------
 
-  While modifying the description of an entity, you get an error message in
-  the application `Error while publishing ...` for Rest text and plain text.
-  The server returns a traceback like as follows ::
+While modifying the description of an entity, you get an error message in
+the instance `Error while publishing ...` for Rest text and plain text.
+The server returns a traceback like as follows ::
 
       2008-10-06 15:05:08 - (cubicweb.rest) ERROR: error while publishing ReST text
       Traceback (most recent call last):
@@ -151,73 +153,69 @@
       file = __builtin__.open(filename, mode, buffering)
       TypeError: __init__() takes at most 3 arguments (4 given)
 
-
-  This can be fixed by applying the patch described in :
-  http://code.google.com/p/googleappengine/issues/detail?id=48
+This can be fixed by applying the patch described in :
+http://code.google.com/p/googleappengine/issues/detail?id=48
 
 What are hooks used for ?
 -------------------------
 
-  Hooks are executed around (actually before or after) events.  The
-  most common events are data creation, update and deletion.  They
-  permit additional constraint checking (those not expressible at the
-  schema level), pre and post computations depending on data
-  movements.
+Hooks are executed around (actually before or after) events.  The
+most common events are data creation, update and deletion.  They
+permit additional constraint checking (those not expressible at the
+schema level), pre and post computations depending on data
+movements.
 
-  As such, they are a vital part of the framework.
+As such, they are a vital part of the framework.
 
-  Other kinds of hooks, called Operations, are available
-  for execution just before commit.
+Other kinds of hooks, called Operations, are available
+for execution just before commit.
 
 When should you define an HTML template rather than define a graphical component ?
 ----------------------------------------------------------------------------------
 
-  An HTML template cannot contain code, hence it is only about static
-  content.  A component is made of code and operations that apply on a
-  well defined context (request, result set). It enables much more
-  dynamic views.
+An HTML template cannot contain code, hence it is only about static
+content.  A component is made of code and operations that apply on a
+well defined context (request, result set). It enables much more
+dynamic views.
 
 What is the difference between `AppRsetObject` and `AppObject` ?
 ----------------------------------------------------------------
 
-  `AppRsetObject` instances are selected on a request and a result
-  set. `AppObject` instances are directly selected by id.
+`AppRsetObject` instances are selected on a request and a result
+set. `AppObject` instances are directly selected by id.
 
 How to update a database after a schema modification ?
 ------------------------------------------------------
 
-  It depends on what has been modified in the schema.
-
-  * Update of an attribute permissions and properties:
-    ``synchronize_eschema('MyEntity')``.
+It depends on what has been modified in the schema.
 
-  * Update of a relation permissions and properties:
-    ``synchronize_rschema('MyRelation')``.
+* Update the permissions and properties of an entity or a relation:
+  ``sync_schema_props_perms('MyEntityOrRelation')``.
 
-  * Add an attribute: ``add_attribute('MyEntityType', 'myattr')``.
+* Add an attribute: ``add_attribute('MyEntityType', 'myattr')``.
 
-  * Add a relation: ``add_relation_definition('SubjRelation', 'MyRelation', 'ObjRelation')``.
+* Add a relation: ``add_relation_definition('SubjRelation', 'MyRelation', 'ObjRelation')``.
 
 
 How to create an anonymous user ?
 ---------------------------------
 
-  This allows to bypass authentication for your site. In the
-  ``all-in-one.conf`` file of your instance, define the anonymous user
-  as follows ::
+This allows to bypass authentication for your site. In the
+``all-in-one.conf`` file of your instance, define the anonymous user
+as follows ::
 
-    # login of the CubicWeb user account to use for anonymous user (if you want to
-    # allow anonymous)
-    anonymous-user=anon
+  # login of the CubicWeb user account to use for anonymous user (if you want to
+  # allow anonymous)
+  anonymous-user=anon
 
-    # password of the CubicWeb user account matching login
-    anonymous-password=anon
+  # password of the CubicWeb user account matching login
+  anonymous-password=anon
 
-  You also must ensure that this `anon` user is a registered user of
-  the DB backend. If not, you can create through the administation
-  interface of your instance by adding a user with the role `guests`.
-  This could be the admin account (for development
-  purposes, of course).
+You also must ensure that this `anon` user is a registered user of
+the DB backend. If not, you can create through the administation
+interface of your instance by adding a user with the role `guests`.
+This could be the admin account (for development
+purposes, of course).
 
 .. note::
     While creating a new instance, you can decide to allow access
@@ -225,58 +223,60 @@
     decribed above.
 
 
-How to change the application logo ?
+How to change the instance logo ?
 ------------------------------------
 
-  There are two ways of changing the logo.
+There are two ways of changing the logo.
 
-  1. The easiest way to use a different logo is to replace the existing
-     ``logo.png`` in ``myapp/data`` by your prefered icon and refresh.
-     By default all application will look for a ``logo.png`` to be
-     rendered in the logo section.
+1. The easiest way to use a different logo is to replace the existing
+   ``logo.png`` in ``myapp/data`` by your prefered icon and refresh.
+   By default all instance will look for a ``logo.png`` to be
+   rendered in the logo section.
 
-     .. image:: ../images/lax-book.06-main-template-logo.en.png
+   .. image:: ../images/lax-book.06-main-template-logo.en.png
 
-  2. In your cube directory, you can specify which file to use for the logo.
-     This is configurable in ``mycube/data/external_resources``: ::
+2. In your cube directory, you can specify which file to use for the logo.
+   This is configurable in ``mycube/data/external_resources``: ::
 
-       LOGO = DATADIR/path/to/mylogo.gif
+     LOGO = DATADIR/path/to/mylogo.gif
 
-     where DATADIR is ``mycube/data``.
+   where DATADIR is ``mycube/data``.
 
 
 How to configure a LDAP source ?
 --------------------------------
 
-  Your instance's sources are defined in ``/etc/cubicweb.d/myapp/sources``.
-  Configuring an LDAP source is about declaring that source in your
-  instance configuration file such as: ::
+Your instance's sources are defined in ``/etc/cubicweb.d/myapp/sources``.
+Configuring an LDAP source is about declaring that source in your
+instance configuration file such as: ::
 
-    [ldapuser]
-    adapter=ldapuser
-    # ldap host
-    host=myhost
-    # base DN to lookup for usres
-    user-base-dn=ou=People,dc=mydomain,dc=fr
-    # user search scope
-    user-scope=ONELEVEL
-    # classes of user
-    user-classes=top,posixAccount
-    # attribute used as login on authentication
-    user-login-attr=uid
-    # name of a group in which ldap users will be by default
-    user-default-group=users
-    # map from ldap user attributes to cubicweb attributes
-    user-attrs-map=gecos:email,uid:login
+  [ldapuser]
+  adapter=ldapuser
+  # ldap host
+  host=myhost
+  # base DN to lookup for usres
+  user-base-dn=ou=People,dc=mydomain,dc=fr
+  # user search scope
+  user-scope=ONELEVEL
+  # classes of user
+  user-classes=top,posixAccount
+  # attribute used as login on authentication
+  user-login-attr=uid
+  # name of a group in which ldap users will be by default
+  user-default-group=users
+  # map from ldap user attributes to cubicweb attributes
+  user-attrs-map=gecos:email,uid:login
 
-  Any change applied to configuration file requires to restart your
-  application.
+Any change applied to configuration file requires to restart your
+instance.
 
 I get NoSelectableObject exceptions, how do I debug selectors ?
 ---------------------------------------------------------------
 
-  You just need to put the appropriate context manager around view/component
-  selection (one standard place in in vreg.py) : ::
+You just need to put the appropriate context manager around view/component
+selection (one standard place in in vreg.py):
+
+.. sourcecode:: python
 
     def possible_objects(self, registry, *args, **kwargs):
         """return an iterator on possible objects in a registry for this result set
@@ -291,40 +291,43 @@
                 except NoSelectableObject:
                     continue
 
-  Don't forget the 'from __future__ improt with_statement' at the
-  module top-level.
+Don't forget the 'from __future__ import with_statement' at the module
+top-level.
 
-  This will yield additional WARNINGs, like this:
-  ::
+This will yield additional WARNINGs, like this::
 
     2009-01-09 16:43:52 - (cubicweb.selectors) WARNING: selector one_line_rset returned 0 for <class 'cubicweb.web.views.basecomponents.WFHistoryVComponent'>
 
 How to format an entity date attribute ?
 ----------------------------------------
 
-  If your schema has an attribute of type Date or Datetime, you might
-  want to format it. First, you should define your preferred format using
-  the site configuration panel ``http://appurl/view?vid=systempropertiesform``
-  and then set ``ui.date`` and/or ``ui.datetime``.
-  Then in the view code, use::
+If your schema has an attribute of type Date or Datetime, you might
+want to format it. First, you should define your preferred format using
+the site configuration panel ``http://appurl/view?vid=systempropertiesform``
+and then set ``ui.date`` and/or ``ui.datetime``.
+Then in the view code, use:
+
+.. sourcecode:: python
 
     self.format_date(entity.date_attribute)
 
 Can PostgreSQL and CubicWeb authentication work with kerberos ?
 ----------------------------------------------------------------
 
-  If you have PostgreSQL set up to accept kerberos authentication, you can set
-  the db-host, db-name and db-user parameters in the `sources` configuration
-  file while leaving the password blank. It should be enough for your
-  application to connect to postgresql with a kerberos ticket.
+If you have PostgreSQL set up to accept kerberos authentication, you can set
+the db-host, db-name and db-user parameters in the `sources` configuration
+file while leaving the password blank. It should be enough for your
+instance to connect to postgresql with a kerberos ticket.
 
 
 How to load data from a script ?
 --------------------------------
 
-  The following script aims at loading data within a script assuming pyro-nsd is
-  running and your application is configured with ``pyro-server=yes``, otherwise
-  you would not be able to use dbapi. ::
+The following script aims at loading data within a script assuming pyro-nsd is
+running and your instance is configured with ``pyro-server=yes``, otherwise
+you would not be able to use dbapi.
+
+.. sourcecode:: python
 
     from cubicweb import dbapi
 
@@ -337,24 +340,30 @@
 What is the CubicWeb datatype corresponding to GAE datastore's UserProperty ?
 -----------------------------------------------------------------------------
 
-  If you take a look at your application schema and
-  click on "display detailed view of metadata" you will see that there
-  is a Euser entity in there. That's the one that is modeling users. The
-  thing that corresponds to a UserProperty is a relationship between
-  your entity and the Euser entity. As in ::
+If you take a look at your instance schema and
+click on "display detailed view of metadata" you will see that there
+is a Euser entity in there. That's the one that is modeling users. The
+thing that corresponds to a UserProperty is a relationship between
+your entity and the Euser entity. As in:
+
+.. sourcecode:: python
 
     class TodoItem(EntityType):
        text = String()
        todo_by = SubjectRelation('Euser')
 
-  [XXX check that cw handle users better by
-  mapping Google Accounts to local Euser entities automatically]
+[XXX check that cw handle users better by mapping Google Accounts to local Euser
+entities automatically]
 
 
 How to reset the password for user joe ?
 ----------------------------------------
 
-  You need to generate a new encrypted password::
+If you want to reset the admin password for ``myinstance``, do::
+
+    $ cubicweb-ctl reset-admin-pwd myinstance
+
+You need to generate a new encrypted password::
 
     $ python
     >>> from cubicweb.server.utils import crypt_password
@@ -362,8 +371,17 @@
     'qHO8282QN5Utg'
     >>>
 
-  and paste it in the database::
+and paste it in the database::
 
     $ psql mydb
     mydb=> update cw_cwuser set cw_upassword='qHO8282QN5Utg' where cw_login='joe';
     UPDATE 1
+
+I've just created a user in a group and it doesn't work !
+---------------------------------------------------------
+
+You are probably getting errors such as ::
+
+  remove {'PR': 'Project', 'C': 'CWUser'} from solutions since your_user has no read access to cost
+
+This is because you have to put your user in the "users" group. The user has to be in both groups.
--- a/doc/book/en/annexes/rql/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/rql/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -8,5 +8,4 @@
 
    intro
    language
-   dbapi
    implementation
--- a/doc/book/en/annexes/rql/intro.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/annexes/rql/intro.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -5,41 +5,38 @@
 Goals of RQL
 ~~~~~~~~~~~~
 
-The goal is to have a language emphasizing the way of browsing
-relations. As such, attributes will be regarded as cases of
-special relations (in terms of implementation, the language
-user should see virtually no difference between an attribute and a
+The goal is to have a language emphasizing the way of browsing relations. As
+such, attributes will be regarded as cases of special relations (in terms of
+implementation, the user should see no difference between an attribute and a
 relation).
 
-RQL is inspired by SQL but is the highest level. A knowledge of the
-*CubicWeb* schema defining the application is necessary.
-
 Comparison with existing languages
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 SQL
 ```
-RQL builds on the features of SQL but is at a higher level
-(the current implementation of RQL generates SQL). For that it is limited
-to the way of browsing relations and introduces variables.
-The user does not need to know the model underlying SQL, but the *CubicWeb*
-schema defining the application.
+
+RQL may remind of SQL but works at a higher abstraction level (the *CubicWeb*
+framework generates SQL from RQL to fetch data from relation databases). RQL is
+focused on browsing relations. The user needs only to know about the *CubicWeb*
+data model he is querying, but not about the underlying SQL model.
+
+Sparql
+``````
+
+The query language most similar to RQL is SPARQL_, defined by the W3C to serve
+for the semantic web.
 
 Versa
 `````
-We should look in more detail, but here are already some ideas for
-the moment ... Versa_ is the language most similar to what we wanted
-to do, but the model underlying data being RDF, there is some
-number of things such as namespaces or handling of the RDF types which
-does not interest us. On the functionality level, Versa_ is very comprehensive
-including through many functions of conversion and basic types manipulation,
-which may need to be guided at one time or another.
-Finally, the syntax is a little esoteric.
 
-Sparql
-``````
-The query language most similar to RQL is SPARQL_, defined by the W3C to serve
-for the semantic web.
+We should look in more detail, but here are already some ideas for the moment
+... Versa_ is the language most similar to what we wanted to do, but the model
+underlying data being RDF, there is some number of things such as namespaces or
+handling of the RDF types which does not interest us. On the functionality
+level, Versa_ is very comprehensive including through many functions of
+conversion and basic types manipulation, which may need to be guided at one time
+or another.  Finally, the syntax is a little esoteric.
 
 
 The different types of queries
--- a/doc/book/en/conf.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/conf.py	Fri Aug 07 12:20:50 2009 +0200
@@ -51,7 +51,7 @@
 # The short X.Y version.
 version = '0.54'
 # The full version, including alpha/beta/rc tags.
-release = '3.2'
+release = '3.4'
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
--- a/doc/book/en/development/cubes/available-cubes.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/cubes/available-cubes.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -2,7 +2,7 @@
 Available cubes
 ---------------
 
-An application is based on several basic cubes. In the set of available
+An instance is based on several basic cubes. In the set of available
 basic cubes we can find for example :
 
 Base entity types
--- a/doc/book/en/development/cubes/layout.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/cubes/layout.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -80,7 +80,7 @@
 * ``entities`` contains the entities definition (server side and web interface)
 * ``sobjects`` contains hooks and/or views notifications (server side only)
 * ``views`` contains the web interface components (web interface only)
-* ``test`` contains tests related to the application (not installed)
+* ``test`` contains tests related to the cube (not installed)
 * ``i18n`` contains message catalogs for supported languages (server side and
   web interface)
 * ``data`` contains data files for static content (images, css, javascripts)
--- a/doc/book/en/development/datamodel/baseschema.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/datamodel/baseschema.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,9 +1,9 @@
 
-Pre-defined schemas in the library
-----------------------------------
+Pre-defined entities in the library
+-----------------------------------
 
 The library defines a set of entity schemas that are required by the system
-or commonly used in *CubicWeb* applications.
+or commonly used in *CubicWeb* instances.
 
 
 Entity types used to store the schema
@@ -18,7 +18,7 @@
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * `CWUser`, system users
 * `CWGroup`, users groups
-* `CWPermission`, used to configure the security of the application
+* `CWPermission`, used to configure the security of the instance
 
 Entity types used to manage workflows
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -28,11 +28,11 @@
 
 Other entity types
 ~~~~~~~~~~~~~~~~~~
-* `CWCache`
-* `CWProperty`, used to configure the application
+* `CWCache`, cache entities used to improve performances
+* `CWProperty`, used to configure the instance
 
 * `EmailAddress`, email address, used by the system to send notifications
   to the users and also used by others optionnals schemas
 
 * `Bookmark`, an entity type used to allow a user to customize his links within
-  the application
+  the instance
--- a/doc/book/en/development/datamodel/define-workflows.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/datamodel/define-workflows.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -2,8 +2,8 @@
 
 .. _Workflow:
 
-An Example: Workflow definition
-===============================
+Define a Workflow
+=================
 
 General
 -------
@@ -20,7 +20,7 @@
 -----------------
 
 We want to create a workflow to control the quality of the BlogEntry
-submitted on your application. When a BlogEntry is created by a user
+submitted on your instance. When a BlogEntry is created by a user
 its state should be `submitted`. To be visible to all, it has to
 be in the state `published`. To move it from `submitted` to `published`,
 we need a transition that we can call `approve_blogentry`.
--- a/doc/book/en/development/datamodel/definition.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/datamodel/definition.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -3,7 +3,7 @@
 Yams *schema*
 -------------
 
-The **schema** is the core piece of a *CubicWeb* application as it defines
+The **schema** is the core piece of a *CubicWeb* instance as it defines
 the handled data model. It is based on entity types that are either already
 defined in the *CubicWeb* standard library; or more specific types, that
 *CubicWeb* expects to find in one or more Python files under the directory
@@ -24,9 +24,8 @@
 They are implicitely imported (as well as the special the function "_"
 for translation :ref:`internationalization`).
 
-The instance schema of an application is defined on all appobjects by a .schema
-class attribute set on registration.  It's an instance of
-:class:`yams.schema.Schema`.
+The instance schema is defined on all appobjects by a .schema class attribute set
+on registration.  It's an instance of :class:`yams.schema.Schema`.
 
 Entity type
 ~~~~~~~~~~~
--- a/doc/book/en/development/datamodel/inheritance.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/datamodel/inheritance.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -2,4 +2,7 @@
 Inheritance
 -----------
 
+When describing a data model, entities can inherit from other entities as is
+common in object-oriented programming.
+
 XXX WRITME
--- a/doc/book/en/development/devcore/appobject.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devcore/appobject.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -19,9 +19,9 @@
 At the recording, the following attributes are dynamically added to
 the *subclasses*:
 
-* `vreg`, the `vregistry` of the application
-* `schema`, the application schema
-* `config`, the application configuration
+* `vreg`, the `vregistry` of the instance
+* `schema`, the instance schema
+* `config`, the instance configuration
 
 We also find on instances, the following attributes:
 
@@ -36,7 +36,7 @@
     can be specified through the special parameter `method` (the connection
     is theoretically done automatically :).
 
-  * `datadir_url()`, returns the directory of the application data
+  * `datadir_url()`, returns the directory of the instance data
     (contains static files such as images, css, js...)
 
   * `base_url()`, shortcut to `req.base_url()`
@@ -57,9 +57,9 @@
 
 :Data formatting:
   * `format_date(date, date_format=None, time=False)` returns a string for a
-    mx date time according to application's configuration
+    mx date time according to instance's configuration
   * `format_time(time)` returns a string for a mx date time according to
-    application's configuration
+    instance's configuration
 
 :And more...:
 
--- a/doc/book/en/development/devcore/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devcore/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,6 @@
    :maxdepth: 1
 
    vreg.rst
-   selection.rst
    appobject.rst
    selectors.rst
    dbapi.rst
--- a/doc/book/en/development/devcore/vreg.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devcore/vreg.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -27,7 +27,7 @@
 
 Examples:
 
-.. code-block:: python
+.. sourcecode:: python
 
    # web/views/basecomponents.py
    def registration_callback(vreg):
@@ -45,7 +45,7 @@
 API d'enregistrement des objets
 ```````````````````````````````
 
-.. code-block:: python
+.. sourcecode:: python
 
    register(obj, registryname=None, oid=None, clear=False)
 
--- a/doc/book/en/development/devrepo/sessions.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devrepo/sessions.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -5,21 +5,22 @@
 
 There are three kinds of sessions.
 
-* user sessions are the most common: they are related to users and
+* `user sessions` are the most common: they are related to users and
   carry security checks coming with user credentials
 
-* super sessions are children of ordinary user sessions and allow to
+* `super sessions` are children of ordinary user sessions and allow to
   bypass security checks (they are created by calling unsafe_execute
   on a user session); this is often convenient in hooks which may
   touch data that is not directly updatable by users
 
-* internal sessions have all the powers; they are also used in only a
+* `internal sessions` have all the powers; they are also used in only a
   few situations where you don't already have an adequate session at
   hand, like: user authentication, data synchronisation in
   multi-source contexts
 
-Do not confuse the session type with their connection mode, for
-instance : 'in memory' or 'pyro'.
+.. note::
+  Do not confuse the session type with their connection mode, for
+  instance : 'in memory' or 'pyro'.
 
 [WRITE ME]
 
--- a/doc/book/en/development/devweb/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devweb/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,7 +1,7 @@
 Web development
 ===============
 
-In this chapter, we will core api for web development in the CubicWeb framework.
+In this chapter, we will describe the core api for web development in the *CubicWeb* framework.
 
 .. toctree::
    :maxdepth: 1
--- a/doc/book/en/development/devweb/internationalization.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devweb/internationalization.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,12 +1,12 @@
 .. -*- coding: utf-8 -*-
 
-.. _internationalisation:
+.. _internationalization:
 
 
-Internationalisation
+Internationalization
 ---------------------
 
-Cubicweb fully supports the internalization of it's content and interface.
+Cubicweb fully supports the internalization of its content and interface.
 
 Cubicweb's interface internationalization is based on the translation project `GNU gettext`_.
 
@@ -16,7 +16,7 @@
 
 * in your Python code and cubicweb-tal templates : mark translatable strings
 
-* in your application : handle the translation catalog
+* in your instance : handle the translation catalog
 
 String internationalization
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -66,16 +66,18 @@
 .. note::
 
    We dont need to mark the translation strings of entities/relations
-   used by a particular application's schema as they are generated
+   used by a particular instance's schema as they are generated
    automatically.
 
+If you need to add messages on top of those that can be found in the source,
+you can create a file named `i18n/static-messages.pot`.
 
 Handle the translation catalog
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Once the internationalization is done in your application's code, you need
-to populate and update the translation catalog. Cubicweb provides the
-following commands for this purpose:
+Once the internationalization is done in your code, you need to populate and
+update the translation catalog. Cubicweb provides the following commands for this
+purpose:
 
 
 * `i18ncubicweb` updates Cubicweb framework's translation
@@ -83,28 +85,28 @@
   need to use this command.
 
 * `i18ncube` updates the translation catalogs of *one particular
-  component* (or of all components). After this command is
+  cube* (or of all cubes). After this command is
   executed you must update the translation files *.po* in the "i18n"
   directory of your template. This command will of course not remove
   existing translations still in use.
 
 * `i18ninstance` recompile the translation catalogs of *one particular
   instance* (or of all instances) after the translation catalogs of
-  its components have been updated. This command is automatically
+  its cubes have been updated. This command is automatically
   called every time you create or update your instance. The compiled
   catalogs (*.mo*) are stored in the i18n/<lang>/LC_MESSAGES of
-  application where `lang` is the language identifier ('en' or 'fr'
+  instance where `lang` is the language identifier ('en' or 'fr'
   for exemple).
 
 
 Example
 ```````
-You have added and/or modified some translation strings in your application
-(after creating a new view or modifying the application's schema for exemple).
+You have added and/or modified some translation strings in your cube
+(after creating a new view or modifying the cube's schema for exemple).
 To update the translation catalogs you need to do:
 
-1. `cubicweb-ctl i18ncube <component>`
-2. Edit the <component>/xxx.po  files and add missing translations (empty `msgstr`)
+1. `cubicweb-ctl i18ncube <cube>`
+2. Edit the <cube>/i18n/xxx.po  files and add missing translations (empty `msgstr`)
 3. `hg ci -m "updated i18n catalogs"`
-4. `cubicweb-ctl i18ninstance <myapplication>`
+4. `cubicweb-ctl i18ninstance <myinstance>`
 
--- a/doc/book/en/development/devweb/views.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/devweb/views.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,3 +1,6 @@
+
+.. _Views:
+
 Views
 -----
 
@@ -76,8 +79,7 @@
 
 - Using `templatable`, `content_type` and HTTP cache configuration
 
-.. code-block:: python
-
+.. sourcecode:: python
 
     class RSSView(XMLView):
         id = 'rss'
@@ -88,11 +90,9 @@
         cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
 
 
-
 - Using custom selector
 
-.. code-block:: python
-
+.. sourcecode:: python
 
     class SearchForAssociationView(EntityView):
         """view called by the edition view when the user asks
@@ -112,9 +112,9 @@
 We'll show you now an example of a ``primary`` view and how to customize it.
 
 If you want to change the way a ``BlogEntry`` is displayed, just override
-the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py`` ::
+the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py``:
 
-.. code-block:: python
+.. sourcecode:: python
 
    from cubicweb.view import EntityView
    from cubicweb.selectors import implements
@@ -148,7 +148,7 @@
 
 Let us now improve the primary view of a blog
 
-.. code-block:: python
+.. sourcecode:: python
 
  class BlogPrimaryView(EntityView):
      id = 'primary'
@@ -215,9 +215,9 @@
 [FILLME]
 
 
-
 XML views, binaries...
 ----------------------
+
 For views generating other formats than HTML (an image generated dynamically
 for example), and which can not simply be included in the HTML page generated
 by the main template (see above), you have to:
--- a/doc/book/en/development/entityclasses/data-as-objects.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/entityclasses/data-as-objects.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -61,10 +61,10 @@
 Tne :class:`AnyEntity` class
 ----------------------------
 
-To provide a specific behavior for each entity, we have to define
-a class inheriting from `cubicweb.entities.AnyEntity`. In general, we
-define this class in a module of `mycube.entities` package of an application
-so that it will be available on both server and client side.
+To provide a specific behavior for each entity, we have to define a class
+inheriting from `cubicweb.entities.AnyEntity`. In general, we define this class
+in `mycube.entities` module (or in a submodule if we want to split code among
+multiple files) so that it will be available on both server and client side.
 
 The class `AnyEntity` is loaded dynamically from the class `Entity`
 (`cubciweb.entity`). We define a sub-class to add methods or to
--- a/doc/book/en/development/entityclasses/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/entityclasses/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -2,7 +2,7 @@
 ===============
 
 In this chapter, we will introduce the objects that are used to handle
-the data stored in the database.
+the logic associated to the data stored in the database.
 
 .. toctree::
    :maxdepth: 1
@@ -10,4 +10,4 @@
    data-as-objects
    load-sort
    interfaces
-   more
\ No newline at end of file
+   more
--- a/doc/book/en/development/entityclasses/interfaces.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/entityclasses/interfaces.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,16 +1,19 @@
 Interfaces
 ----------
 
+Same thing as object-oriented programming interfaces.
+
 XXX how to define a cw interface
 
 Declaration of interfaces implemented by a class
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
 XXX __implements__
 
 
 Interfaces defined in the library
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-.. automodule:: cubicweb.interface
-   :members:
-`````````````
+automodule:: cubicweb.interface   :members:
+
+
--- a/doc/book/en/development/entityclasses/load-sort.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/entityclasses/load-sort.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,15 +1,17 @@
+
+.. _FetchAttrs:
 
 Loaded attributes and default sorting management
 ````````````````````````````````````````````````
 
-* The class attribute `fetch_attrs` allows to defined in an entity class
-  a list of names of attributes or relations that should be automatically
-  loaded when we recover the entities of this type. In the case of relations,
+* The class attribute `fetch_attrs` allows to define in an entity class a list
+  of names of attributes or relations that should be automatically loaded when
+  entities of this type are fetched from the database. In the case of relations,
   we are limited to *subject of cardinality `?` or `1`* relations.
 
 * The class method `fetch_order(attr, var)` expects an attribute (or relation)
   name as a parameter and a variable name, and it should return a string
-  to use in the requirement `ORDER BY` of an RQL query to automatically
+  to use in the requirement `ORDERBY` of an RQL query to automatically
   sort the list of entities of such type according to this attribute, or
   `None` if we do not want to sort on the attribute given in the parameter.
   By default, the entities are sorted according to their creation date.
--- a/doc/book/en/development/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -18,3 +18,4 @@
    testing/index
    migration/index
    webstdlib/index
+   profiling/index
--- a/doc/book/en/development/migration/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/migration/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -5,19 +5,19 @@
 Migration
 =========
 
-One of the main concept in *CubicWeb* is to create incremental applications.
-For this purpose, multiple actions are provided to facilitate the improvement
-of an application, and in particular to handle the changes to be applied
-to the data model, without loosing existing data.
+One of the main design goals of *CubicWeb* was to support iterative and agile
+development. For this purpose, multiple actions are provided to facilitate the
+improvement of an instance, and in particular to handle the changes to be
+applied to the data model, without loosing existing data.
 
-The current version of an application model is provided in the file
+The current version of a cube (and of cubicweb itself) is provided in the file
 `__pkginfo__.py` as a tuple of 3 integers.
 
 Migration scripts management
 ----------------------------
 
 Migration scripts has to be located in the directory `migration` of your
-application and named accordingly:
+cube and named accordingly:
 
 ::
 
@@ -67,11 +67,8 @@
 * `interactive_mode`, boolean indicating that the script is executed in
   an interactive mode or not
 
-* `appltemplversion`, application model version of the instance
-
-* `templversion`, installed application model version
-
-* `cubicwebversion`, installed cubicweb version
+* `versions_map`, dictionary of migrated versions  (key are cubes
+  names, including 'cubicweb', values are (from version, to version)
 
 * `confirm(question)`, function asking the user and returning true
   if the user answers yes, false otherwise (always returns true in
@@ -84,16 +81,14 @@
 
 * `checkpoint`, request confirming and executing a "commit" at checking point
 
-* `repo_schema`, instance persisting schema (e.g. instance schema of the
-  current migration)
+* `schema`, instance schema (readen from the database)
 
-* `newschema`, installed schema on the file system (e.g. schema of
+* `fsschema`, installed schema on the file system (e.g. schema of
   the updated model and cubicweb)
 
-* `sqlcursor`, SQL cursor for very rare cases where it is really
-   necessary or beneficial to go through the sql
+* `repo`, repository object
 
-* `repo`, repository object
+* `session`, repository session object
 
 
 Schema migration
@@ -134,18 +129,11 @@
 * `drop_relation_definition(subjtype, rtype, objtype, commit=True)`, removes
   a relation definition.
 
-* `synchronize_permissions(ertype, commit=True)`, synchronizes permissions on
-  an entity type or relation type.
-
-* `synchronize_rschema(rtype, commit=True)`, synchronizes properties and permissions
-  on a relation type.
-
-* `synchronize_eschema(etype, commit=True)`, synchronizes properties and persmissions
-  on an entity type.
-
-* `synchronize_schema(commit=True)`, synchronizes the persisting schema with the
-  updated schema (but without adding or removing new entity types, relations types
-  or even relations definitions).
+* `sync_schema_props_perms(ertype=None, syncperms=True, syncprops=True, syncrdefs=True, commit=True)`,
+  synchronizes properties and/or permissions on:
+  - the whole schema if ertype is None
+  - an entity or relation type schema if ertype is a string
+  - a relation definition  if ertype is a 3-uple (subject, relation, object)
 
 * `change_relation_props(subjtype, rtype, objtype, commit=True, **kwargs)`, changes
   properties of a relation definition by using the named parameters of the properties
@@ -204,7 +192,7 @@
 accomplished otherwise or to repair damaged databases during interactive
 session. They are available in `repository` scripts:
 
-* `sqlexec(sql, args=None, ask_confirm=True)`, executes an arbitrary SQL query
+* `sql(sql, args=None, ask_confirm=True)`, executes an arbitrary SQL query on the system source
 * `add_entity_type_table(etype, commit=True)`
 * `add_relation_type_table(rtype, commit=True)`
 * `uninline_relation(rtype, commit=True)`
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/book/en/development/profiling/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,55 @@
+Profiling and performance
+=========================
+
+If you feel that one of your pages takes more time than it should to be
+generated, chances are that you're making too many RQL queries.  Obviously,
+there are other reasons but experience tends to show this is the first thing to
+track down. Luckily, CubicWeb provides a configuration option to log RQL
+queries. In your ``all-in-one.conf`` file, set the **query-log-file** option::
+
+    # web application query log file
+    query-log-file=~/myapp-rql.log
+
+Then restart your application, reload your page and stop your application.
+The file ``myapp-rql.log`` now contains the list of RQL queries that were
+executed during your test. It's a simple text file containing lines such as::
+
+    Any A WHERE X eid %(x)s, X lastname A {'x': 448} -- (0.002 sec, 0.010 CPU sec)
+    Any A WHERE X eid %(x)s, X firstname A {'x': 447} -- (0.002 sec, 0.000 CPU sec)
+
+The structure of each line is::
+
+    <RQL QUERY> <QUERY ARGS IF ANY> -- <TIME SPENT>
+
+CubicWeb also provides the **exlog** command to examine and summarize data found
+in such a file:
+
+.. sourcecode:: sh
+
+    $ cubicweb-ctl exlog < ~/myapp-rql.log
+    0.07 50 Any A WHERE X eid %(x)s, X firstname A {}
+    0.05 50 Any A WHERE X eid %(x)s, X lastname A {}
+    0.01 1 Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, E employees X, X modification_date AA {}
+    0.01 1 Any X WHERE X eid %(x)s, X owned_by U, U eid %(u)s {, }
+    0.01 1 Any B,T,P ORDERBY lower(T) WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, U eid %(x)s {}
+    0.01 1 Any A,B,C,D WHERE A eid %(x)s,A name B,A creation_date C,A modification_date D {}
+
+This command sorts and uniquifies queries so that it's easy to see where
+is the hot spot that needs optimization.
+
+Do not neglect to set the **fetch_attrs** attribute you can define in your
+entity classes because it can greatly reduce the number of queries executed (see
+:ref:`FetchAttrs`).
+
+You should also know about the **profile** option in the ``all-in-on.conf``. If
+set, this option will make your application run in an `hotshot`_ session and
+store the results in the specified file.
+
+.. _hotshot: http://docs.python.org/library/hotshot.html#module-hotshot
+
+Last but no least, if you're using the PostgreSQL database backend, VACUUMing
+your database can significantly improve the performance of the queries (by
+updating the statistics used by the query optimizer). Nowadays, this is done
+automatically from time to time, but if you've just imported a large amount of
+data in your db, you will want to vacuum it (with the analyse option on). Read
+the documentation of your database for more information.
--- a/doc/book/en/development/webstdlib/basetemplates.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/basetemplates.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -159,7 +159,7 @@
 .. _TheMainTemplate:
 
 TheMainTemplate is responsible for the general layout of the entire application.
-It defines the template of ``id = main`` that is used by the application.
+It defines the template of ``id = main`` that is used by the instance.
 
 The default main template (`cubicweb.web.views.basetemplates.TheMainTemplate`)
 builds the page based on the following pattern:
--- a/doc/book/en/development/webstdlib/baseviews.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/baseviews.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -12,33 +12,6 @@
 
 HTML views
 ~~~~~~~~~~
-*oneline*
-    This is a hyper linked *text* view. Similar to the `secondary` view,
-    but called when we want the view to stand on a single line, or just
-    get a brief view. By default this view uses the
-    parameter `MAX_LINE_CHAR` to control the result size.
-
-*secondary*
-    This is a combinaison of an icon and a *oneline* view.
-    By default it renders the two first attributes of the entity as a
-    clickable link redirecting to the primary view.
-
-*incontext, outofcontext*
-    Similar to the `secondary` view, but called when an entity is considered
-    as in or out of context. By default it respectively returns the result of
-    `textincontext` and `textoutofcontext` wrapped in a link leading to
-    the primary view of the entity.
-
-List
-`````
-*list*
-    This view displays a list of entities by creating a HTML list (`<ul>`)
-    and call the view `listitem` for each entity of the result set.
-
-*listitem*
-    This view redirects by default to the `outofcontext` view.
-
-
 Special views
 `````````````
 
@@ -54,11 +27,41 @@
     This view is the default view used when nothing needs to be rendered.
     It is always applicable and it does not return anything
 
-Text views
-~~~~~~~~~~
+Entity views
+````````````
+*incontext, outofcontext*
+    Those are used to display a link to an entity, depending if the entity is
+    considered as displayed in or out of context (of another entity).  By default
+    it respectively returns the result of `textincontext` and `textoutofcontext`
+    wrapped in a link leading to the primary view of the entity.
+
+*oneline*
+    This view is used when we can't tell if the entity should be considered as
+    displayed in or out of context.  By default it returns the result of `text`
+    in a link leading to the primary view of the entity.
+
+List
+`````
+*list*
+    This view displays a list of entities by creating a HTML list (`<ul>`)
+    and call the view `listitem` for each entity of the result set.
+
+*listitem*
+    This view redirects by default to the `outofcontext` view.
+
+*adaptedlist*
+    This view displays a list of entities of the same type, in HTML section (`<div>`)
+    and call the view `adaptedlistitem` for each entity of the result set.
+
+*adaptedlistitem*
+    This view redirects by default to the `outofcontext` view.
+
+Text entity views
+~~~~~~~~~~~~~~~~~
 *text*
-    This is the simplest text view for an entity. It displays the
-    title of an entity. It should not contain HTML.
+    This is the simplest text view for an entity. By default it returns the
+    result of the `.dc_title` method, which is cut to fit the
+    `navigation.short-line-size` property if necessary.
 
 *textincontext, textoutofcontext*
     Similar to the `text` view, but called when an entity is considered out or
--- a/doc/book/en/development/webstdlib/editcontroller.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/editcontroller.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,5 @@
 .. -*- coding: utf-8 -*-
+
 The 'edit' controller (:mod:`cubicweb.web.views.editcontroller`)
 ----------------------------------------------------------------
 
--- a/doc/book/en/development/webstdlib/primary.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/primary.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -15,7 +15,7 @@
 Let's have a quick look at the EntityView ``PrimaryView`` as well as
 its rendering method
 
-.. code-block:: python
+.. sourcecode:: python
 
     class PrimaryView(EntityView):
         """the full view of an non final entity"""
--- a/doc/book/en/development/webstdlib/startup.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/startup.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -9,5 +9,5 @@
     a result set to apply to.
 
 *schema*
-    A view dedicated to the display of the schema of the application
+    A view dedicated to the display of the schema of the instance
 
--- a/doc/book/en/development/webstdlib/urlpublish.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/urlpublish.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,5 @@
 .. -*- coding: utf-8 -*-
+
 URL Rewriting (:mod:`cubicweb.web.views.urlpublish`) and (:mod:`cubicweb.web.views.urlrewrite`)
 ------------------------------------------------------------------------------------------------
 
--- a/doc/book/en/development/webstdlib/xmlrss.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/development/webstdlib/xmlrss.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -1,3 +1,5 @@
+.. _XmlAndRss:
+
 XML and RSS views (:mod:`cubicweb.web.views.xmlrss`)
 ----------------------------------------------------
 
--- a/doc/book/en/intro/concepts/index.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/intro/concepts/index.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -64,11 +64,12 @@
 
 On a Unix system, the instances are usually stored in the directory
 :file:`/etc/cubicweb.d/`. During development, the :file:`~/etc/cubicweb.d/`
-directory is looked up, as well as the paths in :envvar:`CW_REGISTRY`
+directory is looked up, as well as the paths in :envvar:`CW_INSTANCES_DIR`
 environment variable.
 
-The term application can refer to an instance or to a cube, depending on the
-context. This book will try to avoid using this term and use *cube* and
+The term application is used to refer at "something that should do something as a
+whole", eg more like a project and so can refer to an instance or to a cube,
+depending on the context. This book will try to use *application*, *cube* and
 *instance* as appropriate.
 
 Data Repository
@@ -154,7 +155,7 @@
 identifier in the same registry, At runtime, appobjects are selected in the
 vregistry according to the context.
 
-Application objects are stored in the registry using a two level hierarchy :
+Application objects are stored in the registry using a two-level hierarchy :
 
   object's `__registry__` : object's `id` : [list of app objects]
 
@@ -166,7 +167,7 @@
 At startup, the `registry` or registers base, inspects a number of directories
 looking for compatible classes definition. After a recording process, the objects
 are assigned to registers so that they can be selected dynamically while the
-application is running.
+instance is running.
 
 Selectors
 ~~~~~~~~~
@@ -215,7 +216,7 @@
 
 **No need for a complicated ORM when you have a powerful query language**
 
-All the persistant data in a CubicWeb application is retrieved and modified by using the
+All the persistent data in a CubicWeb instance is retrieved and modified by using the
 Relation Query Language.
 
 This query language is inspired by SQL but is on a higher level in order to
--- a/doc/book/en/intro/tutorial/components.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/intro/tutorial/components.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -11,7 +11,7 @@
 A library of standard cubes are available from `CubicWeb Forge`_
 Cubes provide entities and views.
 
-The available application entities are:
+The available application entities in standard cubes are:
 
 * addressbook: PhoneNumber and PostalAddress
 
@@ -39,11 +39,12 @@
 * zone: Zone (to define places within larger places, for example a
   city in a state in a country)
 
+.. _`CubicWeb Forge`: http://www.cubicweb.org/project/
 
 Adding comments to BlogDemo
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-To import a cube in your application just change the line in the
+To import a cube in your instance just change the line in the
 ``__pkginfo__.py`` file and verify that the cube you are planning
 to use is listed by the command ``cubicweb-ctl list``.
 For example::
@@ -51,7 +52,7 @@
     __use__ = ('comment',)
 
 will make the ``Comment`` entity available in your ``BlogDemo``
-application.
+cube.
 
 Change the schema to add a relationship between ``BlogEntry`` and
 ``Comment`` and you are done. Since the comment cube defines the
@@ -67,13 +68,12 @@
 Once you modified your data model, you need to synchronize the
 database with your model. For this purpose, *CubicWeb* provides
 a very useful command ``cubicweb-ctl shell blogdemo`` which
-launches an interactive migration Python shell. (see
-:ref:`cubicweb-ctl` for more details))
-As you modified a relation from the `BlogEntry` schema,
-run the following command:
+launches an interactive shell where you can enter migration
+commands. (see :ref:`cubicweb-ctl` for more details))
+As you added the cube named `comment`, you need to run:
+
 ::
 
-  synchronize_rschema('BlogEntry')
+  add_cube('comment')
 
-You can now start your application and add comments to each
-`BlogEntry`.
+You can now start your instance and comment your blog entries.
--- a/doc/book/en/intro/tutorial/conclusion.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/intro/tutorial/conclusion.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -3,15 +3,13 @@
 What's next?
 ------------
 
-We demonstrated how from a straight out of the box *CubicWeb*
-installation, you can build your web-application based on a
-schema. It's all already there: views, templates, permissions,
-etc. The step forward is now for you to customize according
-to your needs.
+We demonstrated how from a straight out of the box *CubicWeb* installation, you
+can build your web application based on a data model. It's all already there:
+views, templates, permissions, etc. The step forward is now for you to customize
+according to your needs.
 
-More than a web application, many features are available to
-extend your application, for example: RSS channel integration
-(:ref:`rss`), hooks (:ref:`hooks`), support of sources such as
-Google App Engine (:ref:`gaecontents`) and lots of others to
-discover through our book.
+Many features are available to extend your application, for example: RSS channel
+integration (:ref:`XmlAndRss`), hooks (:ref:`hooks`), support of sources such as
+Google App Engine (:ref:`GoogleAppEngineSource`) and lots of others to discover
+through our book.
 
--- a/doc/book/en/intro/tutorial/create-cube.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/intro/tutorial/create-cube.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 
 This will create in the cubes directory (``/path/to/forest/cubes`` for Mercurial
 installation, ``/usr/share/cubicweb/cubes`` for debian packages installation)
-a directory named ``blog`` reflecting the structure described in :ref:`cubesConcepts`.
+a directory named ``blog`` reflecting the structure described in :ref:`Concepts`.
 
 .. _DefineDataModel:
 
@@ -60,39 +60,39 @@
 Create your instance
 --------------------
 
-To use this cube as an application and create a new instance named ``blogdemo``, do::
+To use this cube as an instance and create a new instance named ``blogdemo``, do::
 
   cubicweb-ctl create blog blogdemo
 
 
 This command will create the corresponding database and initialize it.
 
-Welcome to your web application
+Welcome to your web instance
 -------------------------------
 
-Start your application in debug mode with the following command: ::
+Start your instance in debug mode with the following command: ::
 
   cubicweb-ctl start -D blogdemo
 
 
-You can now access your web application to create blogs and post messages
+You can now access your web instance to create blogs and post messages
 by visiting the URL http://localhost:8080/.
 
-A login form will appear. By default, the application will not allow anonymous
-users to enter the application. To login, you need then use the admin account
+A login form will appear. By default, the instance will not allow anonymous
+users to enter the instance. To login, you need then use the admin account
 you created at the time you initialized the database with ``cubicweb-ctl
 create``.
 
 .. image:: ../../images/login-form.png
 
 
-Once authenticated, you can start playing with your application
+Once authenticated, you can start playing with your instance
 and create entities.
 
 .. image:: ../../images/blog-demo-first-page.png
 
-Please notice that so far, the *CubicWeb* franework managed all aspects of
-the web application based on the schema provided at first.
+Please notice that so far, the *CubicWeb* framework managed all aspects of
+the web application based on the schema provided at the beginning.
 
 
 Add entities
@@ -222,7 +222,7 @@
 
 To do so, please apply the following changes:
 
-.. code-block:: python
+.. sourcecode:: python
 
   from cubicweb.web.views import baseviews
 
@@ -251,7 +251,7 @@
             self.render_entity_relations(entity, siderelations)
 
 .. note::
-  When a view is modified, it is not required to restart the application
+  When a view is modified, it is not required to restart the instance
   server. Save the Python file and reload the page in your web browser
   to view the changes.
 
@@ -268,6 +268,7 @@
 The view has a ``self.w()`` method that is used to output data, in our
 example HTML output.
 
-You can find more details about views and selectors in :ref:`ViewDefinition`.
+.. note::
+   You can find more details about views and selectors in :ref:`ViewDefinition`.
 
 
--- a/doc/book/en/intro/tutorial/maintemplate.rst	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/book/en/intro/tutorial/maintemplate.rst	Fri Aug 07 12:20:50 2009 +0200
@@ -36,15 +36,15 @@
 Customize header
 `````````````````
 
-Let's now move the search box in the header and remove the login form
-from the header. We'll show how to move it to the left column of the application.
+Let's now move the search box in the header and remove the login form from the
+header. We'll show how to move it to the left column of the user interface.
 
 Let's say we do not want anymore the login menu to be in the header
 
 First, to remove the login menu, we just need to comment out the display of the
 login graphic component such as follows:
 
-.. code-block :: python
+.. sourcecode:: python
 
   class MyBlogHTMLPageHeader(HTMLPageHeader):
 
@@ -89,9 +89,9 @@
 ````````````````
 
 If you want to change the footer for example, look
-for HTMLPageFooter and override it in your views file as in: ::
+for HTMLPageFooter and override it in your views file as in:
 
-..code-block :: python
+.. sourcecode:: python
 
   from cubicweb.web.views.basetemplates import HTMLPageFooter
 
--- a/doc/tools/generate_modules.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/doc/tools/generate_modules.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,11 +8,15 @@
 
 import sys
 
-EXCLUDE_DIRS = ('test', 'tests', 'examples', 'data', 'doc', '.hg', 'migration')
+EXCLUDE_DIRS = ('test', 'tests', 'examples', 'data', 'doc', 'dist',
+                '.hg', 'migration')
 if __name__ == '__main__':
 
-    from logilab.common.sphinxutils import generate_modules_file
-
-    gen = generate_modules_file(sys.argv[1:])
-    gen.set_docdir("cubicweb/doc/book/en")
-    gen.make(['cubicweb', '/indexer', '/logilab', '/rql', '/yams'], EXCLUDE_DIRS)
+    from logilab.common.sphinxutils import ModuleGenerator
+    cw_gen = ModuleGenerator('cubicweb', '../..')
+    cw_gen.generate("../book/en/annexes/api_cubicweb.rst",
+                    EXCLUDE_DIRS + ('cwdesklets', 'misc', 'skel', 'skeleton'))
+    for modname in ('indexer', 'logilab', 'rql', 'yams'):
+        cw_gen = ModuleGenerator(modname, '../../../' + modname)
+        cw_gen.generate("../book/en/annexes/api_%s.rst" % modname,
+                        EXCLUDE_DIRS + ('tools',))
--- a/entities/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/entities/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -9,13 +9,11 @@
 
 from warnings import warn
 
-from logilab.common.deprecation import deprecated_function, obsolete
+from logilab.common.deprecation import deprecated
 from logilab.common.decorators import cached
 
 from cubicweb import Unauthorized, typed_eid
 from cubicweb.entity import Entity
-from cubicweb.utils import dump_class
-from cubicweb.schema import FormatConstraint
 
 from cubicweb.interfaces import IBreadCrumbs, IFeed
 
@@ -27,19 +25,6 @@
     id = 'Any'
     __implements__ = (IBreadCrumbs, IFeed)
 
-    @classmethod
-    def selected(cls, etype):
-        """the special Any entity is used as the default factory, so
-        the actual class has to be constructed at selection time once we
-        have an actual entity'type
-        """
-        if cls.id == etype:
-            return cls
-        usercls = dump_class(cls, etype)
-        usercls.id = etype
-        usercls.__initialize__()
-        return usercls
-
     fetch_attrs = ('modification_date',)
     @classmethod
     def fetch_order(cls, attr, var):
@@ -240,22 +225,22 @@
             wdg = widget(cls.vreg, tschema, rschema, cls, 'object')
         return wdg
 
-    @obsolete('use EntityFieldsForm.subject_relation_vocabulary')
+    @deprecated('use EntityFieldsForm.subject_relation_vocabulary')
     def subject_relation_vocabulary(self, rtype, limit):
-        form = self.vreg.select_object('forms', 'edition', self.req, entity=self)
+        form = self.vreg.select('forms', 'edition', self.req, entity=self)
         return form.subject_relation_vocabulary(rtype, limit)
 
-    @obsolete('use EntityFieldsForm.object_relation_vocabulary')
+    @deprecated('use EntityFieldsForm.object_relation_vocabulary')
     def object_relation_vocabulary(self, rtype, limit):
-        form = self.vreg.select_object('forms', 'edition', self.req, entity=self)
+        form = self.vreg.select('forms', 'edition', self.req, entity=self)
         return form.object_relation_vocabulary(rtype, limit)
 
-    @obsolete('use AutomaticEntityForm.[e]relations_by_category')
+    @deprecated('use AutomaticEntityForm.[e]relations_by_category')
     def relations_by_category(self, categories=None, permission=None):
         from cubicweb.web.views.autoform import AutomaticEntityForm
         return AutomaticEntityForm.erelations_by_category(self, categories, permission)
 
-    @obsolete('use AutomaticEntityForm.[e]srelations_by_category')
+    @deprecated('use AutomaticEntityForm.[e]srelations_by_category')
     def srelations_by_category(self, categories=None, permission=None):
         from cubicweb.web.views.autoform import AutomaticEntityForm
         return AutomaticEntityForm.esrelations_by_category(self, categories, permission)
--- a/entities/schemaobjs.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/entities/schemaobjs.py	Fri Aug 07 12:20:50 2009 +0200
@@ -25,8 +25,6 @@
     def dc_long_title(self):
         stereotypes = []
         _ = self.req._
-        if self.meta:
-            stereotypes.append(_('meta'))
         if self.final:
             stereotypes.append(_('final'))
         if stereotypes:
@@ -48,8 +46,6 @@
     def dc_long_title(self):
         stereotypes = []
         _ = self.req._
-        if self.meta:
-            stereotypes.append(_('meta'))
         if self.symetric:
             stereotypes.append(_('symetric'))
         if self.inlined:
@@ -116,6 +112,18 @@
             return self.relation_type[0].rest_path(), {}
         return super(CWRelation, self).after_deletion_path()
 
+    @property
+    def rtype(self):
+        return self.relation_type[0]
+
+    @property
+    def stype(self):
+        return self.from_entity[0]
+
+    @property
+    def otype(self):
+        return self.to_entity[0]
+
 
 class CWAttribute(CWRelation):
     id = 'CWAttribute'
--- a/entities/test/data/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/entities/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,8 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, String
+
 class Company(EntityType):
     name = String()
 
--- a/entities/test/unittest_base.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/entities/test/unittest_base.py	Fri Aug 07 12:20:50 2009 +0200
@@ -263,21 +263,24 @@
 class InterfaceTC(EnvBasedTC):
 
     def test_nonregr_subclasses_and_mixins_interfaces(self):
+        self.failUnless(implements(CWUser, IWorkflowable))
         class MyUser(CWUser):
             __implements__ = (IMileStone,)
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(MyUser)
-        self.failUnless(implements(CWUser, IWorkflowable))
-        self.failUnless(implements(MyUser, IMileStone))
-        self.failUnless(implements(MyUser, IWorkflowable))
+        self.vreg.register_appobject_class(MyUser)
+        self.vreg['etypes'].initialization_completed()
+        MyUser_ = self.vreg['etypes'].etype_class('CWUser')
+        self.failUnless(MyUser is MyUser_)
+        self.failUnless(implements(MyUser_, IMileStone))
+        self.failUnless(implements(MyUser_, IWorkflowable))
 
 
 class SpecializedEntityClassesTC(EnvBasedTC):
 
     def select_eclass(self, etype):
         # clear selector cache
-        clear_cache(self.vreg, 'etype_class')
-        return self.vreg.etype_class(etype)
+        clear_cache(self.vreg['etypes'], 'etype_class')
+        return self.vreg['etypes'].etype_class(etype)
 
     def test_etype_class_selection_and_specialization(self):
         # no specific class for Subdivisions, the default one should be selected
@@ -290,7 +293,7 @@
         for etype in ('Company', 'Division', 'SubDivision'):
             class Foo(AnyEntity):
                 id = etype
-            self.vreg.register_vobject_class(Foo)
+            self.vreg.register_appobject_class(Foo)
             eclass = self.select_eclass('SubDivision')
             if etype == 'SubDivision':
                 self.failUnless(eclass is Foo)
--- a/entity.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/entity.py	Fri Aug 07 12:20:50 2009 +0200
@@ -12,7 +12,7 @@
 from logilab.common import interface
 from logilab.common.compat import all
 from logilab.common.decorators import cached
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 from logilab.mtconverter import TransformData, TransformError, xml_escape
 
 from rql.utils import rqlvar_maker
@@ -20,16 +20,12 @@
 from cubicweb import Unauthorized
 from cubicweb.rset import ResultSet
 from cubicweb.selectors import yes
-from cubicweb.appobject import AppRsetObject
+from cubicweb.appobject import AppObject
 from cubicweb.schema import RQLVocabularyConstraint, RQLConstraint, bw_normalize_etype
 
-try:
-    from cubicweb.common.uilib import printable_value, soup2xhtml
-    from cubicweb.common.mixins import MI_REL_TRIGGERS
-    from cubicweb.common.mttransforms import ENGINE
-except ImportError:
-    # missing -common
-    MI_REL_TRIGGERS = {}
+from cubicweb.common.uilib import printable_value, soup2xhtml
+from cubicweb.common.mixins import MI_REL_TRIGGERS
+from cubicweb.common.mttransforms import ENGINE
 
 _marker = object()
 
@@ -136,7 +132,7 @@
         return super(_metaentity, mcs).__new__(mcs, name, bases, classdict)
 
 
-class Entity(AppRsetObject, dict):
+class Entity(AppObject, dict):
     """an entity instance has e_schema automagically set on
     the class and instances has access to their issuing cursor.
 
@@ -171,15 +167,6 @@
     # class attributes set automatically at registration time
     e_schema = None
 
-    @classmethod
-    def registered(cls, registry):
-        """build class using descriptor at registration time"""
-        assert cls.id is not None
-        super(Entity, cls).registered(registry)
-        if cls.id != 'Any':
-            cls.__initialize__()
-        return cls
-
     MODE_TAGS = set(('link', 'create'))
     CATEGORY_TAGS = set(('primary', 'secondary', 'generic', 'generated')) # , 'metadata'))
     @classmethod
@@ -269,7 +256,7 @@
                     continue
                 if card == '?':
                     restrictions[-1] += '?' # left outer join if not mandatory
-                destcls = cls.vreg.etype_class(desttype)
+                destcls = cls.vreg['etypes'].etype_class(desttype)
                 destcls._fetch_restrictions(var, varmaker, destcls.fetch_attrs,
                                             selection, orderby, restrictions,
                                             user, ordermethod, visited=visited)
@@ -281,8 +268,9 @@
     @classmethod
     @cached
     def parent_classes(cls):
-        parents = [cls.vreg.etype_class(e.type) for e in cls.e_schema.ancestors()]
-        parents.append(cls.vreg.etype_class('Any'))
+        parents = [cls.vreg['etypes'].etype_class(e.type)
+                   for e in cls.e_schema.ancestors()]
+        parents.append(cls.vreg['etypes'].etype_class('Any'))
         return parents
 
     @classmethod
@@ -303,7 +291,7 @@
         return mainattr, needcheck
 
     def __init__(self, req, rset=None, row=None, col=0):
-        AppRsetObject.__init__(self, req, rset, row, col)
+        AppObject.__init__(self, req, rset, row, col)
         dict.__init__(self)
         self._related_cache = {}
         if rset is not None:
@@ -370,11 +358,18 @@
 
     def view(self, vid, __registry='views', **kwargs):
         """shortcut to apply a view on this entity"""
-        return self.vreg.render(__registry, vid, self.req, rset=self.rset,
-                                row=self.row, col=self.col, **kwargs)
+        return self.vreg[__registry].render(vid, self.req, rset=self.rset,
+                                            row=self.row, col=self.col, **kwargs)
 
-    def absolute_url(self, method=None, **kwargs):
+    def absolute_url(self, *args, **kwargs):
         """return an absolute url to view this entity"""
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        if args:
+            assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+            method = args[0]
+        else:
+            method = None
         # in linksearch mode, we don't want external urls else selecting
         # the object for use in the relation is tricky
         # XXX search_state is web specific
@@ -478,7 +473,7 @@
         assert self.has_eid()
         execute = self.req.execute
         for rschema in self.e_schema.subject_relations():
-            if rschema.meta or rschema.is_final():
+            if rschema.is_final() or rschema.meta:
                 continue
             # skip already defined relations
             if getattr(self, rschema.type):
@@ -644,7 +639,8 @@
             if not self.is_saved():
                 return None
             rql = "Any A WHERE X eid %%(x)s, X %s A" % name
-            # XXX should we really use unsafe_execute here??
+            # XXX should we really use unsafe_execute here? I think so (syt),
+            # see #344874
             execute = getattr(self.req, 'unsafe_execute', self.req.execute)
             try:
                 rset = execute(rql, {'x': self.eid}, 'x')
@@ -678,7 +674,10 @@
             pass
         assert self.has_eid()
         rql = self.related_rql(rtype, role)
-        rset = self.req.execute(rql, {'x': self.eid}, 'x')
+        # XXX should we really use unsafe_execute here? I think so (syt),
+        # see #344874
+        execute = getattr(self.req, 'unsafe_execute', self.req.execute)
+        rset = execute(rql, {'x': self.eid}, 'x')
         self.set_related_cache(rtype, role, rset)
         return self.related(rtype, role, limit, entities)
 
@@ -695,13 +694,13 @@
         if len(targettypes) > 1:
             fetchattrs_list = []
             for ttype in targettypes:
-                etypecls = self.vreg.etype_class(ttype)
+                etypecls = self.vreg['etypes'].etype_class(ttype)
                 fetchattrs_list.append(set(etypecls.fetch_attrs))
             fetchattrs = reduce(set.intersection, fetchattrs_list)
             rql = etypecls.fetch_rql(self.req.user, [restriction], fetchattrs,
                                      settype=False)
         else:
-            etypecls = self.vreg.etype_class(targettypes[0])
+            etypecls = self.vreg['etypes'].etype_class(targettypes[0])
             rql = etypecls.fetch_rql(self.req.user, [restriction], settype=False)
         # optimisation: remove ORDERBY if cardinality is 1 or ? (though
         # greater_card return 1 for those both cases)
@@ -716,7 +715,7 @@
 
     # generic vocabulary methods ##############################################
 
-    @obsolete('see new form api')
+    @deprecated('see new form api')
     def vocabulary(self, rtype, role='subject', limit=None):
         """vocabulary functions must return a list of couples
         (label, eid) that will typically be used to fill the
@@ -726,7 +725,7 @@
         interpreted as a separator in case vocabulary results are grouped
         """
         from logilab.common.testlib import mock_object
-        form = self.vreg.select_object('forms', 'edition', self.req, entity=self)
+        form = self.vreg.select('forms', 'edition', self.req, entity=self)
         field = mock_object(name=rtype, role=role)
         return form.form_field_vocabulary(field, limit)
 
@@ -757,7 +756,7 @@
         else:
             restriction += [cstr.restriction for cstr in constraints
                             if isinstance(cstr, RQLConstraint)]
-        etypecls = self.vreg.etype_class(targettype)
+        etypecls = self.vreg['etypes'].etype_class(targettype)
         rql = etypecls.fetch_rql(self.req.user, restriction,
                                  mainvar=searchedvar, ordermethod=ordermethod)
         # ensure we have an order defined
@@ -784,7 +783,7 @@
     def relation_cached(self, rtype, role):
         """return true if the given relation is already cached on the instance
         """
-        return '%s_%s' % (rtype, role) in self._related_cache
+        return self._related_cache.get('%s_%s' % (rtype, role))
 
     def related_cache(self, rtype, role, entities=True, limit=None):
         """return values for the given relation if it's cached on the instance,
--- a/etwist/request.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/etwist/request.py	Fri Aug 07 12:20:50 2009 +0200
@@ -38,7 +38,7 @@
         self._headers = req.headers
 
     def base_url(self):
-        """return the root url of the application"""
+        """return the root url of the instance"""
         return self._base_url
 
     def http_method(self):
@@ -47,7 +47,7 @@
 
     def relative_path(self, includeparams=True):
         """return the normalized path of the request (ie at least relative
-        to the application's root, but some other normalization may be needed
+        to the instance's root, but some other normalization may be needed
         so that the returned path may be used to compare to generated urls
 
         :param includeparams:
--- a/etwist/server.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/etwist/server.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-"""twisted server for CubicWeb web applications
+"""twisted server for CubicWeb web instances
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -8,21 +8,24 @@
 __docformat__ = "restructuredtext en"
 
 import sys
+import os
 import select
 from time import mktime
 from datetime import date, timedelta
 from urlparse import urlsplit, urlunsplit
+import hotshot
 
 from twisted.application import service, strports
+from twisted.scripts._twistd_unix import daemonize
 from twisted.internet import reactor, task, threads
 from twisted.internet.defer import maybeDeferred
 from twisted.web2 import channel, http, server, iweb
 from twisted.web2 import static, resource, responsecode
 
-from cubicweb import ObjectNotFound
+from cubicweb import ObjectNotFound, CW_EVENT_MANAGER
 from cubicweb.web import (AuthenticationError, NotFound, Redirect,
-                       RemoteCallFailed, DirectResponse, StatusResponse,
-                       ExplicitLogin)
+                          RemoteCallFailed, DirectResponse, StatusResponse,
+                          ExplicitLogin)
 from cubicweb.web.application import CubicWebPublisher
 
 from cubicweb.etwist.request import CubicWebTwistedRequestAdapter
@@ -33,12 +36,12 @@
     lc.start(interval)
 
 def start_looping_tasks(repo):
-    for interval, func in repo._looping_tasks:
+    for interval, func, args in repo._looping_tasks:
         repo.info('starting twisted task %s with interval %.2fs',
                   func.__name__, interval)
-        def catch_error_func(repo=repo, func=func):
+        def catch_error_func(repo=repo, func=func, args=args):
             try:
-                func()
+                func(*args)
             except:
                 repo.exception('error in looping task')
         start_task(interval, catch_error_func)
@@ -106,14 +109,15 @@
                 self.pyro_listen_timeout = 0.02
                 start_task(1, self.pyro_loop_event)
             self.appli.repo.start_looping_tasks()
-        try:
-            self.url_rewriter = self.appli.vreg.select_component('urlrewriter')
-        except ObjectNotFound:
-            self.url_rewriter = None
+        self.set_url_rewriter()
+        CW_EVENT_MANAGER.bind('after-registry-reload', self.set_url_rewriter)
         interval = min(config['cleanup-session-time'] or 120,
                        config['cleanup-anonymous-session-time'] or 720) / 2.
         start_task(interval, self.appli.session_handler.clean_sessions)
 
+    def set_url_rewriter(self):
+        self.url_rewriter = self.appli.vreg['components'].select_object('urlrewriter')
+
     def shutdown_event(self):
         """callback fired when the server is shutting down to properly
         clean opened sessions
@@ -271,35 +275,6 @@
             content = self.appli.need_login_content(req)
         return http.Response(code, req.headers_out, content)
 
-
-# This part gets run when you run this file via: "twistd -noy demo.py"
-def main(appid, cfgname):
-    """Starts an cubicweb  twisted server for an application
-
-    appid: application's identifier
-    cfgname: name of the configuration to use (twisted or all-in-one)
-    """
-    from cubicweb.cwconfig import CubicWebConfiguration
-    from cubicweb.etwist import twconfig # trigger configuration registration
-    config = CubicWebConfiguration.config_for(appid, cfgname)
-    # XXX why calling init_available_cubes here ?
-    config.init_available_cubes()
-    # create the site and application objects
-    if '-n' in sys.argv: # debug mode
-        cubicweb = CubicWebRootResource(config, debug=True)
-    else:
-        cubicweb = CubicWebRootResource(config)
-    #toplevel = vhost.VHostURIRewrite(base_url, cubicweb)
-    toplevel = cubicweb
-    website = server.Site(toplevel)
-    application = service.Application("cubicweb")
-    # serve it via standard HTTP on port set in the configuration
-    s = strports.service('tcp:%04d' % (config['port'] or 8080),
-                         channel.HTTPFactory(website))
-    s.setServiceParent(application)
-    return application
-
-
 from twisted.python import failure
 from twisted.internet import defer
 from twisted.web2 import fileupload
@@ -359,7 +334,7 @@
 def _gc_debug():
     import gc
     from pprint import pprint
-    from cubicweb.vregistry import VObject
+    from cubicweb.appobject import AppObject
     gc.collect()
     count = 0
     acount = 0
@@ -367,7 +342,7 @@
     for obj in gc.get_objects():
         if isinstance(obj, CubicWebTwistedRequestAdapter):
             count += 1
-        elif isinstance(obj, VObject):
+        elif isinstance(obj, AppObject):
             acount += 1
         else:
             try:
@@ -381,3 +356,28 @@
     ocount = sorted(ocount.items(), key=lambda x: x[1], reverse=True)[:20]
     pprint(ocount)
     print 'UNREACHABLE', gc.garbage
+
+def run(config, debug):
+    # create the site
+    root_resource = CubicWebRootResource(config, debug)
+    website = server.Site(root_resource)
+    # serve it via standard HTTP on port set in the configuration
+    port = config['port'] or 8080
+    reactor.listenTCP(port, channel.HTTPFactory(website))
+    baseurl = config['base-url'] or config.default_base_url()
+    logger = getLogger('cubicweb.twisted')
+    logger.info('instance started on %s', baseurl)
+    if not debug:
+        daemonize()
+        if config['pid-file']:
+            # ensure the directory where the pid-file should be set exists (for
+            # instance /var/run/cubicweb may be deleted on computer restart)
+            piddir = os.path.dirname(config['pid-file'])
+            if not os.path.exists(piddir):
+                os.makedirs(piddir)
+            file(config['pid-file'], 'w').write(str(os.getpid()))
+    if config['profile']:
+        prof = hotshot.Profile(config['profile'])
+        prof.runcall(reactor.run)
+    else:
+        reactor.run()
--- a/etwist/twconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/etwist/twconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,9 +1,9 @@
 """twisted server configurations:
 
-* the "twisted" configuration to get a web application running in a standalone
+* the "twisted" configuration to get a web instance running in a standalone
   twisted web server which talk to a repository server using Pyro
 
-* the "all-in-one" configuration to get a web application running in a twisted
+* the "all-in-one" configuration to get a web instance running in a twisted
   web server integrating a repository server in the same process (only available
   if the repository part of the software is installed
 
@@ -19,7 +19,7 @@
 from cubicweb.web.webconfig import WebConfiguration, merge_options, Method
 
 class TwistedConfiguration(WebConfiguration):
-    """web application (in a twisted web server) client of a RQL server"""
+    """web instance (in a twisted web server) client of a RQL server"""
     name = 'twisted'
 
     options = merge_options((
@@ -81,14 +81,14 @@
     from cubicweb.server.serverconfig import ServerConfiguration
 
     class AllInOneConfiguration(TwistedConfiguration, ServerConfiguration):
-        """repository and web application in the same twisted process"""
+        """repository and web instance in the same twisted process"""
         name = 'all-in-one'
         repo_method = 'inmemory'
         options = merge_options(TwistedConfiguration.options
                                 + ServerConfiguration.options)
 
-        cubicweb_vobject_path = TwistedConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path
-        cube_vobject_path = TwistedConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path
+        cubicweb_appobject_path = TwistedConfiguration.cubicweb_appobject_path | ServerConfiguration.cubicweb_appobject_path
+        cube_appobject_path = TwistedConfiguration.cube_appobject_path | ServerConfiguration.cube_appobject_path
         def pyro_enabled(self):
             """tell if pyro is activated for the in memory repository"""
             return self['pyro-server']
--- a/etwist/twctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/etwist/twctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,50 +10,17 @@
 
 from cubicweb import underline_title
 from cubicweb.toolsutils import CommandHandler
-from cubicweb.web.webctl import WebCreateHandler
 
 # trigger configuration registration
 import cubicweb.etwist.twconfig # pylint: disable-msg=W0611
 
-
-class TWCreateHandler(WebCreateHandler):
-    cfgname = 'twisted'
-
-    def bootstrap(self, cubes, inputlevel=0):
-        """bootstrap this configuration"""
-        print '\n'+underline_title('Configuring Twisted')
-        mainpyfile = self.config.server_file()
-        mainpy = open(mainpyfile, 'w')
-        mainpy.write('''
-from cubicweb.etwist import server
-application = server.main(%r, %r)
-''' % (self.config.appid, self.config.name))
-        mainpy.close()
-        print '-> generated %s' % mainpyfile
-        super(TWCreateHandler, self).bootstrap(cubes, inputlevel)
-
-
 class TWStartHandler(CommandHandler):
     cmdname = 'start'
     cfgname = 'twisted'
 
     def start_command(self, config, debug):
-        command = ['%s `which twistd`' % sys.executable]
-        for ctl_opt, server_opt in (('pid-file', 'pidfile'),
-                                    ('uid', 'uid'),
-                                    ('log-file', 'logfile',)):
-            value = config[ctl_opt]
-            if not value or (debug and ctl_opt == 'log-file'):
-                continue
-            command.append('--%s %s' % (server_opt, value))
-        if debug:
-            command.append('-n')
-        if config['profile']:
-            command.append('-p %s --savestats' % config['profile'])
-        command.append('-oy')
-        command.append(self.config.server_file())
-        return ' '.join(command)
-
+        from cubicweb.etwist import server
+        server.run(config, debug)
 
 class TWStopHandler(CommandHandler):
     cmdname = 'stop'
@@ -63,16 +30,15 @@
 try:
     from cubicweb.server import serverctl
 
-    class AllInOneCreateHandler(serverctl.RepositoryCreateHandler, TWCreateHandler):
-        """configuration to get a web application running in a twisted web
-        server integrating a repository server in the same process
+    class AllInOneCreateHandler(serverctl.RepositoryCreateHandler):
+        """configuration to get an instance running in a twisted web server
+        integrating a repository server in the same process
         """
         cfgname = 'all-in-one'
 
         def bootstrap(self, cubes, inputlevel=0):
             """bootstrap this configuration"""
             serverctl.RepositoryCreateHandler.bootstrap(self, cubes, inputlevel)
-            TWCreateHandler.bootstrap(self, cubes, inputlevel)
 
     class AllInOneStartHandler(TWStartHandler):
         cmdname = 'start'
--- a/ext/rest.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/ext/rest.py	Fri Aug 07 12:20:50 2009 +0200
@@ -31,6 +31,7 @@
 
 from logilab.mtconverter import ESC_UCAR_TABLE, ESC_CAR_TABLE, xml_escape
 
+from cubicweb import UnknownEid
 from cubicweb.ext.html4zope import Writer
 
 # We provide our own parser as an attempt to get rid of
@@ -68,8 +69,13 @@
         return [prb], [msg]
     # Base URL mainly used by inliner.pep_reference; so this is correct:
     context = inliner.document.settings.context
-    refedentity = context.req.eid_rset(eid_num).get_entity(0, 0)
-    ref = refedentity.absolute_url()
+    try:
+        refedentity = context.req.entity_from_eid(eid_num)
+    except UnknownEid:
+        ref = '#'
+        rest += u' ' + context.req._('(UNEXISTANT EID)')
+    else:
+        ref = refedentity.absolute_url()
     set_classes(options)
     return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
                             **options)], []
--- a/goa/appobjects/components.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/appobjects/components.py	Fri Aug 07 12:20:50 2009 +0200
@@ -45,7 +45,7 @@
     content_type = 'image/png'
     def call(self):
         """display global schema information"""
-        skipmeta = not int(self.req.form.get('withmeta', 0))
+        skipmeta = int(self.req.form.get('skipmeta', 1))
         if skipmeta:
             url = self.build_url('data/schema.png')
         else:
@@ -72,7 +72,7 @@
             continue
         etype = eschema.type
         label = display_name(req, etype, 'plural')
-        view = self.vreg.select_view('list', req, req.etype_rset(etype))
+        view = self.vreg.select('views', 'list', req, req.etype_rset(etype))
         url = view.url()
         etypelink = u'&nbsp;<a href="%s">%s</a>' % (xml_escape(url), label)
         yield (label, etypelink, self.add_entity_link(eschema, req))
--- a/goa/db.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/db.py	Fri Aug 07 12:20:50 2009 +0200
@@ -274,8 +274,8 @@
 
     def view(self, vid, __registry='views', **kwargs):
         """shortcut to apply a view on this entity"""
-        return self.vreg.render(__registry, vid, self.req, rset=self.rset,
-                                row=self.row, col=self.col, **kwargs)
+        return self.vreg[__registry]render(vid, self.req, rset=self.rset,
+                                           row=self.row, col=self.col, **kwargs)
 
     @classmethod
     def _rest_attr_info(cls):
--- a/goa/dbinit.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/dbinit.py	Fri Aug 07 12:20:50 2009 +0200
@@ -20,7 +20,7 @@
         try:
             group = Get(key)
         except datastore_errors.EntityNotFoundError:
-            raise Exception('can\'t find required group %s, is your application '
+            raise Exception('can\'t find required group %s, is your instance '
                             'correctly initialized (eg did you run the '
                             'initialization script) ?' % groupname)
         _GROUP_CACHE[groupname] = group
@@ -86,14 +86,13 @@
 def init_persistent_schema(ssession, schema):
     execute = ssession.unsafe_execute
     rql = ('INSERT CWEType X: X name %(name)s, X description %(descr)s,'
-           'X final FALSE, X meta %(meta)s')
+           'X final FALSE')
     eschema = schema.eschema('CWEType')
-    execute(rql, {'name': u'CWEType', 'descr': unicode(eschema.description),
-                  'meta': eschema.meta})
+    execute(rql, {'name': u'CWEType', 'descr': unicode(eschema.description)})
     for eschema in schema.entities():
         if eschema.is_final() or eschema == 'CWEType':
             continue
-        execute(rql, {'name': unicode(eschema), 'meta': eschema.meta,
+        execute(rql, {'name': unicode(eschema),
                       'descr': unicode(eschema.description)})
 
 def insert_versions(ssession, config):
--- a/goa/dbmyams.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/dbmyams.py	Fri Aug 07 12:20:50 2009 +0200
@@ -167,7 +167,7 @@
     SCHEMAS_LIB_DIRECTORY = join(CW_SOFTWARE_ROOT, 'schemas')
 
 def load_schema(config, schemaclasses=None, extrahook=None):
-    """high level method to load all the schema for a lax application"""
+    """high level method to load all the schema for a lax instance"""
     # IMPORTANT NOTE: dbmodel schemas must be imported **BEFORE**
     # the loader is instantiated because this is where the dbmodels
     # are registered in the yams schema
--- a/goa/gaesource.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/gaesource.py	Fri Aug 07 12:20:50 2009 +0200
@@ -155,7 +155,7 @@
         return rqlst
 
     def set_schema(self, schema):
-        """set the application'schema"""
+        """set the instance'schema"""
         self.interpreter = RQLInterpreter(schema)
         self.schema = schema
         if 'CWUser' in schema and not self.repo.config['use-google-auth']:
--- a/goa/goaconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/goaconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,8 +17,8 @@
 from cubicweb.goa.dbmyams import load_schema
 
 UNSUPPORTED_OPTIONS = set(('connections-pool-size',
-                           'pyro-port', 'pyro-id', 'pyro-application-id',
-                           'pyro-ns-host', 'pyro-ns-port', 'pyro-ns-group',
+                           'pyro-host', 'pyro-id', 'pyro-instance-id',
+                           'pyro-ns-host', 'pyro-ns-group',
                            'https-url', 'host', 'pid-file', 'uid', 'base-url', 'log-file',
                            'smtp-host', 'smtp-port',
                            'embed-allowed',
@@ -30,41 +30,41 @@
 # * check auth-mode=http + fix doc (eg require use-google-auth = False)
 
 class GAEConfiguration(ServerConfiguration, WebConfiguration):
-    """repository and web application in the same twisted process"""
+    """repository and web instance in Google AppEngine environment"""
     name = 'app'
     repo_method = 'inmemory'
     options = merge_options((
         ('included-cubes',
          {'type' : 'csv',
           'default': [],
-          'help': 'list of db model based cubes used by the application.',
+          'help': 'list of db model based cubes used by the instance.',
           'group': 'main', 'inputlevel': 1,
           }),
         ('included-yams-cubes',
          {'type' : 'csv',
           'default': [],
-          'help': 'list of yams based cubes used by the application.',
+          'help': 'list of yams based cubes used by the instance.',
           'group': 'main', 'inputlevel': 1,
           }),
         ('use-google-auth',
          {'type' : 'yn',
           'default': True,
-          'help': 'does this application rely on google authentication service or not.',
+          'help': 'does this instance rely on google authentication service or not.',
           'group': 'main', 'inputlevel': 1,
           }),
         ('schema-type',
          {'type' : 'choice', 'choices': ('yams', 'dbmodel'),
           'default': 'yams',
-          'help': 'does this application is defining its schema using yams or db model.',
+          'help': 'does this instance is defining its schema using yams or db model.',
           'group': 'main', 'inputlevel': 1,
           }),
         # overriden options
         ('query-log-file',
          {'type' : 'string',
           'default': None,
-          'help': 'web application query log file: DON\'T SET A VALUE HERE WHEN '
-          'UPLOADING YOUR APPLICATION. This should only be used to analyse '
-          'queries issued by your application in the development environment.',
+          'help': 'web instance query log file: DON\'T SET A VALUE HERE WHEN '
+          'UPLOADING YOUR INSTANCE. This should only be used to analyse '
+          'queries issued by your instance in the development environment.',
           'group': 'main', 'inputlevel': 2,
           }),
         ('anonymous-user',
@@ -81,12 +81,12 @@
     options = [(optname, optdict) for optname, optdict in options
                if not optname in UNSUPPORTED_OPTIONS]
 
-    cubicweb_vobject_path = WebConfiguration.cubicweb_vobject_path | ServerConfiguration.cubicweb_vobject_path
-    cubicweb_vobject_path = list(cubicweb_vobject_path) + ['goa/appobjects']
-    cube_vobject_path = WebConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path
+    cubicweb_appobject_path = WebConfiguration.cubicweb_appobject_path | ServerConfiguration.cubicweb_appobject_path
+    cubicweb_appobject_path = list(cubicweb_appobject_path) + ['goa/appobjects']
+    cube_appobject_path = WebConfiguration.cube_appobject_path | ServerConfiguration.cube_appobject_path
 
     # use file system schema
-    bootstrap_schema = read_application_schema = False
+    bootstrap_schema = read_instance_schema = False
     # schema is not persistent, don't load schema hooks (unavailable)
     schema_hooks = False
     # no user workflow for now
@@ -130,7 +130,7 @@
         return self._cubes
 
     def vc_config(self):
-        """return CubicWeb's engine and application's cube versions number"""
+        """return CubicWeb's engine and instance's cube versions number"""
         return {}
 
     # overriden from cubicweb web configuration
--- a/goa/goactl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/goactl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -172,13 +172,13 @@
 
 
 class NewGoogleAppCommand(Command):
-    """Create a new google appengine application.
+    """Create a new google appengine instance.
 
-    <application directory>
-      the path to the appengine application directory
+    <instance directory>
+      the path to the appengine instance directory
     """
     name = 'newgapp'
-    arguments = '<application directory>'
+    arguments = '<instance directory>'
 
     def run(self, args):
         if len(args) != 1:
@@ -187,7 +187,7 @@
         appldir = normpath(abspath(appldir))
         appid = basename(appldir)
         context = {'appname': appid}
-        # goa application'skeleton
+        # goa instance'skeleton
         copy_skeleton(join(CW_SOFTWARE_ROOT, 'goa', 'skel'),
                       appldir, context, askconfirm=True)
         # cubicweb core dependancies
--- a/goa/goavreg.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/goavreg.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,7 +11,7 @@
 from os.path import join, isdir
 
 from cubicweb import CW_SOFTWARE_ROOT
-from cubicweb.cwvreg import CubicWebRegistry
+from cubicweb.cwvreg import CubicWebVRegistry
 
 
 def _pkg_name(cube, module):
@@ -19,7 +19,7 @@
         return module
     return 'cubes.%s.%s' % (cube, module)
 
-class GAERegistry(CubicWebRegistry):
+class GAEVRegistry(CubicWebVRegistry):
 
     def set_schema(self, schema):
         """disable reload hooks of cubicweb registry set_schema method"""
@@ -37,7 +37,7 @@
                             'cubicweb.goa.appobjects')
         for cube in reversed(self.config.cubes()):
             self.load_cube(cube)
-        self.load_application(applroot)
+        self.load_instance(applroot)
 
     def load_directory(self, directory, cube, skip=()):
         for filename in listdir(directory):
@@ -49,7 +49,7 @@
                         cube in self.config['included-cubes'],
                         cube)
 
-    def load_application(self, applroot):
+    def load_instance(self, applroot):
         self._auto_load(applroot, self.config['schema-type'] == 'dbmodel')
 
     def _import(self, modname):
@@ -59,7 +59,7 @@
         self.load_module(obj)
 
     def _auto_load(self, path, loadschema, cube=None):
-        vobjpath = self.config.cube_vobject_path
+        vobjpath = self.config.cube_appobject_path
         for filename in listdir(path):
             if filename[-3:] == '.py' and filename[:-3] in vobjpath:
                 self._import(_pkg_name(cube, filename[:-3]))
--- a/goa/overrides/toolsutils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/overrides/toolsutils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,7 +17,7 @@
     return result
 
 def read_config(config_file):
-    """read the application configuration from a file and return it as a
+    """read the instance configuration from a file and return it as a
     dictionnary
 
     :type config_file: str
--- a/goa/skel/loader.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/skel/loader.py	Fri Aug 07 12:20:50 2009 +0200
@@ -12,11 +12,11 @@
     from cubicweb.goa.goaconfig import GAEConfiguration
     from cubicweb.goa.dbinit import create_user, create_groups
 
-    # compute application's root directory
+    # compute instance's root directory
     APPLROOT = dirname(abspath(__file__))
     # apply monkey patches first
     goa.do_monkey_patch()
-    # get application's configuration (will be loaded from app.conf file)
+    # get instance's configuration (will be loaded from app.conf file)
     GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
     config = GAEConfiguration('toto', APPLROOT)
     # create default groups
--- a/goa/skel/main.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/skel/main.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-"""module defining the root handler for a lax application. You should not have
+"""module defining the root handler for a lax instance. You should not have
 to change anything here.
 
 :organization: Logilab
@@ -8,7 +8,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-# compute application's root directory
+# compute instance's root directory
 from os.path import dirname, abspath
 APPLROOT = dirname(abspath(__file__))
 
@@ -16,26 +16,26 @@
 from cubicweb import goa
 goa.do_monkey_patch()
 
-# get application's configuration (will be loaded from app.conf file)
+# get instance's configuration (will be loaded from app.conf file)
 from cubicweb.goa.goaconfig import GAEConfiguration
 GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
 config = GAEConfiguration('toto', APPLROOT)
 
 # dynamic objects registry
-from cubicweb.goa.goavreg import GAERegistry
-vreg = GAERegistry(config, debug=goa.MODE == 'dev')
+from cubicweb.goa.goavreg import GAEVregistry
+vreg = GAEVregistry(config, debug=goa.MODE == 'dev')
 
 # trigger automatic classes registration (metaclass magic), should be done
 # before schema loading
 import custom
 
-# load application'schema
+# load instance'schema
 vreg.schema = config.load_schema()
 
 # load dynamic objects
 vreg.load(APPLROOT)
 
-# call the postinit so custom get a chance to do application specific stuff
+# call the postinit so custom get a chance to do instance specific stuff
 custom.postinit(vreg)
 
 from cubicweb.wsgi.handler import CubicWebWSGIApplication
--- a/goa/skel/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/skel/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,6 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-from cubicweb.schema import format_constraint
 
 class Blog(EntityType):
     title = String(maxsize=50, required=True)
@@ -14,8 +13,6 @@
 class BlogEntry(EntityType):
     title = String(maxsize=100, required=True)
     publish_date = Date(default='TODAY')
-    text_format = String(meta=True, internationalizable=True, maxsize=50,
-                         default='text/rest', constraints=[format_constraint])
-    text = String(fulltextindexed=True)
+    text = RichString(fulltextindexed=True)
     category = String(vocabulary=('important','business'))
     entry_of = SubjectRelation('Blog', cardinality='?*')
--- a/goa/test/unittest_editcontroller.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/test/unittest_editcontroller.py	Fri Aug 07 12:20:50 2009 +0200
@@ -37,8 +37,7 @@
         self.ctrl = self.get_ctrl(self.req)
 
     def get_ctrl(self, req):
-        return self.vreg.select(self.vreg.registry_objects('controllers', 'edit'),
-                                req=req, appli=self)
+        return self.vreg.select('controllers', 'edit', req=req, appli=self)
 
     def publish(self, req):
         assert req is self.ctrl.req
--- a/goa/test/unittest_views.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/test/unittest_views.py	Fri Aug 07 12:20:50 2009 +0200
@@ -46,12 +46,12 @@
         self.blog.put(self.req)
 
     def test_hcal(self):
-        self.vreg.render('views', 'hcal', self.req, rset=self.blog.rset)
+        self.vreg['views'].render('hcal', self.req, rset=self.blog.rset)
 
     def test_django_index(self):
-        self.vreg.render('views', 'index', self.req, rset=None)
+        self.vreg'views'].render('index', self.req, rset=None)
 
-for vid in ('primary', 'secondary', 'oneline', 'incontext', 'outofcontext', 'text'):
+for vid in ('primary', 'oneline', 'incontext', 'outofcontext', 'text'):
     setattr(SomeViewsTC, 'test_%s'%vid, lambda self, vid=vid: self.blog.view(vid))
 
 if __name__ == '__main__':
--- a/goa/testlib.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/testlib.py	Fri Aug 07 12:20:50 2009 +0200
@@ -42,7 +42,7 @@
 
 
 from cubicweb.devtools.fake import FakeRequest
-from cubicweb.goa.goavreg import GAERegistry
+from cubicweb.goa.goavreg import GAEVregistry
 from cubicweb.goa.goaconfig import GAEConfiguration
 from cubicweb.goa.dbinit import (create_user, create_groups, fix_entities,
                               init_persistent_schema, insert_versions)
@@ -115,7 +115,7 @@
         self.config.init_log(logging.CRITICAL)
         self.schema = self.config.load_schema(self.MODEL_CLASSES,
                                               self.load_schema_hook)
-        self.vreg = GAERegistry(self.config)
+        self.vreg = GAEVregistry(self.config)
         self.vreg.schema = self.schema
         self.vreg.load_module(db)
         from cubicweb.goa.appobjects import sessions
@@ -131,7 +131,7 @@
                 self.vreg.load_module(module)
         for cls in self.MODEL_CLASSES:
             self.vreg.load_object(cls)
-        self.session_manager = self.vreg.select_component('sessionmanager')
+        self.session_manager = self.vreg.select('components', 'sessionmanager')
         if need_ds_init:
             # create default groups and create entities according to the schema
             create_groups()
--- a/goa/tools/generate_schema_img.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/tools/generate_schema_img.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,6 +8,7 @@
 import sys
 from os.path import dirname, abspath, join
 from yams import schema2dot
+from cubicweb.web.views.schema import SKIP_TYPES
 
 APPLROOT = abspath(join(dirname(abspath(__file__)), '..'))
 
@@ -22,9 +23,8 @@
 skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of')
 path = join(APPLROOT, 'data', 'schema.png')
 schema2dot.schema2dot(schema, path, #size=size,
-                      skiprels=skip_rels, skipmeta=True)
+                      skiptypes=SKIP_TYPES)
 print 'generated', path
 path = join(APPLROOT, 'data', 'metaschema.png')
-schema2dot.schema2dot(schema, path, #size=size,
-                      skiprels=skip_rels, skipmeta=False)
+schema2dot.schema2dot(schema, path)
 print 'generated', path
--- a/goa/tools/laxctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/goa/tools/laxctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -19,6 +19,8 @@
 from logilab.common.clcommands import Command, register_commands, main_run
 
 from cubicweb.common.uilib import remove_html_tags
+from cubicweb.web.views.schema import SKIP_TYPES
+
 APPLROOT = osp.abspath(osp.join(osp.dirname(osp.abspath(__file__)), '..'))
 
 
@@ -26,11 +28,11 @@
     # apply monkey patches first
     from cubicweb.goa import do_monkey_patch
     do_monkey_patch()
-    from cubicweb.goa.goavreg import GAERegistry
+    from cubicweb.goa.goavreg import GAEVregistry
     from cubicweb.goa.goaconfig import GAEConfiguration
     #WebConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
     config = GAEConfiguration('toto', applroot)
-    vreg = GAERegistry(config)
+    vreg = GAEVregistry(config)
     vreg.set_schema(config.load_schema())
     return vreg
 
@@ -57,19 +59,17 @@
         assert not args, 'no argument expected'
         from yams import schema2dot
         schema = self.vreg.schema
-        skip_rels = ('owned_by', 'created_by', 'identity', 'is', 'is_instance_of')
         path = osp.join(APPLROOT, 'data', 'schema.png')
         schema2dot.schema2dot(schema, path, #size=size,
-                              skiprels=skip_rels, skipmeta=True)
+                              skiptypes=SKIP_TYPES)
         print 'generated', path
         path = osp.join(APPLROOT, 'data', 'metaschema.png')
-        schema2dot.schema2dot(schema, path, #size=size,
-                              skiprels=skip_rels, skipmeta=False)
+        schema2dot.schema2dot(schema, path)
         print 'generated', path
 
 
 class PopulateDataDirCommand(LaxCommand):
-    """populate application's data directory according to used cubes"""
+    """populate instance's data directory according to used cubes"""
     name = 'populatedata'
 
     def _run(self, args):
@@ -118,7 +118,7 @@
 
 
 class URLCommand(LaxCommand):
-    """abstract class for commands doing stuff by accessing the web application
+    """abstract class for commands doing stuff by accessing the web instance
     """
     min_args = max_args = 1
     arguments = '<site url>'
--- a/hercule.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/hercule.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-"""RQL client for cubicweb, connecting to application using pyro
+"""RQL client for cubicweb, connecting to instance using pyro
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -79,7 +79,7 @@
         'debug' :        "Others",
         })
 
-    def __init__(self, application=None, user=None, password=None,
+    def __init__(self, instance=None, user=None, password=None,
                  host=None, debug=0):
         CLIHelper.__init__(self, os.path.join(os.environ["HOME"], ".erqlhist"))
         self.cnx = None
@@ -92,12 +92,12 @@
         self.autocommit = False
         self._last_result = None
         self._previous_lines = []
-        if application is not None:
-            self.do_connect(application, user, password, host)
+        if instance is not None:
+            self.do_connect(instance, user, password, host)
         self.do_debug(debug)
 
-    def do_connect(self, application, user=None, password=None, host=None):
-        """connect to an cubicweb application"""
+    def do_connect(self, instance, user=None, password=None, host=None):
+        """connect to an cubicweb instance"""
         from cubicweb.dbapi import connect
         if user is None:
             user = raw_input('login: ')
@@ -107,16 +107,16 @@
         if self.cnx is not None:
             self.cnx.close()
         self.cnx = connect(login=user, password=password, host=host,
-                           database=application)
+                           database=instance)
         self.schema = self.cnx.get_schema()
         self.cursor = self.cnx.cursor()
         # add entities types to the completion commands
         self._completer.list = (self.commands.keys() +
                                 self.schema.entities() + ['Any'])
-        print _('You are now connected to %s') % application
+        print _('You are now connected to %s') % instance
 
 
-    help_do_connect = ('connect', "connect <application> [<user> [<password> [<host>]]]",
+    help_do_connect = ('connect', "connect <instance> [<user> [<password> [<host>]]]",
                        _(do_connect.__doc__))
 
     def do_debug(self, debug=1):
@@ -142,9 +142,9 @@
     help_do_description = ('description', "description", _(do_description.__doc__))
 
     def do_schema(self, name=None):
-        """display information about the application schema """
+        """display information about the instance schema """
         if self.cnx is None:
-            print _('You are not connected to an application !')
+            print _('You are not connected to an instance !')
             return
         done = None
         if name is None:
@@ -189,7 +189,7 @@
         else, stores the query line and waits for the suite
         """
         if self.cnx is None:
-            print _('You are not connected to an application !')
+            print _('You are not connected to an instance !')
             return
         # append line to buffer
         self._previous_lines.append(stripped_line)
@@ -232,11 +232,11 @@
 class CubicWebClientCommand(Command):
     """A command line querier for CubicWeb, using the Relation Query Language.
 
-    <application>
-      identifier of the application to connect to
+    <instance>
+      identifier of the instance to connect to
     """
     name = 'client'
-    arguments = '<application>'
+    arguments = '<instance>'
     options = CONNECT_OPTIONS + (
         ("verbose",
          {'short': 'v', 'type' : 'int', 'metavar': '<level>',
--- a/i18n/en.po	Fri Aug 07 12:20:37 2009 +0200
+++ b/i18n/en.po	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,7 @@
 msgstr ""
 "Project-Id-Version: 2.0\n"
 "POT-Creation-Date: 2006-01-12 17:35+CET\n"
-"PO-Revision-Date: 2008-12-23 18:43+0100\n"
+"PO-Revision-Date: 2009-08-05 08:39+0200\n"
 "Last-Translator: Sylvain Thenault <sylvain.thenault@logilab.fr>\n"
 "Language-Team: English <devel@logilab.fr.org>\n"
 "MIME-Version: 1.0\n"
@@ -118,6 +118,9 @@
 msgid "%s software version of the database"
 msgstr ""
 
+msgid "(UNEXISTANT EID)"
+msgstr ""
+
 msgid "**"
 msgstr "0..n 0..n"
 
@@ -218,10 +221,10 @@
 msgstr "Attributes"
 
 msgid "CWCache"
-msgstr ""
+msgstr "CubicWeb Cache"
 
 msgid "CWCache_plural"
-msgstr ""
+msgstr "CubicWeb Caches"
 
 msgid "CWConstraint"
 msgstr "Constraint"
@@ -317,6 +320,12 @@
 msgid "Environment"
 msgstr ""
 
+msgid "ExternalUri"
+msgstr "External Uri"
+
+msgid "ExternalUri_plural"
+msgstr "External Uris"
+
 msgid "Float"
 msgstr "Float"
 
@@ -377,6 +386,9 @@
 msgid "New EmailAddress"
 msgstr "New email address"
 
+msgid "New ExternalUri"
+msgstr ""
+
 msgid "New RQLExpression"
 msgstr "New RQL expression"
 
@@ -519,6 +531,9 @@
 msgid "This EmailAddress"
 msgstr "This email address"
 
+msgid "This ExternalUri"
+msgstr ""
+
 msgid "This RQLExpression"
 msgstr "This RQL expression"
 
@@ -565,7 +580,7 @@
 msgid "Workflow history"
 msgstr ""
 
-msgid "You are not connected to an application !"
+msgid "You are not connected to an instance !"
 msgstr ""
 
 #, python-format
@@ -607,10 +622,13 @@
 "represents the current entity and the current user"
 msgstr ""
 
+msgid "a URI representing an object in external data store"
+msgstr ""
+
 msgid ""
 "a simple cache entity characterized by a name and a validity date. The "
 "target application is responsible for updating timestamp when necessary to "
-"invalidate the cache (typically in hooks). Also, checkout the AppRsetObject."
+"invalidate the cache (typically in hooks). Also, checkout the AppObject."
 "get_cache() method."
 msgstr ""
 
@@ -654,7 +672,7 @@
 msgstr ""
 
 msgid "actions_download_as_owl"
-msgstr ""
+msgstr "download as owl"
 
 msgid "actions_download_as_owl_description"
 msgstr ""
@@ -690,7 +708,7 @@
 msgstr ""
 
 msgid "actions_managepermission"
-msgstr ""
+msgstr "manage permissions"
 
 msgid "actions_managepermission_description"
 msgstr ""
@@ -714,7 +732,7 @@
 msgstr ""
 
 msgid "actions_prefs"
-msgstr ""
+msgstr "preferences"
 
 msgid "actions_prefs_description"
 msgstr ""
@@ -743,6 +761,12 @@
 msgid "actions_siteconfig_description"
 msgstr ""
 
+msgid "actions_siteinfo"
+msgstr "site information"
+
+msgid "actions_siteinfo_description"
+msgstr ""
+
 msgid "actions_view"
 msgstr "view"
 
@@ -837,7 +861,7 @@
 msgstr "add an attribute"
 
 msgid "add a CWCache"
-msgstr ""
+msgstr "add a cubicweb cache"
 
 msgid "add a CWConstraint"
 msgstr "add a constraint"
@@ -869,6 +893,9 @@
 msgid "add a EmailAddress"
 msgstr "add an email address"
 
+msgid "add a ExternalUri"
+msgstr "and an external uri"
+
 msgid "add a RQLExpression"
 msgstr "add a rql expression"
 
@@ -962,9 +989,6 @@
 msgid "application entities"
 msgstr ""
 
-msgid "application schema"
-msgstr ""
-
 msgid "april"
 msgstr ""
 
@@ -1104,6 +1128,9 @@
 msgid "calendar (year)"
 msgstr ""
 
+msgid "can not resolve entity types:"
+msgstr ""
+
 #, python-format
 msgid "can't change the %s attribute"
 msgstr ""
@@ -1464,6 +1491,9 @@
 msgid "cwetype-workflow"
 msgstr "workflow"
 
+msgid "cwuri"
+msgstr ""
+
 msgid "data directory url"
 msgstr ""
 
@@ -1496,15 +1526,15 @@
 
 msgid ""
 "define a final relation: link a final relation type from a non final entity "
-"to a final entity type. used to build the application schema"
+"to a final entity type. used to build the instance schema"
 msgstr ""
 
 msgid ""
 "define a non final relation: link a non final relation type from a non final "
-"entity to a non final entity type. used to build the application schema"
-msgstr ""
-
-msgid "define a relation type, used to build the application schema"
+"entity to a non final entity type. used to build the instance schema"
+msgstr ""
+
+msgid "define a relation type, used to build the instance schema"
 msgstr ""
 
 msgid "define a rql expression used to define permissions"
@@ -1516,7 +1546,7 @@
 msgid "define a schema constraint type"
 msgstr ""
 
-msgid "define an entity type, used to build the application schema"
+msgid "define an entity type, used to build the instance schema"
 msgstr ""
 
 msgid ""
@@ -1612,6 +1642,9 @@
 msgid "download icon"
 msgstr ""
 
+msgid "download image"
+msgstr ""
+
 msgid "download schema as owl"
 msgstr ""
 
@@ -1791,6 +1824,9 @@
 msgid "from_entity_object"
 msgstr "subjet relation"
 
+msgid "from_interval_start"
+msgstr "from"
+
 msgid "from_state"
 msgstr "from state"
 
@@ -1812,13 +1848,19 @@
 msgid "generic relation to link one entity to another"
 msgstr ""
 
+msgid ""
+"generic relation to specify that an external entity represent the same "
+"object as a local one: http://www.w3.org/TR/owl-ref/#sameAs-def NOTE: You'll "
+"have to explicitly declare which entity types can have a same_as relation"
+msgstr ""
+
 msgid "go back to the index page"
 msgstr ""
 
 msgid "granted to groups"
 msgstr ""
 
-msgid "graphical representation of the application'schema"
+msgid "graphical representation of the instance'schema"
 msgstr ""
 
 #, python-format
@@ -1971,6 +2013,9 @@
 "is created"
 msgstr ""
 
+msgid "info"
+msgstr ""
+
 #, python-format
 msgid "initial estimation %s"
 msgstr ""
@@ -1987,6 +2032,12 @@
 msgid "inlined"
 msgstr ""
 
+msgid "instance schema"
+msgstr ""
+
+msgid "internal entity uri"
+msgstr ""
+
 msgid "internationalizable"
 msgstr ""
 
@@ -2000,12 +2051,6 @@
 msgid "is"
 msgstr ""
 
-msgid "is it an application entity type or not ?"
-msgstr ""
-
-msgid "is it an application relation type or not ?"
-msgstr ""
-
 msgid ""
 "is the subject/object entity of the relation composed of the other ? This "
 "implies that when the composite is deleted, composants are also deleted."
@@ -2156,9 +2201,6 @@
 msgid "may"
 msgstr ""
 
-msgid "meta"
-msgstr "meta relation"
-
 msgid "milestone"
 msgstr ""
 
@@ -2237,9 +2279,6 @@
 msgid "no associated permissions"
 msgstr ""
 
-msgid "no possible transition"
-msgstr ""
-
 msgid "no related project"
 msgstr ""
 
@@ -2424,7 +2463,7 @@
 msgstr "remove this attribute"
 
 msgid "remove this CWCache"
-msgstr ""
+msgstr "remove this cubicweb cache"
 
 msgid "remove this CWConstraint"
 msgstr "remove this constraint"
@@ -2456,6 +2495,9 @@
 msgid "remove this EmailAddress"
 msgstr "remove this email address"
 
+msgid "remove this ExternalUri"
+msgstr ""
+
 msgid "remove this RQLExpression"
 msgstr "remove this RQL expression"
 
@@ -2517,6 +2559,9 @@
 msgid "rss"
 msgstr ""
 
+msgid "same_as"
+msgstr ""
+
 msgid "sample format"
 msgstr ""
 
@@ -2641,6 +2686,9 @@
 msgid "sorry, the server is unable to handle this query"
 msgstr ""
 
+msgid "sparql xml"
+msgstr ""
+
 msgid "specializes"
 msgstr ""
 
@@ -2714,6 +2762,9 @@
 msgid "text/rest"
 msgstr "ReST text"
 
+msgid "the URI of the object"
+msgstr ""
+
 msgid "the prefered email"
 msgstr ""
 
@@ -2764,6 +2815,9 @@
 msgid "to_entity_object"
 msgstr "object relations"
 
+msgid "to_interval_end"
+msgstr "to"
+
 msgid "to_state"
 msgstr "to state"
 
@@ -2794,6 +2848,9 @@
 msgid "type"
 msgstr ""
 
+msgid "type here a sparql query"
+msgstr ""
+
 msgid "ui"
 msgstr ""
 
@@ -2842,6 +2899,9 @@
 msgid "unknown property key"
 msgstr ""
 
+msgid "unknown vocabulary:"
+msgstr ""
+
 msgid "up"
 msgstr ""
 
@@ -2864,6 +2924,9 @@
 msgid "updated %(etype)s #%(eid)s (%(title)s)"
 msgstr ""
 
+msgid "uri"
+msgstr ""
+
 msgid "use template languages"
 msgstr ""
 
@@ -2940,21 +3003,24 @@
 msgid "view detail for this entity"
 msgstr ""
 
+msgid "view history"
+msgstr ""
+
 msgid "view workflow"
 msgstr ""
 
 msgid "view_index"
 msgstr "index"
 
-msgid "view_manage"
-msgstr "site management"
-
 msgid "views"
 msgstr ""
 
 msgid "visible"
 msgstr ""
 
+msgid "we are not yet ready to handle this query"
+msgstr ""
+
 msgid "wednesday"
 msgstr ""
 
@@ -3026,6 +3092,9 @@
 #~ msgid "hide meta-data"
 #~ msgstr "hide meta entities and relations"
 
+#~ msgid "meta"
+#~ msgstr "meta relation"
+
 #~ msgid "planned_delivery"
 #~ msgstr "planned delivery"
 
@@ -3035,5 +3104,8 @@
 #~ msgid "show meta-data"
 #~ msgstr "show the complete schema"
 
+#~ msgid "view_manage"
+#~ msgstr "site management"
+
 #~ msgid "wikiid"
 #~ msgstr "wiki identifier"
--- a/i18n/entities.pot	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-msgid "__msg state changed"
-msgstr ""
-
-msgid "managers"
-msgstr ""
-
-msgid "users"
-msgstr ""
-
-msgid "guests"
-msgstr ""
-
-msgid "owners"
-msgstr ""
-
-msgid "read_perm"
-msgstr ""
-
-msgid "add_perm"
-msgstr ""
-
-msgid "update_perm"
-msgstr ""
-
-msgid "delete_perm"
-msgstr ""
--- a/i18n/es.po	Fri Aug 07 12:20:37 2009 +0200
+++ b/i18n/es.po	Fri Aug 07 12:20:50 2009 +0200
@@ -123,6 +123,9 @@
 msgid "%s software version of the database"
 msgstr "versión sistema de la base para %s"
 
+msgid "(UNEXISTANT EID)"
+msgstr ""
+
 msgid "**"
 msgstr "0..n 0..n"
 
@@ -164,8 +167,12 @@
 "<div>This schema of the data model <em>excludes</em> the meta-data, but you "
 "can also display a <a href=\"%s\">complete schema with meta-data</a>.</div>"
 msgstr ""
-"<div>Este esquema del modelo de datos <em>no incluye</em> los meta-datos, pero "
-"se puede ver a un <a href=\"%s\">modelo completo con meta-datos</a>.</div>"
+"<div>Este esquema del modelo de datos <em>no incluye</em> los meta-datos, "
+"pero se puede ver a un <a href=\"%s\">modelo completo con meta-datos</a>.</"
+"div>"
+
+msgid "<no value>"
+msgstr ""
 
 msgid "?*"
 msgstr "0..1 0..n"
@@ -321,6 +328,12 @@
 msgid "Environment"
 msgstr "Ambiente"
 
+msgid "ExternalUri"
+msgstr ""
+
+msgid "ExternalUri_plural"
+msgstr ""
+
 msgid "Float"
 msgstr "Número flotante"
 
@@ -381,6 +394,9 @@
 msgid "New EmailAddress"
 msgstr "Agregar Email"
 
+msgid "New ExternalUri"
+msgstr ""
+
 msgid "New RQLExpression"
 msgstr "Agregar expresión rql"
 
@@ -523,6 +539,9 @@
 msgid "This EmailAddress"
 msgstr "Esta dirección electrónica"
 
+msgid "This ExternalUri"
+msgstr ""
+
 msgid "This RQLExpression"
 msgstr "Esta expresión RQL"
 
@@ -569,8 +588,8 @@
 msgid "Workflow history"
 msgstr "Histórico del Workflow"
 
-msgid "You are not connected to an application !"
-msgstr "Usted no esta conectado a una aplicación"
+msgid "You are not connected to an instance !"
+msgstr ""
 
 #, python-format
 msgid "You are now connected to %s"
@@ -625,16 +644,15 @@
 "pueda ser realizada. Esta expresión puede utilizar las variables X y U que "
 "representan respectivamente la entidad en transición y el usuario actual. "
 
+msgid "a URI representing an object in external data store"
+msgstr ""
+
 msgid ""
 "a simple cache entity characterized by a name and a validity date. The "
 "target application is responsible for updating timestamp when necessary to "
-"invalidate the cache (typically in hooks). Also, checkout the AppRsetObject."
+"invalidate the cache (typically in hooks). Also, checkout the AppObject."
 "get_cache() method."
 msgstr ""
-"una entidad cache simple caracterizada por un nombre y una fecha correcta. "
-"El sistema objetivo es responsable de actualizar timestamp cuand se "
-"necesario para invalidar el cache (usualmente en hooks).Recomendamos revisar "
-"el METODO  AppRsetObject.get_cache()."
 
 msgid "about this site"
 msgstr "Sobre este Espacio"
@@ -765,6 +783,12 @@
 msgid "actions_siteconfig_description"
 msgstr ""
 
+msgid "actions_siteinfo"
+msgstr ""
+
+msgid "actions_siteinfo_description"
+msgstr ""
+
 msgid "actions_view"
 msgstr "Ver"
 
@@ -891,6 +915,9 @@
 msgid "add a EmailAddress"
 msgstr "Agregar un email"
 
+msgid "add a ExternalUri"
+msgstr ""
+
 msgid "add a RQLExpression"
 msgstr "Agregar una expresión rql"
 
@@ -986,9 +1013,6 @@
 msgid "application entities"
 msgstr "Entidades de la aplicación"
 
-msgid "application schema"
-msgstr "Esquema de la aplicación"
-
 msgid "april"
 msgstr "Abril"
 
@@ -1131,6 +1155,9 @@
 msgid "calendar (year)"
 msgstr "calendario (anual)"
 
+msgid "can not resolve entity types:"
+msgstr ""
+
 #, python-format
 msgid "can't change the %s attribute"
 msgstr "no puede modificar el atributo %s"
@@ -1179,6 +1206,9 @@
 msgid "click on the box to cancel the deletion"
 msgstr "Seleccione la zona de edición para cancelar la eliminación"
 
+msgid "click to edit this field"
+msgstr ""
+
 msgid "comment"
 msgstr "Comentario"
 
@@ -1517,6 +1547,9 @@
 msgid "cwetype-workflow"
 msgstr "Workflow"
 
+msgid "cwuri"
+msgstr ""
+
 msgid "data directory url"
 msgstr "Url del repertorio de datos"
 
@@ -1549,23 +1582,16 @@
 
 msgid ""
 "define a final relation: link a final relation type from a non final entity "
-"to a final entity type. used to build the application schema"
+"to a final entity type. used to build the instance schema"
 msgstr ""
-"Define una relación no final: liga un tipo de relación no final desde una "
-"entidad hacia un tipo de entidad no final. Utilizada para construir el "
-"esquema de la aplicación"
 
 msgid ""
 "define a non final relation: link a non final relation type from a non final "
-"entity to a non final entity type. used to build the application schema"
+"entity to a non final entity type. used to build the instance schema"
 msgstr ""
-"Define una relación 'atributo', utilizada para construir el esquema dela "
-"aplicación"
-
-msgid "define a relation type, used to build the application schema"
+
+msgid "define a relation type, used to build the instance schema"
 msgstr ""
-"Define un tipo de relación, utilizada para construir el esquema de la "
-"aplicación"
 
 msgid "define a rql expression used to define permissions"
 msgstr "Expresión RQL utilizada para definir los derechos de acceso"
@@ -1576,10 +1602,8 @@
 msgid "define a schema constraint type"
 msgstr "Define un tipo de condición de esquema"
 
-msgid "define an entity type, used to build the application schema"
+msgid "define an entity type, used to build the instance schema"
 msgstr ""
-"Define un tipo de entidad, utilizada para construir el esquema de la "
-"aplicación"
 
 msgid ""
 "defines what's the property is applied for. You must select this first to be "
@@ -1680,6 +1704,9 @@
 msgid "download icon"
 msgstr "ícono de descarga"
 
+msgid "download image"
+msgstr ""
+
 msgid "download schema as owl"
 msgstr "Descargar esquema en OWL"
 
@@ -1800,12 +1827,6 @@
 msgid "facets_cwfinal-facet_description"
 msgstr "faceta para las entidades \"finales\""
 
-msgid "facets_cwmeta-facet"
-msgstr "faceta \"meta\""
-
-msgid "facets_cwmeta-facet_description"
-msgstr "faceta para las entidades \"meta\""
-
 msgid "facets_etype-facet"
 msgstr "faceta \"es de tipo\""
 
@@ -1870,6 +1891,9 @@
 msgid "from_entity_object"
 msgstr "Relación sujeto"
 
+msgid "from_interval_start"
+msgstr ""
+
 msgid "from_state"
 msgstr "De el estado"
 
@@ -1891,14 +1915,20 @@
 msgid "generic relation to link one entity to another"
 msgstr "relación generica para ligar entidades"
 
+msgid ""
+"generic relation to specify that an external entity represent the same "
+"object as a local one: http://www.w3.org/TR/owl-ref/#sameAs-def NOTE: You'll "
+"have to explicitly declare which entity types can have a same_as relation"
+msgstr ""
+
 msgid "go back to the index page"
 msgstr "Regresar a la página de inicio"
 
 msgid "granted to groups"
 msgstr "Otorgado a los grupos"
 
-msgid "graphical representation of the application'schema"
-msgstr "Representación gráfica del esquema de la aplicación"
+msgid "graphical representation of the instance'schema"
+msgstr ""
 
 #, python-format
 msgid "graphical schema for %s"
@@ -2059,6 +2089,9 @@
 msgstr ""
 "Indica cual estado deberá ser utilizado por defecto al crear una entidad"
 
+msgid "info"
+msgstr ""
+
 #, python-format
 msgid "initial estimation %s"
 msgstr "Estimación inicial %s"
@@ -2075,6 +2108,12 @@
 msgid "inlined"
 msgstr "Puesto en línea"
 
+msgid "instance schema"
+msgstr ""
+
+msgid "internal entity uri"
+msgstr ""
+
 msgid "internationalizable"
 msgstr "Internacionalizable"
 
@@ -2088,12 +2127,6 @@
 msgid "is"
 msgstr "es"
 
-msgid "is it an application entity type or not ?"
-msgstr "Es un Tipo de entidad en la aplicación o no ?"
-
-msgid "is it an application relation type or not ?"
-msgstr "Es una relación aplicativa o no ?"
-
 msgid ""
 "is the subject/object entity of the relation composed of the other ? This "
 "implies that when the composite is deleted, composants are also deleted."
@@ -2156,8 +2189,9 @@
 msgid ""
 "link a permission to the entity. This permission should be used in the "
 "security definition of the entity's type to be useful."
-msgstr "relaciónar una autorización con la entidad. Este autorización debe "
-"ser usada en la definición de la entidad para ser utíl."
+msgstr ""
+"relaciónar una autorización con la entidad. Este autorización debe ser usada "
+"en la definición de la entidad para ser utíl."
 
 msgid ""
 "link a property to the user which want this property customization. Unless "
@@ -2252,9 +2286,6 @@
 msgid "may"
 msgstr "Mayo"
 
-msgid "meta"
-msgstr "Meta"
-
 msgid "milestone"
 msgstr "Milestone"
 
@@ -2310,20 +2341,20 @@
 
 msgid "navigation.combobox-limit"
 msgstr ""
+
 # msgstr "Navegación: numero maximo de elementos en una caja de elección (combobox)"
-
 msgid "navigation.page-size"
 msgstr ""
+
 # msgstr "Navegación: numero maximo de elementos por pagina"
-
 msgid "navigation.related-limit"
 msgstr ""
+
 # msgstr "Navegación: numero maximo de elementos relacionados"
-
 msgid "navigation.short-line-size"
 msgstr ""
-#msgstr "Navegación: numero maximo de caracteres en una linéa corta"
-
+
+# msgstr "Navegación: numero maximo de caracteres en una linéa corta"
 msgid "navtop"
 msgstr "Encabezado del contenido principal"
 
@@ -2339,9 +2370,6 @@
 msgid "no associated permissions"
 msgstr "no autorización relacionada"
 
-msgid "no possible transition"
-msgstr "transición no posible"
-
 msgid "no related project"
 msgstr "no hay proyecto relacionado"
 
@@ -2361,9 +2389,6 @@
 msgid "not selected"
 msgstr "no seleccionado"
 
-msgid "not specified"
-msgstr "no especificado"
-
 msgid "not the initial state for this entity"
 msgstr "no el estado inicial para esta entidad"
 
@@ -2560,6 +2585,9 @@
 msgid "remove this EmailAddress"
 msgstr "Eliminar este correo electronico"
 
+msgid "remove this ExternalUri"
+msgstr ""
+
 msgid "remove this RQLExpression"
 msgstr "Eliminar esta expresión RQL"
 
@@ -2625,6 +2653,9 @@
 msgid "rss"
 msgstr "RSS"
 
+msgid "same_as"
+msgstr ""
+
 msgid "sample format"
 msgstr "ejemplo"
 
@@ -2753,6 +2784,9 @@
 msgid "sorry, the server is unable to handle this query"
 msgstr "lo sentimos, el servidor no puede manejar esta consulta"
 
+msgid "sparql xml"
+msgstr ""
+
 msgid "specializes"
 msgstr "derivado de"
 
@@ -2826,6 +2860,9 @@
 msgid "text/rest"
 msgstr "text/rest"
 
+msgid "the URI of the object"
+msgstr ""
+
 msgid "the prefered email"
 msgstr "dirección principal de email"
 
@@ -2876,6 +2913,9 @@
 msgid "to_entity_object"
 msgstr "hacia entidad objeto"
 
+msgid "to_interval_end"
+msgstr ""
+
 msgid "to_state"
 msgstr "hacia el estado"
 
@@ -2906,6 +2946,9 @@
 msgid "type"
 msgstr "type"
 
+msgid "type here a sparql query"
+msgstr ""
+
 msgid "ui"
 msgstr "interfaz de usuario"
 
@@ -2954,6 +2997,9 @@
 msgid "unknown property key"
 msgstr "propiedad desconocida"
 
+msgid "unknown vocabulary:"
+msgstr ""
+
 msgid "up"
 msgstr "arriba"
 
@@ -2976,6 +3022,9 @@
 msgid "updated %(etype)s #%(eid)s (%(title)s)"
 msgstr "actualización de la entidad %(etype)s #%(eid)s (%(title)s)"
 
+msgid "uri"
+msgstr ""
+
 msgid "use template languages"
 msgstr "utilizar plantillas de lenguaje"
 
@@ -3062,15 +3111,24 @@
 msgid "view detail for this entity"
 msgstr "ver detalle de esta entidad"
 
+msgid "view history"
+msgstr ""
+
 msgid "view workflow"
 msgstr "ver workflow"
 
+msgid "view_index"
+msgstr ""
+
 msgid "views"
 msgstr "vistas"
 
 msgid "visible"
 msgstr "visible"
 
+msgid "we are not yet ready to handle this query"
+msgstr ""
+
 msgid "wednesday"
 msgstr "miercoles"
 
@@ -3160,6 +3218,9 @@
 #~ msgid "This Card"
 #~ msgstr "Esta Ficha"
 
+#~ msgid "You are not connected to an application !"
+#~ msgstr "Usted no esta conectado a una aplicación"
+
 #~ msgid ""
 #~ "a card is a textual content used as documentation, reference, procedure "
 #~ "reminder"
@@ -3167,6 +3228,17 @@
 #~ "una ficha es un texto utilizado como documentación, referencia, memoria "
 #~ "de algún procedimiento..."
 
+#~ msgid ""
+#~ "a simple cache entity characterized by a name and a validity date. The "
+#~ "target application is responsible for updating timestamp when necessary "
+#~ "to invalidate the cache (typically in hooks). Also, checkout the "
+#~ "AppRsetObject.get_cache() method."
+#~ msgstr ""
+#~ "una entidad cache simple caracterizada por un nombre y una fecha "
+#~ "correcta. El sistema objetivo es responsable de actualizar timestamp "
+#~ "cuand se necesario para invalidar el cache (usualmente en hooks)."
+#~ "Recomendamos revisar el METODO  AppRsetObject.get_cache()."
+
 #~ msgid "add a Card"
 #~ msgstr "Agregar una ficha"
 
@@ -3176,6 +3248,9 @@
 #~ msgid "and"
 #~ msgstr "et"
 
+#~ msgid "application schema"
+#~ msgstr "Esquema de la aplicación"
+
 #~ msgid "at least one relation %s is required on %s(%s)"
 #~ msgstr "au moins une relation %s est nÈcessaire sur %s(%s)"
 
@@ -3207,15 +3282,50 @@
 #~ "langue par dÈfaut (regarder le rÈpertoire i18n de l'application pour voir "
 #~ "les langues disponibles)"
 
+#~ msgid ""
+#~ "define a final relation: link a final relation type from a non final "
+#~ "entity to a final entity type. used to build the application schema"
+#~ msgstr ""
+#~ "Define una relación no final: liga un tipo de relación no final desde una "
+#~ "entidad hacia un tipo de entidad no final. Utilizada para construir el "
+#~ "esquema de la aplicación"
+
+#~ msgid ""
+#~ "define a non final relation: link a non final relation type from a non "
+#~ "final entity to a non final entity type. used to build the application "
+#~ "schema"
+#~ msgstr ""
+#~ "Define una relación 'atributo', utilizada para construir el esquema dela "
+#~ "aplicación"
+
+#~ msgid "define a relation type, used to build the application schema"
+#~ msgstr ""
+#~ "Define un tipo de relación, utilizada para construir el esquema de la "
+#~ "aplicación"
+
+#~ msgid "define an entity type, used to build the application schema"
+#~ msgstr ""
+#~ "Define un tipo de entidad, utilizada para construir el esquema de la "
+#~ "aplicación"
+
 #~ msgid "detailed schema view"
 #~ msgstr "Vista detallada del esquema"
 
+#~ msgid "facets_cwmeta-facet"
+#~ msgstr "faceta \"meta\""
+
+#~ msgid "facets_cwmeta-facet_description"
+#~ msgstr "faceta para las entidades \"meta\""
+
 #~ msgid "filter"
 #~ msgstr "filtrer"
 
 #~ msgid "footer"
 #~ msgstr "pied de page"
 
+#~ msgid "graphical representation of the application'schema"
+#~ msgstr "Representación gráfica del esquema de la aplicación"
+
 #~ msgid "header"
 #~ msgstr "en-tÍte de page"
 
@@ -3231,6 +3341,12 @@
 #~ msgid "inlined view"
 #~ msgstr "Vista incluída (en línea)"
 
+#~ msgid "is it an application entity type or not ?"
+#~ msgstr "Es un Tipo de entidad en la aplicación o no ?"
+
+#~ msgid "is it an application relation type or not ?"
+#~ msgstr "Es una relación aplicativa o no ?"
+
 #~ msgid ""
 #~ "link a transition to one or more rql expression allowing to go through "
 #~ "this transition"
@@ -3248,9 +3364,18 @@
 #~ msgstr ""
 #~ "nombre maximum d'entitÈs liÈes ‡ afficher dans la vue de restriction"
 
+#~ msgid "meta"
+#~ msgstr "Meta"
+
 #~ msgid "no associated epermissions"
 #~ msgstr "permisos no asociados"
 
+#~ msgid "no possible transition"
+#~ msgstr "transición no posible"
+
+#~ msgid "not specified"
+#~ msgstr "no especificado"
+
 #~ msgid "owned by"
 #~ msgstr "appartient ‡"
 
--- a/i18n/fr.po	Fri Aug 07 12:20:37 2009 +0200
+++ b/i18n/fr.po	Fri Aug 07 12:20:50 2009 +0200
@@ -4,7 +4,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: cubicweb 2.46.0\n"
-"PO-Revision-Date: 2008-12-23 18:41+0100\n"
+"PO-Revision-Date: 2009-08-05 08:37+0200\n"
 "Last-Translator: Logilab Team <contact@logilab.fr>\n"
 "Language-Team: fr <contact@logilab.fr>\n"
 "MIME-Version: 1.0\n"
@@ -123,6 +123,9 @@
 msgid "%s software version of the database"
 msgstr "version logicielle de la base pour %s"
 
+msgid "(UNEXISTANT EID)"
+msgstr "(EID INTROUVABLE)"
+
 msgid "**"
 msgstr "0..n 0..n"
 
@@ -324,6 +327,12 @@
 msgid "Environment"
 msgstr "Environement"
 
+msgid "ExternalUri"
+msgstr "Uri externe"
+
+msgid "ExternalUri_plural"
+msgstr "Uri externes"
+
 msgid "Float"
 msgstr "Nombre flottant"
 
@@ -384,6 +393,9 @@
 msgid "New EmailAddress"
 msgstr "Nouvelle adresse électronique"
 
+msgid "New ExternalUri"
+msgstr "Nouvelle Uri externe"
+
 msgid "New RQLExpression"
 msgstr "Nouvelle expression rql"
 
@@ -526,6 +538,9 @@
 msgid "This EmailAddress"
 msgstr "Cette adresse électronique"
 
+msgid "This ExternalUri"
+msgstr "Cette Uri externe"
+
 msgid "This RQLExpression"
 msgstr "Cette expression RQL"
 
@@ -572,8 +587,8 @@
 msgid "Workflow history"
 msgstr "Historique des changements d'état"
 
-msgid "You are not connected to an application !"
-msgstr "Vous n'êtes pas connecté à une application"
+msgid "You are not connected to an instance !"
+msgstr "Vous n'êtes pas connecté à une instance !"
 
 #, python-format
 msgid "You are now connected to %s"
@@ -630,16 +645,20 @@
 "représente respectivement l'entité à laquelle on veut appliquer la "
 "transition et l'utilisateur courant."
 
+msgid "a URI representing an object in external data store"
+msgstr "une Uri désignant un objet dans un entrepôt de donné externe"
+
 msgid ""
 "a simple cache entity characterized by a name and a validity date. The "
 "target application is responsible for updating timestamp when necessary to "
-"invalidate the cache (typically in hooks). Also, checkout the AppRsetObject."
+"invalidate the cache (typically in hooks). Also, checkout the AppObject."
 "get_cache() method."
 msgstr ""
-"une simple entité de cache, caractérisées par un nom et une date de "
-"validité. L'application est responsable de la mise à jour de la date quand "
-"il est nécessaire d'invalider le cache (typiquement dans les crochets). Voir "
-"aussi la méthode get_cache() sur la classe AppRsetObject."
+"un cache simple caractérisé par un nom et une date de validité. C'est\n"
+"le code de l'instance qui est responsable de mettre à jour la date de\n"
+"validité lorsque le cache doit être invalidé (en général dans un hook).\n"
+"Pour récupérer un cache, il faut utiliser utiliser la méthode\n"
+"get_cache(cachename)."
 
 msgid "about this site"
 msgstr "à propos de ce site"
@@ -770,6 +789,12 @@
 msgid "actions_siteconfig_description"
 msgstr ""
 
+msgid "actions_siteinfo"
+msgstr ""
+
+msgid "actions_siteinfo_description"
+msgstr ""
+
 msgid "actions_view"
 msgstr "voir"
 
@@ -896,6 +921,9 @@
 msgid "add a EmailAddress"
 msgstr "ajouter une adresse email"
 
+msgid "add a ExternalUri"
+msgstr "ajouter une Uri externe"
+
 msgid "add a RQLExpression"
 msgstr "ajouter une expression rql"
 
@@ -991,9 +1019,6 @@
 msgid "application entities"
 msgstr "entités applicatives"
 
-msgid "application schema"
-msgstr "Schéma de l'application"
-
 msgid "april"
 msgstr "avril"
 
@@ -1137,6 +1162,9 @@
 msgid "calendar (year)"
 msgstr "calendrier (annuel)"
 
+msgid "can not resolve entity types:"
+msgstr "impossible d'interpréter les types d'entités :"
+
 #, python-format
 msgid "can't change the %s attribute"
 msgstr "ne peut changer l'attribut %s"
@@ -1527,6 +1555,9 @@
 msgid "cwetype-workflow"
 msgstr "workflow"
 
+msgid "cwuri"
+msgstr "uri interne"
+
 msgid "data directory url"
 msgstr "url du répertoire de données"
 
@@ -1559,23 +1590,16 @@
 
 msgid ""
 "define a final relation: link a final relation type from a non final entity "
-"to a final entity type. used to build the application schema"
+"to a final entity type. used to build the instance schema"
 msgstr ""
-"définit une relation non finale: lie un type de relation non finaledepuis "
-"une entité vers un type d'entité non final. Utilisé pour construire le "
-"schéma de l'application"
 
 msgid ""
 "define a non final relation: link a non final relation type from a non final "
-"entity to a non final entity type. used to build the application schema"
+"entity to a non final entity type. used to build the instance schema"
 msgstr ""
-"définit une relation 'attribut', utilisé pour construire le schéma de "
-"l'application"
-
-msgid "define a relation type, used to build the application schema"
-msgstr ""
-"définit un type de relation, utilisé pour construire le schéma de "
-"l'application"
+
+msgid "define a relation type, used to build the instance schema"
+msgstr "définit un type de relation"
 
 msgid "define a rql expression used to define permissions"
 msgstr "RQL expression utilisée pour définir les droits d'accès"
@@ -1586,9 +1610,8 @@
 msgid "define a schema constraint type"
 msgstr "définit un type de contrainte de schema"
 
-msgid "define an entity type, used to build the application schema"
+msgid "define an entity type, used to build the instance schema"
 msgstr ""
-"définit un type d'entité, utilisé pour construire le schéma de l'application"
 
 msgid ""
 "defines what's the property is applied for. You must select this first to be "
@@ -1689,6 +1712,9 @@
 msgid "download icon"
 msgstr "icône de téléchargement"
 
+msgid "download image"
+msgstr "image de téléchargement"
+
 msgid "download schema as owl"
 msgstr "télécharger le schéma OWL"
 
@@ -1872,6 +1898,9 @@
 msgid "from_entity_object"
 msgstr "relation sujet"
 
+msgid "from_interval_start"
+msgstr "De"
+
 msgid "from_state"
 msgstr "de l'état"
 
@@ -1893,14 +1922,20 @@
 msgid "generic relation to link one entity to another"
 msgstr "relation générique pour lier une entité à une autre"
 
+msgid ""
+"generic relation to specify that an external entity represent the same "
+"object as a local one: http://www.w3.org/TR/owl-ref/#sameAs-def NOTE: You'll "
+"have to explicitly declare which entity types can have a same_as relation"
+msgstr ""
+
 msgid "go back to the index page"
 msgstr "retourner sur la page d'accueil"
 
 msgid "granted to groups"
 msgstr "accordée aux groupes"
 
-msgid "graphical representation of the application'schema"
-msgstr "représentation graphique du schéma de l'application"
+msgid "graphical representation of the instance'schema"
+msgstr "représentation graphique du schéma de l'instance"
 
 #, python-format
 msgid "graphical schema for %s"
@@ -2062,6 +2097,9 @@
 msgstr ""
 "indique quel état devrait être utilisé par défaut lorsqu'une entité est créée"
 
+msgid "info"
+msgstr "information"
+
 #, python-format
 msgid "initial estimation %s"
 msgstr "estimation initiale %s"
@@ -2078,6 +2116,12 @@
 msgid "inlined"
 msgstr "mise en ligne"
 
+msgid "instance schema"
+msgstr "schéma de l'instance"
+
+msgid "internal entity uri"
+msgstr "uri interne"
+
 msgid "internationalizable"
 msgstr "internationalisable"
 
@@ -2091,12 +2135,6 @@
 msgid "is"
 msgstr "de type"
 
-msgid "is it an application entity type or not ?"
-msgstr "est-ce une entité applicative ou non ?"
-
-msgid "is it an application relation type or not ?"
-msgstr "est-ce une relation applicative ou non ?"
-
 msgid ""
 "is the subject/object entity of the relation composed of the other ? This "
 "implies that when the composite is deleted, composants are also deleted."
@@ -2257,9 +2295,6 @@
 msgid "may"
 msgstr "mai"
 
-msgid "meta"
-msgstr "méta"
-
 msgid "milestone"
 msgstr "jalon"
 
@@ -2340,9 +2375,6 @@
 msgid "no associated permissions"
 msgstr "aucune permission associée"
 
-msgid "no possible transition"
-msgstr "aucune transition possible"
-
 msgid "no related project"
 msgstr "pas de projet rattaché"
 
@@ -2560,6 +2592,9 @@
 msgid "remove this EmailAddress"
 msgstr "supprimer cette adresse email"
 
+msgid "remove this ExternalUri"
+msgstr "supprimer cette Uri externe"
+
 msgid "remove this RQLExpression"
 msgstr "supprimer cette expression rql"
 
@@ -2630,6 +2665,9 @@
 msgid "rss"
 msgstr "RSS"
 
+msgid "same_as"
+msgstr "identique à l'entité externe"
+
 msgid "sample format"
 msgstr "exemple"
 
@@ -2757,6 +2795,9 @@
 msgid "sorry, the server is unable to handle this query"
 msgstr "désolé, le serveur ne peut traiter cette requête"
 
+msgid "sparql xml"
+msgstr "XML Sparql"
+
 msgid "specializes"
 msgstr "dérive de"
 
@@ -2830,6 +2871,9 @@
 msgid "text/rest"
 msgstr "ReST"
 
+msgid "the URI of the object"
+msgstr "l'Uri de l'objet"
+
 msgid "the prefered email"
 msgstr "l'adresse électronique principale"
 
@@ -2881,6 +2925,9 @@
 msgid "to_entity_object"
 msgstr "relation objet"
 
+msgid "to_interval_end"
+msgstr "à"
+
 msgid "to_state"
 msgstr "vers l'état"
 
@@ -2911,6 +2958,9 @@
 msgid "type"
 msgstr "type"
 
+msgid "type here a sparql query"
+msgstr "Tapez une requête sparql"
+
 msgid "ui"
 msgstr "propriétés génériques de l'interface"
 
@@ -2959,6 +3009,9 @@
 msgid "unknown property key"
 msgstr "clé de propriété inconnue"
 
+msgid "unknown vocabulary:"
+msgstr "vocabulaire inconnu : "
+
 msgid "up"
 msgstr "haut"
 
@@ -2981,6 +3034,9 @@
 msgid "updated %(etype)s #%(eid)s (%(title)s)"
 msgstr "modification de l'entité %(etype)s #%(eid)s (%(title)s)"
 
+msgid "uri"
+msgstr "uri"
+
 msgid "use template languages"
 msgstr "utiliser les langages de template"
 
@@ -3065,21 +3121,25 @@
 msgid "view detail for this entity"
 msgstr "voir les détails de cette entité"
 
+msgid "view history"
+msgstr "voir l'historique"
+
 msgid "view workflow"
 msgstr "voir les états possibles"
 
 msgid "view_index"
 msgstr "accueil"
 
-msgid "view_manage"
-msgstr "gestion du site"
-
 msgid "views"
 msgstr "vues"
 
 msgid "visible"
 msgstr "visible"
 
+msgid "we are not yet ready to handle this query"
+msgstr ""
+"nous ne sommes pas capable de gérer ce type de requête sparql pour le moment"
+
 msgid "wednesday"
 msgstr "mercredi"
 
@@ -3169,6 +3229,9 @@
 #~ msgid "This Card"
 #~ msgstr "Cette fiche"
 
+#~ msgid "You are not connected to an application !"
+#~ msgstr "Vous n'êtes pas connecté à une application"
+
 #~ msgid ""
 #~ "a card is a textual content used as documentation, reference, procedure "
 #~ "reminder"
@@ -3176,6 +3239,17 @@
 #~ "une fiche est un texte utilisé comme documentation, référence, rappel de "
 #~ "procédure..."
 
+#~ msgid ""
+#~ "a simple cache entity characterized by a name and a validity date. The "
+#~ "target application is responsible for updating timestamp when necessary "
+#~ "to invalidate the cache (typically in hooks). Also, checkout the "
+#~ "AppRsetObject.get_cache() method."
+#~ msgstr ""
+#~ "une simple entité de cache, caractérisées par un nom et une date de "
+#~ "validité. L'application est responsable de la mise à jour de la date "
+#~ "quand il est nécessaire d'invalider le cache (typiquement dans les "
+#~ "crochets). Voir aussi la méthode get_cache() sur la classe AppRsetObject."
+
 #~ msgid "actions_addpermission"
 #~ msgstr "ajouter une permission"
 
@@ -3188,6 +3262,9 @@
 #~ msgid "and"
 #~ msgstr "et"
 
+#~ msgid "application schema"
+#~ msgstr "Schéma de l'application"
+
 #~ msgid "at least one relation %s is required on %s(%s)"
 #~ msgstr "au moins une relation %s est nécessaire sur %s(%s)"
 
@@ -3219,6 +3296,32 @@
 #~ "langue par défaut (regarder le répertoire i18n de l'application pour voir "
 #~ "les langues disponibles)"
 
+#~ msgid ""
+#~ "define a final relation: link a final relation type from a non final "
+#~ "entity to a final entity type. used to build the application schema"
+#~ msgstr ""
+#~ "définit une relation non finale: lie un type de relation non finaledepuis "
+#~ "une entité vers un type d'entité non final. Utilisé pour construire le "
+#~ "schéma de l'application"
+
+#~ msgid ""
+#~ "define a non final relation: link a non final relation type from a non "
+#~ "final entity to a non final entity type. used to build the application "
+#~ "schema"
+#~ msgstr ""
+#~ "définit une relation 'attribut', utilisé pour construire le schéma de "
+#~ "l'application"
+
+#~ msgid "define a relation type, used to build the application schema"
+#~ msgstr ""
+#~ "définit un type de relation, utilisé pour construire le schéma de "
+#~ "l'application"
+
+#~ msgid "define an entity type, used to build the application schema"
+#~ msgstr ""
+#~ "définit un type d'entité, utilisé pour construire le schéma de "
+#~ "l'application"
+
 #~ msgid "detailed schema view"
 #~ msgstr "vue détaillée du schéma"
 
@@ -3228,6 +3331,9 @@
 #~ msgid "footer"
 #~ msgstr "pied de page"
 
+#~ msgid "graphical representation of the application'schema"
+#~ msgstr "représentation graphique du schéma de l'application"
+
 #~ msgid "header"
 #~ msgstr "en-tête de page"
 
@@ -3243,6 +3349,12 @@
 #~ msgid "inlined view"
 #~ msgstr "vue embarquée (en ligne)"
 
+#~ msgid "is it an application entity type or not ?"
+#~ msgstr "est-ce une entité applicative ou non ?"
+
+#~ msgid "is it an application relation type or not ?"
+#~ msgstr "est-ce une relation applicative ou non ?"
+
 #~ msgid "linked"
 #~ msgstr "lié"
 
@@ -3254,9 +3366,15 @@
 #~ msgstr ""
 #~ "nombre maximum d'entités liées à afficher dans la vue de restriction"
 
+#~ msgid "meta"
+#~ msgstr "méta"
+
 #~ msgid "no associated epermissions"
 #~ msgstr "aucune permission spécifique n'est définie"
 
+#~ msgid "no possible transition"
+#~ msgstr "aucune transition possible"
+
 #~ msgid "not specified"
 #~ msgstr "non spécifié"
 
@@ -3281,6 +3399,9 @@
 #~ msgid "synopsis"
 #~ msgstr "synopsis"
 
+#~ msgid "view_manage"
+#~ msgstr "gestion du site"
+
 #~ msgid "wikiid"
 #~ msgstr "identifiant wiki"
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i18n/static-messages.pot	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,11 @@
+msgid "read_perm"
+msgstr ""
+
+msgid "add_perm"
+msgstr ""
+
+msgid "update_perm"
+msgstr ""
+
+msgid "delete_perm"
+msgstr ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.4.0_Any.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,2 @@
+drop_attribute('CWEType', 'meta')
+drop_attribute('CWRType', 'meta')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.4.0_common.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,6 @@
+from os.path import join
+from cubicweb.toolsutils import create_dir
+
+option_renamed('pyro-application-id', 'pyro-instance-id')
+
+create_dir(join(config.appdatahome, 'backup'))
--- a/misc/migration/bootstrapmigration_repository.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/misc/migration/bootstrapmigration_repository.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,49 +10,68 @@
 
 applcubicwebversion, cubicwebversion = versions_map['cubicweb']
 
+if applcubicwebversion < (3, 4, 0) and cubicwebversion >= (3, 4, 0):
+    from cubicweb import RepositoryError
+    from cubicweb.server.hooks import uniquecstrcheck_before_modification
+    session.set_shared_data('do-not-insert-cwuri', True)
+    repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
+    repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
+    add_relation_type('cwuri')
+    base_url = session.base_url()
+    # use an internal session since some entity might forbid modifications to admin
+    isession = repo.internal_session()
+    for eid, in rql('Any X', ask_confirm=False):
+        type, source, extid = session.describe(eid)
+        if source == 'system':
+            isession.execute('SET X cwuri %(u)s WHERE X eid %(x)s',
+                             {'x': eid, 'u': base_url + u'eid/%s' % eid})
+    isession.commit()
+    repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
+    repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
+    session.set_shared_data('do-not-insert-cwuri', False)
+
 if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1):
-   from base64 import b64encode
-   for table in ('entities', 'deleted_entities'):
-      for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
-                            % table, ask_confirm=False):
-         sql('UPDATE %s SET extid=%%(extid)s WHERE eid=%%(eid)s' % table,
-             {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
-   checkpoint()
+    from base64 import b64encode
+    for table in ('entities', 'deleted_entities'):
+        for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
+                              % table, ask_confirm=False):
+            sql('UPDATE %s SET extid=%%(extid)s WHERE eid=%%(eid)s' % table,
+                {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
+    checkpoint()
 
 if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
-   add_cube('card', update_database=False)
+    add_cube('card', update_database=False)
 
 if applcubicwebversion < (2, 47, 0) and cubicwebversion >= (2, 47, 0):
-    from cubicweb.server import schemaserial
-    schemaserial.HAS_FULLTEXT_CONTAINER = False
-    session.set_shared_data('do-not-insert-is_instance_of', True)
-    add_attribute('CWRType', 'fulltext_container')
-    schemaserial.HAS_FULLTEXT_CONTAINER = True
+     from cubicweb.server import schemaserial
+     schemaserial.HAS_FULLTEXT_CONTAINER = False
+     session.set_shared_data('do-not-insert-is_instance_of', True)
+     add_attribute('CWRType', 'fulltext_container')
+     schemaserial.HAS_FULLTEXT_CONTAINER = True
 
 
 
 if applcubicwebversion < (2, 50, 0) and cubicwebversion >= (2, 50, 0):
-    session.set_shared_data('do-not-insert-is_instance_of', True)
-    add_relation_type('is_instance_of')
-    # fill the relation using an efficient sql query instead of using rql
-    sql('INSERT INTO is_instance_of_relation '
-        '  SELECT * from is_relation')
-    checkpoint()
-    session.set_shared_data('do-not-insert-is_instance_of', False)
+     session.set_shared_data('do-not-insert-is_instance_of', True)
+     add_relation_type('is_instance_of')
+     # fill the relation using an efficient sql query instead of using rql
+     sql('INSERT INTO is_instance_of_relation '
+         '  SELECT * from is_relation')
+     checkpoint()
+     session.set_shared_data('do-not-insert-is_instance_of', False)
 
 if applcubicwebversion < (2, 42, 0) and cubicwebversion >= (2, 42, 0):
-    sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP')
-    sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP')
-    sql('CREATE INDEX entities_mtime_idx ON entities(mtime)')
-    sql('''CREATE TABLE deleted_entities (
+     sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP')
+     sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP')
+     sql('CREATE INDEX entities_mtime_idx ON entities(mtime)')
+     sql('''CREATE TABLE deleted_entities (
   eid INTEGER PRIMARY KEY NOT NULL,
   type VARCHAR(64) NOT NULL,
   source VARCHAR(64) NOT NULL,
   dtime TIMESTAMP NOT NULL,
   extid VARCHAR(256)
 )''')
-    sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)')
-    sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)')
-    sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)')
-    checkpoint()
-
+     sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)')
+     sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)')
+     sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)')
+     checkpoint()
--- a/rset.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/rset.py	Fri Aug 07 12:20:50 2009 +0200
@@ -83,7 +83,8 @@
         try:
             return self._rsetactions[key]
         except KeyError:
-            actions = self.vreg.possible_vobjects('actions', self.req, self, **kwargs)
+            actions = self.vreg['actions'].possible_vobjects(
+                self.req, rset=self, **kwargs)
             self._rsetactions[key] = actions
             return actions
 
@@ -346,7 +347,7 @@
             raise NotAnEntity(etype)
         return self._build_entity(row, col)
 
-    def _build_entity(self, row, col, _localcache=None):
+    def _build_entity(self, row, col):
         """internal method to get a single entity, returns a
         partially initialized Entity instance.
 
@@ -369,23 +370,23 @@
         # XXX should we consider updating a cached entity with possible
         #     new attributes found in this resultset ?
         try:
-            if hasattr(req, 'is_super_session'):
-                # this is a Session object which is not caching entities, so we
-                # have to use a local cache to avoid recursion pb
-                if _localcache is None:
-                    _localcache = {}
-                return _localcache[eid]
-            else:
-                return req.entity_cache(eid)
+            entity = req.entity_cache(eid)
+            if entity.rset is None:
+                # entity has no rset set, this means entity has been cached by
+                # the repository (req is a repository session) which had no rset
+                # info. Add id.
+                entity.rset = self
+                entity.row = row
+                entity.col = col
+            return entity
         except KeyError:
             pass
         # build entity instance
         etype = self.description[row][col]
-        entity = self.vreg.etype_class(etype)(req, self, row, col)
+        entity = self.vreg['etypes'].etype_class(etype)(req, rset=self,
+                                                        row=row, col=col)
         entity.set_eid(eid)
         # cache entity
-        if _localcache is not None:
-            _localcache[eid] = entity
         req.set_entity_cache(entity)
         eschema = entity.e_schema
         # try to complete the entity if there are some additional columns
@@ -419,7 +420,7 @@
                         rrset = ResultSet([], rql % (attr, entity.eid))
                         req.decorate_rset(rrset)
                     else:
-                        rrset = self._build_entity(row, i, _localcache).as_rset()
+                        rrset = self._build_entity(row, i).as_rset()
                     entity.set_related_cache(attr, x, rrset)
         return entity
 
--- a/rtags.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/rtags.py	Fri Aug 07 12:20:50 2009 +0200
@@ -41,6 +41,9 @@
         return self.get(*key)
     __contains__ = __getitem__
 
+    def clear(self):
+        self._tagdefs.clear()
+
     def _get_keys(self, stype, rtype, otype, tagged):
         keys = [(rtype, tagged, '*', '*'),
                 (rtype, tagged, '*', otype),
--- a/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,14 +14,15 @@
 from warnings import warn
 
 from logilab.common.decorators import cached, clear_cache, monkeypatch
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 from logilab.common.compat import any
 
 from yams import BadSchemaDefinition, buildobjs as ybo
 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema
-from yams.constraints import BaseConstraint, StaticVocabularyConstraint
-from yams.reader import (CONSTRAINTS, RelationFileReader, PyFileReader,
-                         SchemaLoader)
+from yams.constraints import (BaseConstraint, StaticVocabularyConstraint,
+                              FormatConstraint)
+from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
+                         obsolete as yobsolete, cleanup_sys_modules)
 
 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
 
@@ -33,7 +34,22 @@
 schema.use_py_datetime()
 nodes.use_py_datetime()
 
-BASEGROUPS = ('managers', 'users', 'guests', 'owners')
+PURE_VIRTUAL_RTYPES = set(('identity', 'has_text',))
+VIRTUAL_RTYPES = set(('eid', 'identity', 'has_text',))
+
+#  set of meta-relations available for every entity types
+META_RTYPES = set((
+    'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
+    'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
+    ))
+
+#  set of entity and relation types used to build the schema
+SCHEMA_TYPES = set((
+    'CWEType', 'CWRType', 'CWAttribute', 'CWRelation',
+    'CWConstraint', 'CWConstraintType', 'RQLExpression',
+    'relation_type', 'from_entity', 'to_entity',
+    'constrained_by', 'cstrtype',
+    ))
 
 _LOGGER = getLogger('cubicweb.schemaloader')
 
@@ -50,75 +66,6 @@
         etype = ETYPE_NAME_MAP[etype]
     return etype
 
-# monkey path yams.builder.RelationDefinition to support a new wildcard type '@'
-# corresponding to system entity (ie meta but not schema)
-def _actual_types(self, schema, etype):
-    # two bits of error checking & reporting :
-    if type(etype) not in (str, list, tuple):
-        raise RuntimeError, ('Entity types must not be instances but strings or'
-                             ' list/tuples thereof. Ex. (bad, good) : '
-                             'SubjectRelation(Foo), SubjectRelation("Foo"). '
-                             'Hence, %r is not acceptable.' % etype)
-    # real work :
-    if etype == '**':
-        return self._pow_etypes(schema)
-    if isinstance(etype, (tuple, list)):
-        return etype
-    if '*' in etype or '@' in etype:
-        assert len(etype) in (1, 2)
-        etypes = ()
-        if '*' in etype:
-            etypes += tuple(self._wildcard_etypes(schema))
-        if '@' in etype:
-            etypes += tuple(system_etypes(schema))
-        return etypes
-    return (etype,)
-ybo.RelationDefinition._actual_types = _actual_types
-
-
-## cubicweb provides a RichString class for convenience
-class RichString(ybo.String):
-    """Convenience RichString attribute type
-    The following declaration::
-
-      class Card(EntityType):
-          content = RichString(fulltextindexed=True, default_format='text/rest')
-
-    is equivalent to::
-
-      class Card(EntityType):
-          content_format = String(meta=True, internationalizable=True,
-                                 default='text/rest', constraints=[format_constraint])
-          content  = String(fulltextindexed=True)
-    """
-    def __init__(self, default_format='text/plain', format_constraints=None, **kwargs):
-        self.default_format = default_format
-        self.format_constraints = format_constraints or [format_constraint]
-        super(RichString, self).__init__(**kwargs)
-
-PyFileReader.context['RichString'] = RichString
-
-## need to monkeypatch yams' _add_relation function to handle RichString
-yams_add_relation = ybo._add_relation
-@monkeypatch(ybo)
-def _add_relation(relations, rdef, name=None, insertidx=None):
-    if isinstance(rdef, RichString):
-        format_attrdef = ybo.String(meta=True, internationalizable=True,
-                                    default=rdef.default_format, maxsize=50,
-                                    constraints=rdef.format_constraints)
-        yams_add_relation(relations, format_attrdef, name+'_format', insertidx)
-    yams_add_relation(relations, rdef, name, insertidx)
-
-
-yams_EntityType_add_relation = ybo.EntityType.add_relation
-@monkeypatch(ybo.EntityType)
-def add_relation(self, rdef, name=None):
-    yams_EntityType_add_relation(self, rdef, name)
-    if isinstance(rdef, RichString) and not rdef in self._defined:
-        format_attr_name = (name or rdef.name) + '_format'
-        rdef = self.get_relations(format_attr_name).next()
-        self._ensure_relation_type(rdef)
-
 def display_name(req, key, form=''):
     """return a internationalized string for the key (schema entity or relation
     name) in a given form
@@ -131,7 +78,7 @@
     # ensure unicode
     # added .lower() in case no translation are available
     return unicode(req._(key)).lower()
-__builtins__['display_name'] = obsolete('display_name should be imported from cubicweb.schema')(display_name)
+__builtins__['display_name'] = deprecated('display_name should be imported from cubicweb.schema')(display_name)
 
 def ERSchema_display_name(self, req, form=''):
     """return a internationalized string for the entity/relation type name in
@@ -253,7 +200,7 @@
     """return system entity types only: skip final, schema and application entities
     """
     for eschema in schema.entities():
-        if eschema.is_final() or eschema.schema_entity() or not eschema.meta:
+        if eschema.is_final() or eschema.schema_entity():
             continue
         yield eschema.type
 
@@ -293,6 +240,15 @@
                 continue
             yield rschema, attrschema
 
+    def main_attribute(self):
+        """convenience method that returns the *main* (i.e. the first non meta)
+        attribute defined in the entity schema
+        """
+        for rschema, _ in self.attribute_definitions():
+            if not (rschema in META_RTYPES
+                    or self.is_metadata(rschema)):
+                return rschema
+
     def add_subject_relation(self, rschema):
         """register the relation schema as possible subject relation"""
         super(CubicWebEntitySchema, self).add_subject_relation(rschema)
@@ -300,10 +256,11 @@
 
     def del_subject_relation(self, rtype):
         super(CubicWebEntitySchema, self).del_subject_relation(rtype)
-        self._update_has_text(False)
+        self._update_has_text(True)
 
-    def _update_has_text(self, need_has_text=None):
+    def _update_has_text(self, deletion=False):
         may_need_has_text, has_has_text = False, False
+        need_has_text = None
         for rschema in self.subject_relations():
             if rschema.is_final():
                 if rschema == 'has_text':
@@ -321,10 +278,9 @@
                     may_need_has_text = True
                 else:
                     need_has_text = False
-                    break
         if need_has_text is None:
             need_has_text = may_need_has_text
-        if need_has_text and not has_has_text:
+        if need_has_text and not has_has_text and not deletion:
             rdef = ybo.RelationDefinition(self.type, 'has_text', 'String')
             self.schema.add_relation_def(rdef)
         elif not need_has_text and has_has_text:
@@ -332,7 +288,7 @@
 
     def schema_entity(self):
         """return True if this entity type is used to build the schema"""
-        return self.type in self.schema.schema_entity_types()
+        return self.type in SCHEMA_TYPES
 
     def check_perm(self, session, action, eid=None):
         # NB: session may be a server session or a request object
@@ -370,6 +326,9 @@
             eid = getattr(rdef, 'eid', None)
         self.eid = eid
 
+    @property
+    def meta(self):
+        return self.type in META_RTYPES
 
     def update(self, subjschema, objschema, rdef):
         super(CubicWebRelationSchema, self).update(subjschema, objschema, rdef)
@@ -408,8 +367,8 @@
                (target == 'object' and card[1])
 
     def schema_relation(self):
-        return self.type in ('relation_type', 'from_entity', 'to_entity',
-                             'constrained_by', 'cstrtype')
+        """return True if this relation type is used to build the schema"""
+        return self.type in SCHEMA_TYPES
 
     def physical_mode(self):
         """return an appropriate mode for physical storage of this relation type:
@@ -446,7 +405,7 @@
 
 
     :type name: str
-    :ivar name: name of the schema, usually the application identifier
+    :ivar name: name of the schema, usually the instance identifier
 
     :type base: str
     :ivar base: path of the directory where the schema is defined
@@ -459,24 +418,16 @@
         self._eid_index = {}
         super(CubicWebSchema, self).__init__(*args, **kwargs)
         ybo.register_base_types(self)
-        rschema = self.add_relation_type(ybo.RelationType('eid', meta=True))
+        rschema = self.add_relation_type(ybo.RelationType('eid'))
         rschema.final = True
         rschema.set_default_groups()
-        rschema = self.add_relation_type(ybo.RelationType('has_text', meta=True))
+        rschema = self.add_relation_type(ybo.RelationType('has_text'))
         rschema.final = True
         rschema.set_default_groups()
-        rschema = self.add_relation_type(ybo.RelationType('identity', meta=True))
+        rschema = self.add_relation_type(ybo.RelationType('identity'))
         rschema.final = False
         rschema.set_default_groups()
 
-    def schema_entity_types(self):
-        """return the list of entity types used to build the schema"""
-        return frozenset(('CWEType', 'CWRType', 'CWAttribute', 'CWRelation',
-                          'CWConstraint', 'CWConstraintType', 'RQLExpression',
-                          # XXX those are not really "schema" entity types
-                          #     but we usually don't want them as @* targets
-                          'CWProperty', 'CWPermission', 'State', 'Transition'))
-
     def add_entity_type(self, edef):
         edef.name = edef.name.encode()
         edef.name = bw_normalize_etype(edef.name)
@@ -534,6 +485,7 @@
         for k, v in self._eid_index.items():
             if v == (subjtype, rtype, objtype):
                 del self._eid_index[k]
+                break
         super(CubicWebSchema, self).del_relation_def(subjtype, rtype, objtype)
 
     def del_entity_type(self, etype):
@@ -565,6 +517,11 @@
     def __init__(self, restriction):
         self.restriction = restriction
 
+    def check_consistency(self, subjschema, objschema, rdef):
+        if objschema.is_final():
+            raise BadSchemaDefinition("unique constraint doesn't apply to "
+                                      "final entity type")
+
     def serialize(self):
         return self.restriction
 
@@ -799,7 +756,7 @@
             return self._check(session, x=eid)
         return self._check(session)
 
-PyFileReader.context['ERQLExpression'] = ERQLExpression
+PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression)
 
 class RRQLExpression(RQLExpression):
     def __init__(self, expression, mainvars=None, eid=None):
@@ -843,9 +800,10 @@
             kwargs['o'] = toeid
         return self._check(session, **kwargs)
 
-PyFileReader.context['RRQLExpression'] = RRQLExpression
+PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression)
 
 # workflow extensions #########################################################
+from yams.buildobjs import _add_relation as yams_add_relation
 
 class workflowable_definition(ybo.metadefinition):
     """extends default EntityType's metaclass to add workflow relations
@@ -875,23 +833,6 @@
 
 # schema loading ##############################################################
 
-class CubicWebRelationFileReader(RelationFileReader):
-    """cubicweb specific relation file reader, handling additional RQL
-    constraints on a relation definition
-    """
-
-    def handle_constraint(self, rdef, constraint_text):
-        """arbitrary constraint is an rql expression for cubicweb"""
-        if not rdef.constraints:
-            rdef.constraints = []
-        rdef.constraints.append(RQLVocabularyConstraint(constraint_text))
-
-    def process_properties(self, rdef, relation_def):
-        if 'inline' in relation_def:
-            rdef.inlined = True
-        RelationFileReader.process_properties(self, rdef, relation_def)
-
-
 CONSTRAINTS['RQLConstraint'] = RQLConstraint
 CONSTRAINTS['RQLUniqueConstraint'] = RQLUniqueConstraint
 CONSTRAINTS['RQLVocabularyConstraint'] = RQLVocabularyConstraint
@@ -903,8 +844,6 @@
     the persistent schema
     """
     schemacls = CubicWebSchema
-    SchemaLoader.file_handlers.update({'.rel' : CubicWebRelationFileReader,
-                                       })
 
     def load(self, config, path=(), **kwargs):
         """return a Schema instance from the schema definition read
@@ -927,7 +866,7 @@
 
 class CubicWebSchemaLoader(BootstrapSchemaLoader):
     """cubicweb specific schema loader, automatically adding metadata to the
-    application's schema
+    instance's schema
     """
 
     def load(self, config, **kwargs):
@@ -936,10 +875,14 @@
         """
         self.info('loading %s schemas', ', '.join(config.cubes()))
         if config.apphome:
-            path = reversed([config.apphome] + config.cubes_path())
+            path = tuple(reversed([config.apphome] + config.cubes_path()))
         else:
-            path = reversed(config.cubes_path())
-        return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
+            path = tuple(reversed(config.cubes_path()))
+        try:
+            return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
+        finally:
+            # we've to cleanup modules imported from cubicweb.schemas as well
+            cleanup_sys_modules([self.lib_directory])
 
     def _load_definition_files(self, cubes):
         for filepath in (join(self.lib_directory, 'bootstrap.py'),
@@ -954,49 +897,22 @@
                 self.handle_file(filepath)
 
 
+set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
+set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader'))
+set_log_methods(RQLExpression, getLogger('cubicweb.schema'))
+
 # _() is just there to add messages to the catalog, don't care about actual
 # translation
 PERM_USE_TEMPLATE_FORMAT = _('use_template_format')
-
-class FormatConstraint(StaticVocabularyConstraint):
-    need_perm_formats = [_('text/cubicweb-page-template')]
-
-    regular_formats = (_('text/rest'),
-                       _('text/html'),
-                       _('text/plain'),
-                       )
-    def __init__(self):
-        pass
-
-    def serialize(self):
-        """called to make persistent valuable data of a constraint"""
-        return None
+NEED_PERM_FORMATS = [_('text/cubicweb-page-template')]
 
-    @classmethod
-    def deserialize(cls, value):
-        """called to restore serialized data of a constraint. Should return
-        a `cls` instance
-        """
-        return cls()
-
-    def vocabulary(self, entity=None, req=None):
-        if req is None and entity is not None:
-            req = entity.req
-        if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT):
-            return self.regular_formats + tuple(self.need_perm_formats)
-        return self.regular_formats
-
-    def __str__(self):
-        return 'value in (%s)' % u', '.join(repr(unicode(word)) for word in self.vocabulary())
-
-
-format_constraint = FormatConstraint()
-CONSTRAINTS['FormatConstraint'] = FormatConstraint
-PyFileReader.context['format_constraint'] = format_constraint
-
-set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
-set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader'))
-set_log_methods(RQLExpression, getLogger('cubicweb.schema'))
+@monkeypatch(FormatConstraint)
+def vocabulary(self, entity=None, req=None):
+    if req is None and entity is not None:
+        req = entity.req
+    if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT):
+        return self.regular_formats + tuple(NEED_PERM_FORMATS)
+    return self.regular_formats
 
 # XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is
 # necessary
--- a/schemas/Bookmark.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schemas/Bookmark.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,9 +5,21 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+__docformat__ = "restructuredtext en"
+_ = unicode
 
-class Bookmark(MetaUserEntityType):
+from yams.buildobjs import EntityType, RelationType, SubjectRelation, String
+from cubicweb.schema import RRQLExpression
+
+class Bookmark(EntityType):
     """bookmarks are used to have user's specific internal links"""
+    permissions = {
+        'read':   ('managers', 'users', 'guests',),
+        'add':    ('managers', 'users',),
+        'delete': ('managers', 'owners',),
+        'update': ('managers', 'owners',),
+        }
+
     title = String(required=True, maxsize=128, internationalizable=True)
     path  = String(maxsize=512, required=True,
                    description=_("relative url of the bookmarked page"))
@@ -16,7 +28,7 @@
                                     description=_("users using this bookmark"))
 
 
-class bookmarked_by(MetaUserRelationType):
+class bookmarked_by(RelationType):
     permissions = {'read':   ('managers', 'users', 'guests',),
                    # test user in users group to avoid granting permission to anonymous user
                    'add':    ('managers', RRQLExpression('O identity U, U in_group G, G name "users"')),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schemas/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,24 @@
+# permissions for "meta" entity type (readable by anyone, can only be
+# added/deleted by managers)
+META_ETYPE_PERMS = {
+    'read':   ('managers', 'users', 'guests',),
+    'add':    ('managers',),
+    'delete': ('managers',),
+    'update': ('managers', 'owners',),
+    }
+
+# permissions for "meta" relation type (readable by anyone, can only be
+# added/deleted by managers)
+META_RTYPE_PERMS = {
+    'read':   ('managers', 'users', 'guests',),
+    'add':    ('managers',),
+    'delete': ('managers',),
+    }
+
+# permissions for relation type that should only set by hooks using unsafe
+# execute, readable by anyone
+HOOKS_RTYPE_PERMS = {
+    'read':   ('managers', 'users', 'guests',),
+    'add':    (),
+    'delete': (),
+    }
--- a/schemas/base.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schemas/base.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,11 +6,16 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            String, Boolean, Datetime, Password)
+from cubicweb.schema import (RQLConstraint, WorkflowableEntityType,
+                             ERQLExpression, RRQLExpression)
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
 
 class CWUser(WorkflowableEntityType):
     """define a CubicWeb user"""
-    meta = True # XXX backported from old times, shouldn't be there anymore
     permissions = {
         'read':   ('managers', 'users', ERQLExpression('X identity U')),
         'add':    ('managers',),
@@ -35,7 +40,7 @@
                                description=_('groups grant permissions to the user'))
 
 
-class EmailAddress(MetaEntityType):
+class EmailAddress(EntityType):
     """an electronic mail address associated to a short alias"""
     permissions = {
         'read':   ('managers', 'users', 'guests',), # XXX if P use_email X, U has_read_permission P
@@ -81,11 +86,11 @@
         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
         }
 
-class in_group(MetaRelationType):
+class in_group(RelationType):
     """core relation indicating a user's groups"""
-    meta = False
+    permissions = META_RTYPE_PERMS
 
-class owned_by(MetaRelationType):
+class owned_by(RelationType):
     """core relation indicating owners of an entity. This relation
     implicitly put the owner into the owners group for the entity
     """
@@ -97,10 +102,10 @@
     # 0..n cardinality for entities created by internal session (no attached user)
     # and to support later deletion of a user which has created some entities
     cardinality = '**'
-    subject = '**'
+    subject = '*'
     object = 'CWUser'
 
-class created_by(MetaRelationType):
+class created_by(RelationType):
     """core relation indicating the original creator of an entity"""
     permissions = {
         'read':   ('managers', 'users', 'guests'),
@@ -110,22 +115,28 @@
     # 0..1 cardinality for entities created by internal session (no attached user)
     # and to support later deletion of a user which has created some entities
     cardinality = '?*'
-    subject = '**'
+    subject = '*'
     object = 'CWUser'
 
 
-class creation_date(MetaAttributeRelationType):
+class creation_date(RelationType):
     """creation time of an entity"""
     cardinality = '11'
-    subject = '**'
+    subject = '*'
     object = 'Datetime'
 
-class modification_date(MetaAttributeRelationType):
+class modification_date(RelationType):
     """latest modification time of an entity"""
     cardinality = '11'
-    subject = '**'
+    subject = '*'
     object = 'Datetime'
 
+class cwuri(RelationType):
+    """internal entity uri"""
+    cardinality = '11'
+    subject = '*'
+    object = 'String'
+
 
 class CWProperty(EntityType):
     """used for cubicweb configuration. Once a property has been created you
@@ -137,7 +148,6 @@
         'update': ('managers', 'owners',),
         'delete': ('managers', 'owners',),
         }
-    meta = True
     # key is a reserved word for mysql
     pkey = String(required=True, internationalizable=True, maxsize=256,
                   description=_('defines what\'s the property is applied for. '
@@ -152,7 +162,7 @@
                                              ' a global property'))
 
 
-class for_user(MetaRelationType):
+class for_user(RelationType):
     """link a property to the user which want this property customization. Unless
     you're a site manager, this relation will be handled automatically.
     """
@@ -164,9 +174,11 @@
     inlined = True
 
 
-class CWPermission(MetaEntityType):
+class CWPermission(EntityType):
     """entity type that may be used to construct some advanced security configuration
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True, maxsize=100,
                   description=_('name or identifier of the permission'))
     label = String(required=True, internationalizable=True, maxsize=100,
@@ -186,7 +198,7 @@
         'delete': ('managers',),
         }
 
-class require_group(MetaRelationType):
+class require_group(RelationType):
     """used to grant a permission to a group"""
     permissions = {
         'read':   ('managers', 'users', 'guests'),
@@ -199,20 +211,43 @@
     """generic relation to link one entity to another"""
     symetric = True
 
+class ExternalUri(EntityType):
+    """a URI representing an object in external data store"""
+    uri = String(required=True, unique=True, maxsize=256,
+                 description=_('the URI of the object'))
 
-class CWCache(MetaEntityType):
+class same_as(RelationType):
+    """generic relation to specify that an external entity represent the same
+    object as a local one:
+       http://www.w3.org/TR/owl-ref/#sameAs-def
+
+    NOTE: You'll have to explicitly declare which entity types can have a
+    same_as relation
+    """
+    permissions = {
+        'read':   ('managers', 'users', 'guests',),
+        'add':    ('managers', 'users'),
+        'delete': ('managers', 'owners'),
+        }
+    cardinality = '*1'
+    symetric = True
+    # NOTE: the 'object = ExternalUri' declaration will still be mandatory
+    #       in the cube's schema.
+    object = 'ExternalUri'
+
+class CWCache(EntityType):
     """a simple cache entity characterized by a name and
     a validity date.
 
     The target application is responsible for updating timestamp
     when necessary to invalidate the cache (typically in hooks).
 
-    Also, checkout the AppRsetObject.get_cache() method.
+    Also, checkout the AppObject.get_cache() method.
     """
     permissions = {
         'read':   ('managers', 'users', 'guests'),
         'add':    ('managers',),
-        'update': ('managers', 'users',),
+        'update': ('managers', 'users',), # XXX
         'delete': ('managers',),
         }
 
--- a/schemas/bootstrap.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schemas/bootstrap.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,36 +1,38 @@
-"""core CubicWeb schema necessary for bootstrapping the actual application's schema
+"""core CubicWeb schema necessary for bootstrapping the actual instance's schema
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+__docformat__ = "restructuredtext en"
+_ = unicode
 
-from cubicweb.schema import format_constraint
-
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            ObjectRelation, RichString, String, Boolean, Int)
+from cubicweb.schema import RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
 
 # not restricted since as "is" is handled as other relations, guests need
 # access to this
-class CWEType(MetaEntityType):
-    """define an entity type, used to build the application schema"""
+class CWEType(EntityType):
+    """define an entity type, used to build the instance schema"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
     description = RichString(internationalizable=True,
                              description=_('semantic description of this entity type'))
-    meta = Boolean(description=_('is it an application entity type or not ?'))
     # necessary to filter using RQL
     final = Boolean(description=_('automatic'))
 
 
-class CWRType(MetaEntityType):
-    """define a relation type, used to build the application schema"""
+class CWRType(EntityType):
+    """define a relation type, used to build the instance schema"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
-    description_format = String(meta=True, internationalizable=True, maxsize=50,
-                                default='text/plain', constraints=[format_constraint])
-    description = String(internationalizable=True,
-                         description=_('semantic description of this relation type'))
-    meta = Boolean(description=_('is it an application relation type or not ?'))
+    description = RichString(internationalizable=True,
+                             description=_('semantic description of this relation type'))
     symetric = Boolean(description=_('is this relation equivalent in both direction ?'))
     inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!'))
     fulltext_container = String(description=_('if full text content of subject/object entity '
@@ -40,12 +42,13 @@
     final = Boolean(description=_('automatic'))
 
 
-class CWAttribute(MetaEntityType):
+class CWAttribute(EntityType):
     """define a final relation: link a final relation type from a non final
     entity to a final entity type.
 
-    used to build the application schema
+    used to build the instance schema
     """
+    permissions = META_ETYPE_PERMS
     relation_type = SubjectRelation('CWRType', cardinality='1*',
                                     constraints=[RQLConstraint('O final TRUE')],
                                     composite='object')
@@ -67,10 +70,8 @@
     internationalizable = Boolean(description=_('is this attribute\'s value translatable'))
     defaultval = String(maxsize=256)
 
-    description_format = String(meta=True, internationalizable=True, maxsize=50,
-                                default='text/plain', constraints=[format_constraint])
-    description = String(internationalizable=True,
-                         description=_('semantic description of this attribute'))
+    description = RichString(internationalizable=True,
+                             description=_('semantic description of this attribute'))
 
 
 CARDINALITY_VOCAB = [_('?*'), _('1*'), _('+*'), _('**'),
@@ -78,12 +79,13 @@
                      _('?1'), _('11'), _('+1'), _('*1'),
                      _('??'), _('1?'), _('+?'), _('*?')]
 
-class CWRelation(MetaEntityType):
+class CWRelation(EntityType):
     """define a non final relation: link a non final relation type from a non
     final entity to a non final entity type.
 
-    used to build the application schema
+    used to build the instance schema
     """
+    permissions = META_ETYPE_PERMS
     relation_type = SubjectRelation('CWRType', cardinality='1*',
                                     constraints=[RQLConstraint('O final FALSE')],
                                     composite='object')
@@ -107,15 +109,14 @@
                        vocabulary=('', _('subject'), _('object')),
                        maxsize=8, default=None)
 
-    description_format = String(meta=True, internationalizable=True, maxsize=50,
-                                default='text/plain', constraints=[format_constraint])
-    description = String(internationalizable=True,
-                         description=_('semantic description of this relation'))
+    description = RichString(internationalizable=True,
+                             description=_('semantic description of this relation'))
 
 
 # not restricted since it has to be read when checking allowed transitions
-class RQLExpression(MetaEntityType):
+class RQLExpression(EntityType):
     """define a rql expression used to define permissions"""
+    permissions = META_ETYPE_PERMS
     exprtype = String(required=True, vocabulary=['ERQLExpression', 'RRQLExpression'])
     mainvars = String(maxsize=8,
                       description=_('name of the main variables which should be '
@@ -140,21 +141,24 @@
                                         description=_('rql expression allowing to update entities of this type'))
 
 
-class CWConstraint(MetaEntityType):
+class CWConstraint(EntityType):
     """define a schema constraint"""
+    permissions = META_ETYPE_PERMS
     cstrtype = SubjectRelation('CWConstraintType', cardinality='1*')
     value = String(description=_('depends on the constraint type'))
 
 
-class CWConstraintType(MetaEntityType):
+class CWConstraintType(EntityType):
     """define a schema constraint type"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
 
 
 # not restricted since it has to be read when checking allowed transitions
-class CWGroup(MetaEntityType):
+class CWGroup(EntityType):
     """define a CubicWeb users group"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
 
@@ -169,40 +173,55 @@
 
 
 
-class relation_type(MetaRelationType):
+class relation_type(RelationType):
     """link a relation definition to its relation type"""
-    inlined = True
-class from_entity(MetaRelationType):
-    """link a relation definition to its subject entity type"""
+    permissions = META_RTYPE_PERMS
     inlined = True
-class to_entity(MetaRelationType):
-    """link a relation definition to its object entity type"""
-    inlined = True
-class constrained_by(MetaRelationType):
-    """constraints applying on this relation"""
 
-class cstrtype(MetaRelationType):
-    """constraint factory"""
+class from_entity(RelationType):
+    """link a relation definition to its subject entity type"""
+    permissions = META_RTYPE_PERMS
     inlined = True
 
-class read_permission(MetaRelationType):
+class to_entity(RelationType):
+    """link a relation definition to its object entity type"""
+    permissions = META_RTYPE_PERMS
+    inlined = True
+
+class constrained_by(RelationType):
+    """constraints applying on this relation"""
+    permissions = META_RTYPE_PERMS
+
+class cstrtype(RelationType):
+    """constraint factory"""
+    permissions = META_RTYPE_PERMS
+    inlined = True
+
+class read_permission(RelationType):
     """core relation giving to a group the permission to read an entity or
     relation type
     """
-class add_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class add_permission(RelationType):
     """core relation giving to a group the permission to add an entity or
     relation type
     """
-class delete_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class delete_permission(RelationType):
     """core relation giving to a group the permission to delete an entity or
     relation type
     """
-class update_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class update_permission(RelationType):
     """core relation giving to a group the permission to update an entity type
     """
+    permissions = META_RTYPE_PERMS
 
 
-class is_(MetaRelationType):
+class is_(RelationType):
     """core relation indicating the type of an entity
     """
     name = 'is'
@@ -214,10 +233,10 @@
         'delete': (),
         }
     cardinality = '1*'
-    subject = '**'
+    subject = '*'
     object = 'CWEType'
 
-class is_instance_of(MetaRelationType):
+class is_instance_of(RelationType):
     """core relation indicating the types (including specialized types)
     of an entity
     """
@@ -229,10 +248,10 @@
         'delete': (),
         }
     cardinality = '+*'
-    subject = '**'
+    subject = '*'
     object = 'CWEType'
 
-class specializes(MetaRelationType):
+class specializes(RelationType):
     name = 'specializes'
     permissions = {
         'read':   ('managers', 'users', 'guests'),
--- a/schemas/workflow.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schemas/workflow.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,11 +5,20 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+__docformat__ = "restructuredtext en"
+_ = unicode
 
-class State(MetaEntityType):
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            ObjectRelation, RichString, String)
+from cubicweb.schema import RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS, HOOKS_RTYPE_PERMS
+
+class State(EntityType):
     """used to associate simple states to an entity type and/or to define
     workflows
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True,
                   maxsize=256)
     description = RichString(fulltextindexed=True, default_format='text/rest',
@@ -28,15 +37,15 @@
                                    description=_('initial state for entities of this type'))
 
 
-class Transition(MetaEntityType):
+class Transition(EntityType):
     """use to define a transition from one or multiple states to a destination
     states in workflow's definitions.
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True,
                   maxsize=256)
-    description_format = String(meta=True, internationalizable=True, maxsize=50,
-                                default='text/rest', constraints=[format_constraint])
-    description = String(fulltextindexed=True,
+    description = RichString(fulltextindexed=True,
                          description=_('semantic description of this transition'))
     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
                                 description=_('a RQL expression which should return some results, '
@@ -56,20 +65,23 @@
                                         description=_('destination state for this transition'))
 
 
-class TrInfo(MetaEntityType):
+class TrInfo(EntityType):
+    permissions = META_ETYPE_PERMS
+
     from_state = SubjectRelation('State', cardinality='?*')
     to_state = SubjectRelation('State', cardinality='1*')
-    comment_format = String(meta=True, internationalizable=True, maxsize=50,
-                            default='text/rest', constraints=[format_constraint])
-    comment = String(fulltextindexed=True)
+    comment = RichString(fulltextindexed=True)
     # get actor and date time using owned_by and creation_date
 
 
-class from_state(MetaRelationType):
+class from_state(RelationType):
+    permissions = HOOKS_RTYPE_PERMS
     inlined = True
-class to_state(MetaRelationType):
+class to_state(RelationType):
+    permissions = HOOKS_RTYPE_PERMS
     inlined = True
-class wf_info_for(MetaRelationType):
+
+class wf_info_for(RelationType):
     """link a transition information to its object"""
     permissions = {
         'read':   ('managers', 'users', 'guests',),# RRQLExpression('U has_read_permission O')),
@@ -80,30 +92,39 @@
     composite = 'object'
     fulltext_container = composite
 
-class state_of(MetaRelationType):
+class state_of(RelationType):
     """link a state to one or more entity type"""
-class transition_of(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+class transition_of(RelationType):
     """link a transition to one or more entity type"""
+    permissions = META_RTYPE_PERMS
 
-class initial_state(MetaRelationType):
+class initial_state(RelationType):
     """indicate which state should be used by default when an entity using
     states is created
     """
+    permissions = META_RTYPE_PERMS
     inlined = True
 
-class destination_state(MetaRelationType):
+class destination_state(RelationType):
     """destination state of a transition"""
+    permissions = META_RTYPE_PERMS
     inlined = True
 
-class allowed_transition(MetaRelationType):
+class allowed_transition(RelationType):
     """allowed transition from this state"""
+    permissions = META_RTYPE_PERMS
 
-class in_state(UserRelationType):
+class in_state(RelationType):
     """indicate the current state of an entity"""
-    meta = True
     # not inlined intentionnaly since when using ldap sources, user'state
     # has to be stored outside the CWUser table
-
+    inlined = False
     # add/delete perms given to managers/users, after what most of the job
     # is done by workflow enforcment
+    permissions = {
+        'read':   ('managers', 'users', 'guests',),
+        'add':    ('managers', 'users',), # XXX has_update_perm
+        'delete': ('managers', 'users',),
+        }
 
--- a/schemaviewer.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/schemaviewer.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,11 +6,11 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from logilab.common.ureports import Section, Title, Table, Link, Span, Text
 from yams.schema2dot import CARD_MAP
 
-_ = unicode
 I18NSTRINGS = [_('read'), _('add'), _('delete'), _('update'), _('order')]
 
 class SchemaViewer(object):
@@ -19,7 +19,7 @@
         self.req = req
         if req is not None:
             self.req.add_css('cubicweb.schema.css')
-            self._possible_views = req.vreg.possible_views
+            self._possible_views = req.vreg['views'].possible_views
             if not encoding:
                 encoding = req.encoding
         else:
@@ -38,8 +38,7 @@
                        klass='acl')
 
 
-    def visit_schema(self, schema, display_relations=0,
-                     skiprels=(), skipmeta=True):
+    def visit_schema(self, schema, display_relations=0, skiptypes=()):
         """get a layout for a whole schema"""
         title = Title(self.req._('Schema %s') % schema.name,
                       klass='titleUnderline')
@@ -48,21 +47,15 @@
                                            klass='titleUnderline'),))
         layout.append(esection)
         eschemas = [eschema for eschema in schema.entities()
-                    if not eschema.is_final()]
-        if skipmeta:
-            eschemas = [eschema for eschema in eschemas
-                        if not eschema.meta]
+                    if not (eschema.is_final() or eschema in skiptypes)]
         for eschema in sorted(eschemas):
-            esection.append(self.visit_entityschema(eschema, skiprels))
+            esection.append(self.visit_entityschema(eschema, skiptypes))
         if display_relations:
             title = Title(self.req._('Relations'), klass='titleUnderline')
             rsection = Section(children=(title,))
             layout.append(rsection)
             relations = [rschema for rschema in schema.relations()
-                         if not (rschema.is_final() or rschema.type in skiprels)]
-            if skipmeta:
-                relations = [rschema for rschema in relations
-                             if not rschema.meta]
+                         if not (rschema.is_final() or rschema.type in skiptypes)]
             keys = [(rschema.type, rschema) for rschema in relations]
             for key, rschema in sorted(keys):
                 relstr = self.visit_relationschema(rschema)
@@ -107,17 +100,13 @@
     def stereotype(self, name):
         return Span((' <<%s>>' % name,), klass='stereotype')
 
-    def visit_entityschema(self, eschema, skiprels=()):
+    def visit_entityschema(self, eschema, skiptypes=()):
         """get a layout for an entity schema"""
         etype = eschema.type
         layout = Section(children=' ', klass='clear')
         layout.append(Link(etype,'&nbsp;' , id=etype)) # anchor
         title = Link(self.eschema_link_url(eschema), etype)
-        if eschema.meta:
-            stereotype = self.stereotype('meta')
-            boxchild = [Section(children=(title, ' (%s)'%eschema.display_name(self.req), stereotype), klass='title')]
-        else:
-            boxchild = [Section(children=(title, ' (%s)'%eschema.display_name(self.req)), klass='title')]
+        boxchild = [Section(children=(title, ' (%s)'% eschema.display_name(self.req)), klass='title')]
         table = Table(cols=4, rheaders=1,
                       children=self._entity_attributes_data(eschema))
         boxchild.append(Section(children=(table,), klass='body'))
@@ -129,7 +118,7 @@
         rels = []
         first = True
         for rschema, targetschemas, x in eschema.relation_definitions():
-            if rschema.type in skiprels:
+            if rschema.type in skiptypes:
                 continue
             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
                 continue
--- a/selectors.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/selectors.py	Fri Aug 07 12:20:50 2009 +0200
@@ -46,15 +46,15 @@
 from warnings import warn
 
 from logilab.common.compat import all
-from logilab.common.deprecation import deprecated_function
+from logilab.common.deprecation import deprecated
 from logilab.common.interface import implements as implements_iface
 
 from yams import BASE_TYPES
 
 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
                       role, typed_eid)
-from cubicweb.vregistry import (NoSelectableObject, Selector,
-                                chainall, objectify_selector)
+# even if not used, let yes here so it's importable through this module
+from cubicweb.appobject import Selector, objectify_selector, yes
 from cubicweb.cwconfig import CubicWebConfiguration
 from cubicweb.schema import split_expression
 
@@ -165,7 +165,7 @@
             if isinstance(iface, basestring):
                 # entity type
                 try:
-                    iface = vreg.etype_class(iface)
+                    iface = vreg['etypes'].etype_class(iface)
                 except KeyError:
                     continue # entity type not in the schema
             score += score_interface(cls_or_inst, cls, iface)
@@ -212,7 +212,7 @@
     def score(self, cls, req, etype):
         if etype in BASE_TYPES:
             return 0
-        return self.score_class(cls.vreg.etype_class(etype), req)
+        return self.score_class(cls.vreg['etypes'].etype_class(etype), req)
 
     def score_class(self, eclass, req):
         raise NotImplementedError()
@@ -274,20 +274,9 @@
 
 # very basic selectors ########################################################
 
-class yes(Selector):
-    """return arbitrary score
-
-    default score of 0.5 so any other selector take precedence
-    """
-    def __init__(self, score=0.5):
-        self.score = score
-
-    def __call__(self, *args, **kwargs):
-        return self.score
-
 @objectify_selector
 @lltrace
-def none_rset(cls, req, rset=None, *args, **kwargs):
+def none_rset(cls, req, rset=None, **kwargs):
     """accept no result set (e.g. given rset is None)"""
     if rset is None:
         return 1
@@ -295,7 +284,7 @@
 
 @objectify_selector
 @lltrace
-def any_rset(cls, req, rset=None, *args, **kwargs):
+def any_rset(cls, req, rset=None, **kwargs):
     """accept result set, whatever the number of result it contains"""
     if rset is not None:
         return 1
@@ -303,7 +292,7 @@
 
 @objectify_selector
 @lltrace
-def nonempty_rset(cls, req, rset=None, *args, **kwargs):
+def nonempty_rset(cls, req, rset=None, **kwargs):
     """accept any non empty result set"""
     if rset is not None and rset.rowcount:
         return 1
@@ -311,7 +300,7 @@
 
 @objectify_selector
 @lltrace
-def empty_rset(cls, req, rset=None, *args, **kwargs):
+def empty_rset(cls, req, rset=None, **kwargs):
     """accept empty result set"""
     if rset is not None and rset.rowcount == 0:
         return 1
@@ -319,7 +308,7 @@
 
 @objectify_selector
 @lltrace
-def one_line_rset(cls, req, rset=None, row=None, *args, **kwargs):
+def one_line_rset(cls, req, rset=None, row=None, **kwargs):
     """if row is specified, accept result set with a single line of result,
     else accepts anyway
     """
@@ -329,7 +318,7 @@
 
 @objectify_selector
 @lltrace
-def two_lines_rset(cls, req, rset=None, *args, **kwargs):
+def two_lines_rset(cls, req, rset=None, **kwargs):
     """accept result set with *at least* two lines of result"""
     if rset is not None and rset.rowcount > 1:
         return 1
@@ -337,7 +326,7 @@
 
 @objectify_selector
 @lltrace
-def two_cols_rset(cls, req, rset=None, *args, **kwargs):
+def two_cols_rset(cls, req, rset=None, **kwargs):
     """accept result set with at least one line and two columns of result"""
     if rset is not None and rset.rowcount and len(rset.rows[0]) > 1:
         return 1
@@ -345,7 +334,7 @@
 
 @objectify_selector
 @lltrace
-def paginated_rset(cls, req, rset=None, *args, **kwargs):
+def paginated_rset(cls, req, rset=None, **kwargs):
     """accept result set with more lines than the page size.
 
     Page size is searched in (respecting order):
@@ -366,7 +355,7 @@
 
 @objectify_selector
 @lltrace
-def sorted_rset(cls, req, rset=None, row=None, col=0, **kwargs):
+def sorted_rset(cls, req, rset=None, **kwargs):
     """accept sorted result set"""
     rqlst = rset.syntax_tree()
     if len(rqlst.children) > 1 or not rqlst.children[0].orderby:
@@ -375,7 +364,7 @@
 
 @objectify_selector
 @lltrace
-def one_etype_rset(cls, req, rset=None, row=None, col=0, *args, **kwargs):
+def one_etype_rset(cls, req, rset=None, col=0, **kwargs):
     """accept result set where entities in the specified column (or 0) are all
     of the same type
     """
@@ -387,7 +376,7 @@
 
 @objectify_selector
 @lltrace
-def two_etypes_rset(cls, req, rset=None, row=None, col=0, **kwargs):
+def two_etypes_rset(cls, req, rset=None, col=0, **kwargs):
     """accept result set where entities in the specified column (or 0) are not
     of the same type
     """
@@ -570,9 +559,9 @@
         self.registry = registry
         self.oid = oid
 
-    def __call__(self, cls, req, rset=None, *args, **kwargs):
+    def __call__(self, cls, req, **kwargs):
         try:
-            cls.vreg.select_object(self.registry, self.oid, req, rset, *args, **kwargs)
+            cls.vreg[self.registry].select(self.oid, req, **kwargs)
             return 1
         except NoSelectableObject:
             return 0
@@ -616,10 +605,10 @@
     @lltrace
     def __call__(self, cls, req, *args, **kwargs):
         try:
-            etype = req.form['etype']
+            etype = kwargs['etype']
         except KeyError:
             try:
-                etype = kwargs['etype']
+                etype = req.form['etype']
             except KeyError:
                 return 0
         else:
@@ -630,7 +619,7 @@
                 req.form['etype'] = etype
             except KeyError:
                 return 0
-        return self.score_class(cls.vreg.etype_class(etype), req)
+        return self.score_class(cls.vreg['etypes'].etype_class(etype), req)
 
 
 class entity_implements(ImplementsMixIn, EntitySelector):
@@ -942,6 +931,7 @@
     def __repr__(self):
         return u'<rql_condition "%s" at %x>' % (self.rql, id(self))
 
+
 class but_etype(EntitySelector):
     """accept if the given entity types are not found in the result set.
 
@@ -974,87 +964,88 @@
 
 
 # XXX DEPRECATED ##############################################################
+from cubicweb.vregistry import chainall
 
-yes_selector = deprecated_function(yes)
-norset_selector = deprecated_function(none_rset)
-rset_selector = deprecated_function(any_rset)
-anyrset_selector = deprecated_function(nonempty_rset)
-emptyrset_selector = deprecated_function(empty_rset)
-onelinerset_selector = deprecated_function(one_line_rset)
-twolinerset_selector = deprecated_function(two_lines_rset)
-twocolrset_selector = deprecated_function(two_cols_rset)
-largerset_selector = deprecated_function(paginated_rset)
-sortedrset_selector = deprecated_function(sorted_rset)
-oneetyperset_selector = deprecated_function(one_etype_rset)
-multitype_selector = deprecated_function(two_etypes_rset)
-anonymous_selector = deprecated_function(anonymous_user)
-not_anonymous_selector = deprecated_function(authenticated_user)
-primaryview_selector = deprecated_function(primary_view)
-contextprop_selector = deprecated_function(match_context_prop)
+yes_selector = deprecated()(yes)
+norset_selector = deprecated()(none_rset)
+rset_selector = deprecated()(any_rset)
+anyrset_selector = deprecated()(nonempty_rset)
+emptyrset_selector = deprecated()(empty_rset)
+onelinerset_selector = deprecated()(one_line_rset)
+twolinerset_selector = deprecated()(two_lines_rset)
+twocolrset_selector = deprecated()(two_cols_rset)
+largerset_selector = deprecated()(paginated_rset)
+sortedrset_selector = deprecated()(sorted_rset)
+oneetyperset_selector = deprecated()(one_etype_rset)
+multitype_selector = deprecated()(two_etypes_rset)
+anonymous_selector = deprecated()(anonymous_user)
+not_anonymous_selector = deprecated()(authenticated_user)
+primaryview_selector = deprecated()(primary_view)
+contextprop_selector = deprecated()(match_context_prop)
 
+@deprecated('use non_final_entity instead of %s')
 def nfentity_selector(cls, req, rset=None, row=None, col=0, **kwargs):
     return non_final_entity()(cls, req, rset, row, col)
-nfentity_selector = deprecated_function(nfentity_selector)
 
+@deprecated('use implements instead of %s')
 def implement_interface(cls, req, rset=None, row=None, col=0, **kwargs):
     return implements(*cls.accepts_interfaces)(cls, req, rset, row, col)
-_interface_selector = deprecated_function(implement_interface)
-interface_selector = deprecated_function(implement_interface)
-implement_interface = deprecated_function(implement_interface, 'use implements')
+_interface_selector = deprecated()(implement_interface)
+interface_selector = deprecated()(implement_interface)
 
+@deprecated('use specified_etype_implements instead of %s')
 def accept_etype(cls, req, *args, **kwargs):
     """check etype presence in request form *and* accepts conformance"""
     return specified_etype_implements(*cls.accepts)(cls, req, *args)
-etype_form_selector = deprecated_function(accept_etype)
-accept_etype = deprecated_function(accept_etype, 'use specified_etype_implements')
+etype_form_selector = accept_etype
 
+@deprecated('use match_search_state instead of %s')
 def searchstate_selector(cls, req, rset=None, row=None, col=0, **kwargs):
     return match_search_state(cls.search_states)(cls, req, rset, row, col)
-searchstate_selector = deprecated_function(searchstate_selector)
 
+@deprecated('use match_user_groups instead of %s')
 def match_user_group(cls, req, rset=None, row=None, col=0, **kwargs):
     return match_user_groups(*cls.require_groups)(cls, req, rset, row, col, **kwargs)
-in_group_selector = deprecated_function(match_user_group)
-match_user_group = deprecated_function(match_user_group)
+in_group_selector = match_user_group
 
+@deprecated('use relation_possible instead of %s')
 def has_relation(cls, req, rset=None, row=None, col=0, **kwargs):
     return relation_possible(cls.rtype, role(cls), cls.etype,
                              getattr(cls, 'require_permission', 'read'))(cls, req, rset, row, col, **kwargs)
-has_relation = deprecated_function(has_relation)
 
+@deprecated('use relation_possible instead of %s')
 def one_has_relation(cls, req, rset=None, row=None, col=0, **kwargs):
     return relation_possible(cls.rtype, role(cls), cls.etype,
                              getattr(cls, 'require_permission', 'read',
                                      once_is_enough=True))(cls, req, rset, row, col, **kwargs)
-one_has_relation = deprecated_function(one_has_relation, 'use relation_possible selector')
 
+@deprecated('use implements instead of %s')
 def accept_rset(cls, req, rset=None, row=None, col=0, **kwargs):
     """simply delegate to cls.accept_rset method"""
     return implements(*cls.accepts)(cls, req, rset, row=row, col=col)
-accept_rset_selector = deprecated_function(accept_rset)
-accept_rset = deprecated_function(accept_rset, 'use implements selector')
+accept_rset_selector = accept_rset
 
 accept = chainall(non_final_entity(), accept_rset, name='accept')
-accept_selector = deprecated_function(accept)
-accept = deprecated_function(accept, 'use implements selector')
+accept = deprecated('use implements selector')(accept)
+accept_selector = deprecated()(accept)
 
-accept_one = deprecated_function(chainall(one_line_rset, accept,
-                                          name='accept_one'))
-accept_one_selector = deprecated_function(accept_one)
+accept_one = deprecated()(chainall(one_line_rset, accept,
+                                   name='accept_one'))
+accept_one_selector = deprecated()(accept_one)
 
 
 def _rql_condition(cls, req, rset=None, row=None, col=0, **kwargs):
     if cls.condition:
         return rql_condition(cls.condition)(cls, req, rset, row, col)
     return 1
-_rqlcondition_selector = deprecated_function(_rql_condition)
+_rqlcondition_selector = deprecated()(_rql_condition)
 
-rqlcondition_selector = deprecated_function(chainall(non_final_entity(), one_line_rset, _rql_condition,
+rqlcondition_selector = deprecated()(chainall(non_final_entity(), one_line_rset, _rql_condition,
                          name='rql_condition'))
 
+@deprecated('use but_etype instead of %s')
 def but_etype_selector(cls, req, rset=None, row=None, col=0, **kwargs):
     return but_etype(cls.etype)(cls, req, rset, row, col)
-but_etype_selector = deprecated_function(but_etype_selector)
 
 @lltrace
 def etype_rtype_selector(cls, req, rset=None, row=None, col=0, **kwargs):
@@ -1069,24 +1060,25 @@
         if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
             return 0
     return 1
-etype_rtype_selector = deprecated_function(etype_rtype_selector)
+etype_rtype_selector = deprecated()(etype_rtype_selector)
 
-#req_form_params_selector = deprecated_function(match_form_params) # form_params
-#kwargs_selector = deprecated_function(match_kwargs) # expected_kwargs
+#req_form_params_selector = deprecated()(match_form_params) # form_params
+#kwargs_selector = deprecated()(match_kwargs) # expected_kwargs
 
 # compound selectors ##########################################################
 
 searchstate_accept = chainall(nonempty_rset(), accept,
                               name='searchstate_accept')
-searchstate_accept_selector = deprecated_function(searchstate_accept)
+searchstate_accept_selector = deprecated()(searchstate_accept)
 
 searchstate_accept_one = chainall(one_line_rset, accept, _rql_condition,
                                   name='searchstate_accept_one')
-searchstate_accept_one_selector = deprecated_function(searchstate_accept_one)
+searchstate_accept_one_selector = deprecated()(searchstate_accept_one)
 
-searchstate_accept = deprecated_function(searchstate_accept)
-searchstate_accept_one = deprecated_function(searchstate_accept_one)
+searchstate_accept = deprecated()(searchstate_accept)
+searchstate_accept_one = deprecated()(searchstate_accept_one)
 
+# end of deprecation section ##################################################
 
 def unbind_method(selector):
     def new_selector(registered):
--- a/server/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,9 +14,78 @@
 from os.path import join, exists
 
 from logilab.common.modutils import LazyObject
+from logilab.common.textutils import splitstrip
 
-# server debugging flag
-DEBUG = False
+# server-side debugging #########################################################
+
+# server debugging flags. They may be combined using binary operators.
+DBG_NONE = 0 # no debug information
+DBG_RQL = 1  # rql execution information
+DBG_SQL = 2  # executed sql
+DBG_REPO = 4 # repository events
+DBG_MORE = 8 # repository events
+
+# current debug mode
+DEBUG = 0
+
+def set_debug(debugmode):
+    """change the repository debugging mode"""
+    global DEBUG
+    if not debugmode:
+        DEBUG = 0
+        return
+    if isinstance(debugmode, basestring):
+        for mode in splitstrip(debugmode, sep='|'):
+            DEBUG |= globals()[mode]
+    else:
+        DEBUG |= debugmode
+
+
+class debugged(object):
+    """repository debugging context manager / decorator
+
+    Can be used either as a context manager:
+
+    >>> with debugged(server.DBG_RQL | server.DBG_REPO):
+    ...     # some code in which you want to debug repository activity,
+    ...     # seing information about RQL being executed an repository events.
+
+    or as a function decorator:
+
+    >>> @debugged(server.DBG_RQL | server.DBG_REPO)
+    ... def some_function():
+    ...     # some code in which you want to debug repository activity,
+    ...     # seing information about RQL being executed an repository events
+
+    debug mode will be reseted at its original value when leaving the "with"
+    block or the decorated function
+    """
+    def __init__(self, debugmode):
+        self.debugmode = debugmode
+        self._clevel = None
+
+    def __enter__(self):
+        """enter with block"""
+        self._clevel = DEBUG
+        set_debug(self.debugmode)
+
+    def __exit__(self, exctype, exc, traceback):
+        """leave with block"""
+        set_debug(self._clevel)
+        return traceback is None
+
+    def __call__(self, func):
+        """decorate function"""
+        def wrapped(*args, **kwargs):
+            _clevel = DEBUG
+            set_debug(self.debugmode)
+            try:
+                return func(*args, **kwargs)
+            finally:
+                set_debug(self._clevel)
+        return wrapped
+
+# database initialization ######################################################
 
 def init_repository(config, interactive=True, drop=False, vreg=None):
     """initialise a repository database by creating tables add filling them
@@ -24,16 +93,16 @@
     a initial user)
     """
     from glob import glob
-    from cubicweb.schema import BASEGROUPS
+    from yams import BASE_GROUPS
     from cubicweb.dbapi import in_memory_cnx
     from cubicweb.server.repository import Repository
     from cubicweb.server.utils import manager_userpasswd
     from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema
     # configuration to avoid db schema loading and user'state checking
     # on connection
-    read_application_schema = config.read_application_schema
+    read_instance_schema = config.read_instance_schema
     bootstrap_schema = config.bootstrap_schema
-    config.read_application_schema = False
+    config.read_instance_schema = False
     config.creating = True
     config.bootstrap_schema = True
     config.consider_user_state = False
@@ -92,11 +161,12 @@
         else:
             login, pwd = unicode(source['db-user']), source['db-password']
     print '-> inserting default user and default groups.'
-    for group in BASEGROUPS:
-        rset = session.execute('INSERT CWGroup X: X name %(name)s',
-                               {'name': unicode(group)})
-    rset = session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s',
-                           {'login': login, 'pwd': pwd})
+    # sort for eid predicatability as expected in some server tests
+    for group in sorted(BASE_GROUPS):
+        session.execute('INSERT CWGroup X: X name %(name)s',
+                        {'name': unicode(group)})
+    session.execute('INSERT CWUser X: X login %(login)s, X upassword %(pwd)s',
+                    {'login': login, 'pwd': pwd})
     session.execute('SET U in_group G WHERE G name "managers"')
     session.commit()
     # reloging using the admin user
@@ -136,11 +206,11 @@
     session.close()
     # restore initial configuration
     config.creating = False
-    config.read_application_schema = read_application_schema
+    config.read_instance_schema = read_instance_schema
     config.bootstrap_schema = bootstrap_schema
     config.consider_user_state = True
     config.set_language = True
-    print '-> database for application %s initialized.' % config.appid
+    print '-> database for instance %s initialized.' % config.appid
 
 
 def initialize_schema(config, schema, mhandler, event='create'):
@@ -152,7 +222,7 @@
     # execute cubes pre<event> script if any
     for path in reversed(paths):
         mhandler.exec_event_script('pre%s' % event, path)
-    # enter application'schema into the database
+    # enter instance'schema into the database
     serialize_schema(mhandler.rqlcursor, schema)
     # execute cubicweb's post<event> script
     mhandler.exec_event_script('post%s' % event)
@@ -160,20 +230,6 @@
     for path in reversed(paths):
         mhandler.exec_event_script('post%s' % event, path)
 
-def set_debug(debugmode):
-    global DEBUG
-    DEBUG = debugmode
-
-def debugged(func):
-    """decorator to activate debug mode"""
-    def wrapped(*args, **kwargs):
-        global DEBUG
-        DEBUG = True
-        try:
-            return func(*args, **kwargs)
-        finally:
-            DEBUG = False
-    return wrapped
 
 # sqlite'stored procedures have to be registered at connexion opening time
 SQL_CONNECT_HOOKS = {}
--- a/server/checkintegrity.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/checkintegrity.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,6 +13,7 @@
 
 from logilab.common.shellutils import ProgressBar
 
+from cubicweb.schema import PURE_VIRTUAL_RTYPES
 from cubicweb.server.sqlutils import SQL_PREFIX
 
 def has_eid(sqlcursor, eid, eids):
@@ -196,9 +197,7 @@
     """check all relations registered in the repo system table"""
     print 'Checking relations'
     for rschema in schema.relations():
-        if rschema.is_final():
-            continue
-        if rschema == 'identity':
+        if rschema.is_final() or rschema in PURE_VIRTUAL_RTYPES:
             continue
         if rschema.inlined:
             for subjtype in rschema.subjects():
@@ -282,7 +281,7 @@
 
 
 def check(repo, cnx, checks, reindex, fix):
-    """check integrity of application's repository,
+    """check integrity of instance's repository,
     using given user and password to locally connect to the repository
     (no running cubicweb server needed)
     """
--- a/server/hookhelper.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/hookhelper.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,9 +17,7 @@
 
 def entity_attr(session, eid, attr):
     """return an arbitrary attribute of the entity with the given eid"""
-    rset = session.execute('Any N WHERE X eid %%(x)s, X %s N' % attr,
-                           {'x': eid}, 'x')
-    return rset[0][0]
+    return getattr(session.entity_from_eid(eid), attr)
 
 def rproperty(session, rtype, eidfrom, eidto, rprop):
     rschema = session.repo.schema[rtype]
@@ -76,6 +74,8 @@
     relation hooks, the relation may has been deleted at this point, so
     we have handle that
     """
+    if eid in session.transaction_data.get('neweids', ()):
+        return
     pending = session.transaction_data.get('pendingrelations', ())
     for eidfrom, rtype, eidto in reversed(pending):
         if rtype == 'in_state' and eidfrom == eid:
--- a/server/hooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/hooks.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,66 +17,89 @@
                                      get_user_sessions, rproperty)
 from cubicweb.server.repository import FTIndexEntityOp
 
+# special relations that don't have to be checked for integrity, usually
+# because they are handled internally by hooks (so we trust ourselves)
+DONT_CHECK_RTYPES_ON_ADD = set(('owned_by', 'created_by',
+                                'is', 'is_instance_of',
+                                'wf_info_for', 'from_state', 'to_state'))
+DONT_CHECK_RTYPES_ON_DEL = set(('is', 'is_instance_of',
+                                'wf_info_for', 'from_state', 'to_state'))
+
+
 def relation_deleted(session, eidfrom, rtype, eidto):
     session.transaction_data.setdefault('pendingrelations', []).append(
         (eidfrom, rtype, eidto))
 
+def eschema_type_eid(session, etype):
+    """get eid of the CWEType entity for the given yams type"""
+    eschema = session.repo.schema.eschema(etype)
+    # eschema.eid is None if schema has been readen from the filesystem, not
+    # from the database (eg during tests)
+    if eschema.eid is None:
+        eschema.eid = session.unsafe_execute(
+            'Any X WHERE X is CWEType, X name %(name)s', {'name': etype})[0][0]
+    return eschema.eid
 
-# base meta-data handling #####################################################
+
+# base meta-data handling ######################################################
 
 def setctime_before_add_entity(session, entity):
     """before create a new entity -> set creation and modification date
 
     this is a conveniency hook, you shouldn't have to disable it
     """
-    if not 'creation_date' in entity:
-        entity['creation_date'] = datetime.now()
-    if not 'modification_date' in entity:
-        entity['modification_date'] = datetime.now()
+    timestamp = datetime.now()
+    entity.setdefault('creation_date', timestamp)
+    entity.setdefault('modification_date', timestamp)
+    if not session.get_shared_data('do-not-insert-cwuri'):
+        entity.setdefault('cwuri', u'%seid/%s' % (session.base_url(), entity.eid))
+
 
 def setmtime_before_update_entity(session, entity):
     """update an entity -> set modification date"""
-    if not 'modification_date' in entity:
-        entity['modification_date'] = datetime.now()
+    entity.setdefault('modification_date', datetime.now())
+
 
 class SetCreatorOp(PreCommitOperation):
 
     def precommit_event(self):
-        if self.eid in self.session.transaction_data.get('pendingeids', ()):
+        session = self.session
+        if self.entity.eid in session.transaction_data.get('pendingeids', ()):
             # entity have been created and deleted in the same transaction
             return
-        ueid = self.session.user.eid
-        execute = self.session.unsafe_execute
-        if not execute('Any X WHERE X created_by U, X eid %(x)s',
-                       {'x': self.eid}, 'x'):
-            execute('SET X created_by U WHERE X eid %(x)s, U eid %(u)s',
-                    {'x': self.eid, 'u': ueid}, 'x')
+        if not self.entity.created_by:
+            session.add_relation(self.entity.eid, 'created_by', session.user.eid)
+
 
 def setowner_after_add_entity(session, entity):
     """create a new entity -> set owner and creator metadata"""
     asession = session.actual_session()
     if not asession.is_internal_session:
-        session.unsafe_execute('SET X owned_by U WHERE X eid %(x)s, U eid %(u)s',
-                               {'x': entity.eid, 'u': asession.user.eid}, 'x')
-        SetCreatorOp(asession, eid=entity.eid)
+        session.add_relation(entity.eid, 'owned_by', asession.user.eid)
+        SetCreatorOp(asession, entity=entity)
+
 
 def setis_after_add_entity(session, entity):
     """create a new entity -> set is relation"""
     if hasattr(entity, '_cw_recreating'):
         return
-    session.unsafe_execute('SET X is E WHERE X eid %(x)s, E name %(name)s',
-                           {'x': entity.eid, 'name': entity.id}, 'x')
+    try:
+        session.add_relation(entity.eid, 'is',
+                             eschema_type_eid(session, entity.id))
+    except IndexError:
+        # during schema serialization, skip
+        return
     # XXX < 2.50 bw compat
     if not session.get_shared_data('do-not-insert-is_instance_of'):
-        basetypes = entity.e_schema.ancestors() + [entity.e_schema]
-        session.unsafe_execute('SET X is_instance_of E WHERE X eid %%(x)s, E name IN (%s)' %
-                               ','.join("'%s'" % str(etype) for etype in basetypes),
-                               {'x': entity.eid}, 'x')
+        for etype in entity.e_schema.ancestors() + [entity.e_schema]:
+            session.add_relation(entity.eid, 'is_instance_of',
+                                 eschema_type_eid(session, etype))
+
 
 def setowner_after_add_user(session, entity):
     """when a user has been created, add owned_by relation on itself"""
-    session.unsafe_execute('SET X owned_by X WHERE X eid %(x)s',
-                           {'x': entity.eid}, 'x')
+    session.add_relation(entity.eid, 'owned_by', entity.eid)
+
 
 def fti_update_after_add_relation(session, eidfrom, rtype, eidto):
     """sync fulltext index when relevant relation is added. Reindexing the
@@ -88,6 +111,8 @@
         FTIndexEntityOp(session, entity=session.entity_from_eid(eidto))
     elif ftcontainer == 'object':
         FTIndexEntityOp(session, entity=session.entity_from_eid(eidfrom))
+
+
 def fti_update_after_delete_relation(session, eidfrom, rtype, eidto):
     """sync fulltext index when relevant relation is deleted. Reindexing both
     entities is necessary.
@@ -96,6 +121,7 @@
         FTIndexEntityOp(session, entity=session.entity_from_eid(eidto))
         FTIndexEntityOp(session, entity=session.entity_from_eid(eidfrom))
 
+
 class SyncOwnersOp(PreCommitOperation):
 
     def precommit_event(self):
@@ -104,12 +130,13 @@
                                     {'c': self.compositeeid, 'x': self.composedeid},
                                     ('c', 'x'))
 
+
 def sync_owner_after_add_composite_relation(session, eidfrom, rtype, eidto):
     """when adding composite relation, the composed should have the same owners
     has the composite
     """
     if rtype == 'wf_info_for':
-        # skip this special composite relation
+        # skip this special composite relation # XXX (syt) why?
         return
     composite = rproperty(session, rtype, eidfrom, eidto, 'composite')
     if composite == 'subject':
@@ -117,6 +144,7 @@
     elif composite == 'object':
         SyncOwnersOp(session, compositeeid=eidto, composedeid=eidfrom)
 
+
 def _register_metadata_hooks(hm):
     """register meta-data related hooks on the hooks manager"""
     hm.register_hook(setctime_before_add_entity, 'before_add_entity', '')
@@ -130,6 +158,7 @@
     if 'CWUser' in hm.schema:
         hm.register_hook(setowner_after_add_user, 'after_add_entity', 'CWUser')
 
+
 # core hooks ##################################################################
 
 class DelayedDeleteOp(PreCommitOperation):
@@ -139,12 +168,15 @@
 
     def precommit_event(self):
         session = self.session
-        if not self.eid in session.transaction_data.get('pendingeids', ()):
+        # don't do anything if the entity is being created or deleted
+        if not (self.eid in session.transaction_data.get('pendingeids', ()) or
+                self.eid in session.transaction_data.get('neweids', ())):
             etype = session.describe(self.eid)[0]
             session.unsafe_execute('DELETE %s X WHERE X eid %%(x)s, NOT %s'
                                    % (etype, self.relation),
                                    {'x': self.eid}, 'x')
 
+
 def handle_composite_before_del_relation(session, eidfrom, rtype, eidto):
     """delete the object of composite relation"""
     composite = rproperty(session, rtype, eidfrom, eidto, 'composite')
@@ -153,6 +185,7 @@
     elif composite == 'object':
         DelayedDeleteOp(session, eid=eidfrom, relation='X %s Y' % rtype)
 
+
 def before_del_group(session, eid):
     """check that we don't remove the owners group"""
     check_internal_entity(session, eid, ('owners',))
@@ -182,6 +215,7 @@
     def commit_event(self):
         pass
 
+
 def cstrcheck_after_add_relation(session, eidfrom, rtype, eidto):
     """check the relation satisfy its constraints
 
@@ -207,9 +241,6 @@
                 raise ValidationError(entity.eid, {attr: msg % val})
 
 
-
-
-
 class CheckRequiredRelationOperation(LateOperation):
     """checking relation cardinality has to be done after commit in
     case the relation is being replaced
@@ -224,9 +255,8 @@
             etype = self.session.describe(self.eid)[0]
             _ = self.session._
             msg = _('at least one relation %(rtype)s is required on %(etype)s (%(eid)s)')
-            raise ValidationError(self.eid, {self.rtype: msg % {'rtype': _(self.rtype),
-                                                                'etype': _(etype),
-                                                                'eid': self.eid}})
+            msg %= {'rtype': _(self.rtype), 'etype': _(etype), 'eid': self.eid}
+            raise ValidationError(self.eid, {self.rtype: msg})
 
     def commit_event(self):
         pass
@@ -234,16 +264,19 @@
     def _rql(self):
         raise NotImplementedError()
 
+
 class CheckSRelationOp(CheckRequiredRelationOperation):
     """check required subject relation"""
     def _rql(self):
         return 'Any O WHERE S eid %%(x)s, S %s O' % self.rtype, {'x': self.eid}, 'x'
 
+
 class CheckORelationOp(CheckRequiredRelationOperation):
     """check required object relation"""
     def _rql(self):
         return 'Any S WHERE O eid %%(x)s, S %s O' % self.rtype, {'x': self.eid}, 'x'
 
+
 def checkrel_if_necessary(session, opcls, rtype, eid):
     """check an equivalent operation has not already been added"""
     for op in session.pending_operations:
@@ -252,12 +285,13 @@
     else:
         opcls(session, rtype=rtype, eid=eid)
 
+
 def cardinalitycheck_after_add_entity(session, entity):
     """check cardinalities are satisfied"""
     eid = entity.eid
     for rschema, targetschemas, x in entity.e_schema.relation_definitions():
         # skip automatically handled relations
-        if rschema.type in ('owned_by', 'created_by', 'is', 'is_instance_of'):
+        if rschema.type in DONT_CHECK_RTYPES_ON_ADD:
             continue
         if x == 'subject':
             subjtype = entity.e_schema
@@ -273,8 +307,11 @@
         if card[cardindex] in '1+':
             checkrel_if_necessary(session, opcls, rschema.type, eid)
 
+
 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
     """check cardinalities are satisfied"""
+    if rtype in DONT_CHECK_RTYPES_ON_DEL:
+        return
     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
     pendingeids = session.transaction_data.get('pendingeids', ())
     if card[0] in '1+' and not eidfrom in pendingeids:
@@ -311,6 +348,7 @@
         Operation.__init__(self, session, *args, **kwargs)
         self.group = result[0][0]
 
+
 class DeleteGroupOp(GroupOperation):
     """synchronize user when a in_group relation has been deleted"""
     def commit_event(self):
@@ -322,6 +360,7 @@
             self.error('user %s not in group %s',  self.cnxuser, self.group)
             return
 
+
 def after_del_in_group(session, fromeid, rtype, toeid):
     """modify user permission, need to update users"""
     for session_ in get_user_sessions(session.repo, fromeid):
@@ -339,6 +378,7 @@
             return
         groups.add(self.group)
 
+
 def after_add_in_group(session, fromeid, rtype, toeid):
     """modify user permission, need to update users"""
     for session_ in get_user_sessions(session.repo, fromeid):
@@ -358,11 +398,13 @@
         except BadConnectionId:
             pass # already closed
 
+
 def after_del_user(session, eid):
     """modify user permission, need to update users"""
     for session_ in get_user_sessions(session.repo, eid):
         DelUserOp(session, session_.id)
 
+
 def _register_usergroup_hooks(hm):
     """register user/group related hooks on the hooks manager"""
     hm.register_hook(after_del_user, 'after_delete_entity', 'CWUser')
@@ -421,19 +463,20 @@
     def precommit_event(self):
         session = self.session
         entity = self.entity
-        rset = session.execute('Any S WHERE ET initial_state S, ET name %(name)s',
-                               {'name': str(entity.e_schema)})
         # if there is an initial state and the entity's state is not set,
         # use the initial state as a default state
         pendingeids = session.transaction_data.get('pendingeids', ())
-        if rset and not entity.eid in pendingeids and not entity.in_state:
-            session.unsafe_execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
-                                   {'x' : entity.eid, 's' : rset[0][0]}, 'x')
+        if not entity.eid in pendingeids and not entity.in_state:
+            rset = session.execute('Any S WHERE ET initial_state S, ET name %(name)s',
+                                   {'name': entity.id})
+            if rset:
+                session.add_relation(entity.eid, 'in_state', rset[0][0])
 
 
 def set_initial_state_after_add(session, entity):
     SetInitialStateOp(session, entity=entity)
 
+
 def _register_wf_hooks(hm):
     """register workflow related hooks on the hooks manager"""
     if 'in_state' in hm.schema:
@@ -458,6 +501,7 @@
         except KeyError:
             self.error('%s has no associated value', self.key)
 
+
 class ChangeCWPropertyOp(Operation):
     """a user's custom properties has been added/changed"""
 
@@ -465,6 +509,7 @@
         """the observed connections pool has been commited"""
         self.epropdict[self.key] = self.value
 
+
 class AddCWPropertyOp(Operation):
     """a user's custom properties has been added/changed"""
 
@@ -475,6 +520,7 @@
             self.repo.vreg.eprop_values[eprop.pkey] = eprop.value
         # if for_user is set, update is handled by a ChangeCWPropertyOp operation
 
+
 def after_add_eproperty(session, entity):
     key, value = entity.pkey, entity.value
     try:
@@ -484,12 +530,15 @@
     except ValueError, ex:
         raise ValidationError(entity.eid, {'value': session._(str(ex))})
     if not session.user.matching_groups('managers'):
-        session.unsafe_execute('SET P for_user U WHERE P eid %(x)s,U eid %(u)s',
-                               {'x': entity.eid, 'u': session.user.eid}, 'x')
+        session.add_relation(entity.eid, 'for_user', session.user.eid)
     else:
         AddCWPropertyOp(session, eprop=entity)
 
+
 def after_update_eproperty(session, entity):
+    if not ('pkey' in entity.edited_attributes or
+            'value' in entity.edited_attributes):
+        return
     key, value = entity.pkey, entity.value
     try:
         value = session.vreg.typed_value(key, value)
@@ -506,6 +555,7 @@
         ChangeCWPropertyOp(session, epropdict=session.vreg.eprop_values,
                           key=key, value=value)
 
+
 def before_del_eproperty(session, eid):
     for eidfrom, rtype, eidto in session.transaction_data.get('pendingrelations', ()):
         if rtype == 'for_user' and eidfrom == eid:
@@ -516,6 +566,7 @@
                               {'x': eid}, 'x')[0][0]
         DelCWPropertyOp(session, epropdict=session.vreg.eprop_values, key=key)
 
+
 def after_add_for_user(session, fromeid, rtype, toeid):
     if not session.describe(fromeid)[0] == 'CWProperty':
         return
@@ -528,6 +579,7 @@
         ChangeCWPropertyOp(session, epropdict=session_.user.properties,
                           key=key, value=value)
 
+
 def before_del_for_user(session, fromeid, rtype, toeid):
     key = session.execute('Any K WHERE P eid %(x)s, P pkey K',
                           {'x': fromeid}, 'x')[0][0]
@@ -535,6 +587,7 @@
     for session_ in get_user_sessions(session.repo, toeid):
         DelCWPropertyOp(session, epropdict=session_.user.properties, key=key)
 
+
 def _register_eproperty_hooks(hm):
     """register workflow related hooks on the hooks manager"""
     hm.register_hook(after_add_eproperty, 'after_add_entity', 'CWProperty')
--- a/server/hooksmanager.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/hooksmanager.py	Fri Aug 07 12:20:50 2009 +0200
@@ -34,7 +34,8 @@
                   'before_delete_entity', 'after_delete_entity')
 RELATIONS_HOOKS = ('before_add_relation',   'after_add_relation' ,
                    'before_delete_relation','after_delete_relation')
-SYSTEM_HOOKS = ('server_startup', 'server_shutdown',
+SYSTEM_HOOKS = ('server_backup', 'server_restore',
+                'server_startup', 'server_shutdown',
                 'session_open', 'session_close')
 
 ALL_HOOKS = frozenset(ENTITIES_HOOKS + RELATIONS_HOOKS + SYSTEM_HOOKS)
@@ -65,10 +66,11 @@
     def register_hook(self, function, event, etype=''):
         """register a function to call when <event> occurs
 
-         <etype> is an entity/relation type or an empty string.
-         If etype is the empty string, the function will be called at each
-         event, else the function will be called only when event occurs on an
-         entity/relation of the given type.
+        <etype> is an entity/relation type or an empty string.
+
+        If etype is the empty string, the function will be called at each event,
+        else the function will be called only when event occurs on an entity or
+        relation of the given type.
         """
         assert event in ALL_HOOKS, '%r NOT IN %r' % (event, ALL_HOOKS)
         assert (not event in SYSTEM_HOOKS or not etype), (event, etype)
@@ -82,19 +84,28 @@
             self.error('can\'t register hook %s on %s (%s)',
                        event, etype or 'any', function.func_name)
 
-    def unregister_hook(self, function, event, etype=''):
-        """register a function to call when <event> occurs
-
-        <etype> is an entity/relation type or an empty string.
-        If etype is the empty string, the function will be called at each
-        event, else the function will be called only when event occurs on an
-        entity/relation of the given type.
+    def unregister_hook(self, function_or_cls, event=None, etype=''):
+        """unregister a function to call when <event> occurs, or a Hook subclass.
+        In the later case, event/type information are extracted from the given
+        class.
         """
-        assert event in ALL_HOOKS, event
-        etype = etype or ''
-        self.info('unregister hook %s on %s (%s)', event, etype,
-                  function.func_name)
-        self._hooks[event][etype].remove(function)
+        if isinstance(function_or_cls, type) and issubclass(function_or_cls, Hook):
+            for event, ertype in function_or_cls.register_to():
+                for hook in self._hooks[event][ertype]:
+                    if getattr(hook, 'im_self', None).__class__ is function_or_cls:
+                        self._hooks[event][ertype].remove(hook)
+                        self.info('unregister hook %s on %s (%s)', event, etype,
+                                  function_or_cls.__name__)
+                        break
+                else:
+                    self.warning("can't unregister hook %s on %s (%s), not found",
+                                 event, etype, function_or_cls.__name__)
+        else:
+            assert event in ALL_HOOKS, event
+            etype = etype or ''
+            self.info('unregister hook %s on %s (%s)', event, etype,
+                      function_or_cls.func_name)
+            self._hooks[event][etype].remove(function_or_cls)
 
     def call_hooks(self, __event, __type='', *args, **kwargs):
         """call hook matching event and optional type"""
@@ -220,9 +231,9 @@
                '%s: events is expected to be a tuple, not %s' % (
             cls, type(cls.events))
         for event in cls.events:
-            if event == 'server_startup':
+            if event in SYSTEM_HOOKS:
                 assert not cls.accepts or cls.accepts == ('Any',), \
-                       '%s doesnt make sense on server_startup' % cls.accepts
+                       '%s doesnt make sense on %s' % (cls.accepts, event)
                 cls.accepts = ('Any',)
             for ertype in cls.accepts:
                 if (event, ertype) in done:
--- a/server/migractions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/migractions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -22,7 +22,7 @@
 from os.path import join, exists
 from datetime import datetime
 
-from logilab.common.deprecation import deprecated_function, obsolete
+from logilab.common.deprecation import deprecated
 from logilab.common.decorators import cached, clear_cache
 from logilab.common.adbh import get_adv_func_helper
 
@@ -30,7 +30,7 @@
 from yams.schema2sql import eschema2sql, rschema2sql
 
 from cubicweb import AuthenticationError, ETYPE_NAME_MAP
-from cubicweb.schema import CubicWebRelationSchema
+from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CubicWebRelationSchema
 from cubicweb.dbapi import get_repository, repo_connect
 from cubicweb.common.migration import MigrationHelper, yes
 
@@ -109,61 +109,26 @@
 
     def backup_database(self, backupfile=None, askconfirm=True):
         config = self.config
-        source = config.sources()['system']
-        helper = get_adv_func_helper(source['db-driver'])
-        date = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
-        app = config.appid
-        backupfile = backupfile or join(config.backup_dir(),
-                                        '%s-%s.dump' % (app, date))
-        if exists(backupfile):
-            if not self.confirm('a backup already exists for %s, overwrite it?' % app):
-                return
-        elif askconfirm and not self.confirm('backup %s database?' % app):
-            return
-        cmd = helper.backup_command(source['db-name'], source.get('db-host'),
-                                    source.get('db-user'), backupfile,
-                                    keepownership=False)
-        while True:
-            print cmd
-            if os.system(cmd):
-                print 'error while backuping the base'
-                answer = self.confirm('continue anyway?',
-                                      shell=False, abort=False, retry=True)
-                if not answer:
-                    raise SystemExit(1)
-                if answer == 1: # 1: continue, 2: retry
-                    break
-            else:
-                from cubicweb.toolsutils import restrict_perms_to_user
-                print 'database backup:', backupfile
-                restrict_perms_to_user(backupfile, self.info)
-                break
+        repo = self.repo_connect()
+        timestamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
+        for source in repo.sources:
+            source.backup(self.confirm, backupfile, timestamp,
+                          askconfirm=askconfirm)
+        repo.hm.call_hooks('server_backup', repo=repo, timestamp=timestamp)
 
-    def restore_database(self, backupfile, drop=True):
+    def restore_database(self, backupfile, drop=True, systemonly=True,
+                         askconfirm=True):
         config = self.config
-        source = config.sources()['system']
-        helper = get_adv_func_helper(source['db-driver'])
-        app = config.appid
-        if not exists(backupfile):
-            raise Exception("backup file %s doesn't exist" % backupfile)
-        if self.confirm('restore %s database from %s ?' % (app, backupfile)):
-            for cmd in helper.restore_commands(source['db-name'], source.get('db-host'),
-                                               source.get('db-user'), backupfile,
-                                               source['db-encoding'],
-                                               keepownership=False, drop=drop):
-                while True:
-                    print cmd
-                    if os.system(cmd):
-                        print 'error while restoring the base'
-                        answer = self.confirm('continue anyway?',
-                                              shell=False, abort=False, retry=True)
-                        if not answer:
-                            raise SystemExit(1)
-                        if answer == 1: # 1: continue, 2: retry
-                            break
-                    else:
-                        break
-            print 'database restored'
+        repo = self.repo_connect()
+        if systemonly:
+            repo.system_source.restore(self.confirm, backupfile=backupfile,
+                                       drop=drop, askconfirm=askconfirm)
+        else:
+            # in that case, backup file is expected to be a time stamp
+            for source in repo.sources:
+                source.backup(self.confirm, timestamp=backupfile, drop=drop,
+                              askconfirm=askconfirm)
+            repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
 
     @property
     def cnx(self):
@@ -234,9 +199,9 @@
                         'fsschema': self.fs_schema,
                         'session' : self.session,
                         'repo' : self.repo,
-                        'synchronize_schema': deprecated_function(self.cmd_sync_schema_props_perms),
-                        'synchronize_eschema': deprecated_function(self.cmd_sync_schema_props_perms),
-                        'synchronize_rschema': deprecated_function(self.cmd_sync_schema_props_perms),
+                        'synchronize_schema': deprecated()(self.cmd_sync_schema_props_perms),
+                        'synchronize_eschema': deprecated()(self.cmd_sync_schema_props_perms),
+                        'synchronize_rschema': deprecated()(self.cmd_sync_schema_props_perms),
                         })
         return context
 
@@ -276,7 +241,7 @@
 
     def _synchronize_permissions(self, ertype):
         """permission synchronization for an entity or relation type"""
-        if ertype in ('eid', 'has_text', 'identity'):
+        if ertype in VIRTUAL_RTYPES:
             return
         newrschema = self.fs_schema[ertype]
         teid = self.repo.schema[ertype].eid
@@ -478,7 +443,7 @@
     def cmd_add_cubes(self, cubes, update_database=True):
         """update_database is telling if the database schema should be updated
         or if only the relevant eproperty should be inserted (for the case where
-        a cube has been extracted from an existing application, so the
+        a cube has been extracted from an existing instance, so the
         cube schema is already in there)
         """
         newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes)
@@ -622,7 +587,7 @@
         # register entity's attributes
         for rschema, attrschema in eschema.attribute_definitions():
             # ignore those meta relations, they will be automatically added
-            if rschema.type in ('eid', 'creation_date', 'modification_date'):
+            if rschema.type in META_RTYPES:
                 continue
             if not rschema.type in applschema:
                 # need to add the relation type and to commit to get it
@@ -638,12 +603,12 @@
             for rschema in eschema.subject_relations():
                 # attribute relation have already been processed and
                 # 'owned_by'/'created_by' will be automatically added
-                if rschema.final or rschema.type in ('owned_by', 'created_by', 'is', 'is_instance_of'):
+                if rschema.final or rschema.type in META_RTYPES:
                     continue
                 rtypeadded = rschema.type in applschema
                 for targetschema in rschema.objects(etype):
                     # ignore relations where the targeted type is not in the
-                    # current application schema
+                    # current instance schema
                     targettype = targetschema.type
                     if not targettype in applschema and targettype != etype:
                         continue
@@ -663,7 +628,7 @@
                 rtypeadded = rschema.type in applschema or rschema.type in added
                 for targetschema in rschema.subjects(etype):
                     # ignore relations where the targeted type is not in the
-                    # current application schema
+                    # current instance schema
                     targettype = targetschema.type
                     # don't check targettype != etype since in this case the
                     # relation has already been added as a subject relation
@@ -729,6 +694,22 @@
             self.commit()
             self.rqlexecall(ss.rdef2rql(rschema),
                             ask_confirm=self.verbosity>=2)
+            if rtype in META_RTYPES:
+                # if the relation is in META_RTYPES, ensure we're adding it for
+                # all entity types *in the persistent schema*, not only those in
+                # the fs schema
+                for etype in self.repo.schema.entities():
+                    if not etype in self.fs_schema:
+                        # get sample object type and rproperties
+                        objtypes = rschema.objects()
+                        assert len(objtypes) == 1
+                        objtype = objtypes[0]
+                        props = rschema.rproperties(
+                            rschema.subjects(objtype)[0], objtype)
+                        assert props
+                        self.rqlexecall(ss.rdef2rql(rschema, etype, objtype, props),
+                                        ask_confirm=self.verbosity>=2)
+
         if commit:
             self.commit()
 
@@ -873,7 +854,7 @@
         if commit:
             self.commit()
 
-    @obsolete('use sync_schema_props_perms(ertype, syncprops=False)')
+    @deprecated('use sync_schema_props_perms(ertype, syncprops=False)')
     def cmd_synchronize_permissions(self, ertype, commit=True):
         self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit)
 
@@ -949,7 +930,7 @@
 
     def cmd_set_state(self, eid, statename, commit=False):
         self.session.set_pool() # ensure pool is set
-        entity = self.session.eid_rset(eid).get_entity(0, 0)
+        entity = self.session.entity_from_eid(eid)
         entity.change_state(entity.wf_state(statename).eid)
         if commit:
             self.commit()
--- a/server/querier.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/querier.py	Fri Aug 07 12:20:50 2009 +0200
@@ -24,6 +24,8 @@
 from cubicweb.server.rqlannotation import SQLGenAnnotator, set_qdata
 from cubicweb.server.ssplanner import add_types_restriction
 
+READ_ONLY_RTYPES = set(('eid', 'has_text', 'is', 'is_instance_of', 'identity'))
+
 def empty_rset(session, rql, args, rqlst=None):
     """build an empty result set object"""
     return ResultSet([], rql, args, rqlst=rqlst)
@@ -67,7 +69,7 @@
     if rqlst.where is not None:
         for rel in rqlst.where.iget_nodes(Relation):
             # XXX has_text may have specific perm ?
-            if rel.r_type in ('is', 'is_instance_of', 'has_text', 'identity', 'eid'):
+            if rel.r_type in READ_ONLY_RTYPES:
                 continue
             if not schema.rschema(rel.r_type).has_access(user, 'read'):
                 raise Unauthorized('read', rel.r_type)
@@ -189,8 +191,6 @@
 
         return rqlst to actually execute
         """
-        #if server.DEBUG:
-        #    print '------- preprocessing', union.as_string('utf8')
         noinvariant = set()
         if security and not self.session.is_super_session:
             self._insert_security(union, noinvariant)
@@ -373,7 +373,7 @@
         for relation in rqlst.main_relations:
             lhs, rhs = relation.get_variable_parts()
             rtype = relation.r_type
-            if rtype in ('eid', 'has_text', 'is', 'is_instance_of', 'identity'):
+            if rtype in READ_ONLY_RTYPES:
                 raise QueryError("can't assign to %s" % rtype)
             try:
                 edef = to_build[str(lhs)]
@@ -506,7 +506,7 @@
             elif not isinstance(obj, (int, long)):
                 obj = obj.eid
             if repo.schema.rschema(rtype).inlined:
-                entity = session.eid_rset(subj).get_entity(0, 0)
+                entity = session.entity_from_eid(subj)
                 entity[rtype] = obj
                 repo.glob_update_entity(session, entity)
             else:
@@ -519,7 +519,7 @@
     def __init__(self, repo, schema):
         # system info helper
         self._repo = repo
-        # application schema
+        # instance schema
         self.set_schema(schema)
 
     def set_schema(self, schema):
@@ -586,9 +586,10 @@
         always use substitute arguments in queries (eg avoid query such as
         'Any X WHERE X eid 123'!)
         """
-        if server.DEBUG:
-            print '*'*80
-            print rql
+        if server.DEBUG & (server.DBG_RQL | server.DBG_SQL):
+            if server.DEBUG & (server.DBG_MORE | server.DBG_SQL):
+                print '*'*80
+            print 'querier input', rql, args
         # parse the query and binds variables
         if eid_key is not None:
             if not isinstance(eid_key, (tuple, list)):
--- a/server/repository.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/repository.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,7 @@
 repository mainly:
 
 * brings these classes all together to provide a single access
-  point to a cubicweb application.
+  point to a cubicweb instance.
 * handles session management
 * provides method for pyro registration, to call if pyro is enabled
 
@@ -28,14 +28,14 @@
 from yams import BadSchemaDefinition
 from rql import RQLSyntaxError
 
-from cubicweb import (CW_SOFTWARE_ROOT, UnknownEid, AuthenticationError,
+from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, CW_EVENT_MANAGER,
+                      UnknownEid, AuthenticationError, ExecutionError,
                       ETypeNotSupportedBySources, RTypeNotSupportedBySources,
                       BadConnectionId, Unauthorized, ValidationError,
-                      ExecutionError, typed_eid,
-                      CW_MIGRATION_MAP)
-from cubicweb.cwvreg import CubicWebRegistry
-from cubicweb.schema import CubicWebSchema
-
+                      typed_eid)
+from cubicweb.cwvreg import CubicWebVRegistry
+from cubicweb.schema import VIRTUAL_RTYPES, CubicWebSchema
+from cubicweb import server
 from cubicweb.server.utils import RepoThread, LoopTask
 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation
 from cubicweb.server.session import Session, InternalSession
@@ -115,7 +115,6 @@
     # the web interface but may occurs during test or dbapi connection (though
     # not expected for this).  So: don't do it, we pretend to ensure repository
     # consistency.
-    # XXX should probably not use unsafe_execute!
     if card[0] in '1?':
         rschema = session.repo.schema.rschema(rtype)
         if not rschema.inlined:
@@ -138,7 +137,7 @@
     def __init__(self, config, vreg=None, debug=False):
         self.config = config
         if vreg is None:
-            vreg = CubicWebRegistry(config, debug)
+            vreg = CubicWebVRegistry(config, debug)
         self.vreg = vreg
         self.pyro_registered = False
         self.info('starting repository from %s', self.config.apphome)
@@ -179,12 +178,12 @@
         # open some connections pools
         self._available_pools = Queue.Queue()
         self._available_pools.put_nowait(ConnectionsPool(self.sources))
-        if config.read_application_schema:
-            # normal start: load the application schema from the database
+        if config.read_instance_schema:
+            # normal start: load the instance schema from the database
             self.fill_schema()
         elif config.bootstrap_schema:
             # usually during repository creation
-            self.warning("set fs application'schema as bootstrap schema")
+            self.warning("set fs instance'schema as bootstrap schema")
             config.bootstrap_cubes()
             self.set_bootstrap_schema(self.config.load_schema())
             # need to load the Any and CWUser entity types
@@ -197,7 +196,7 @@
                                 'cubicweb.entities.authobjs')
         else:
             # test start: use the file system schema (quicker)
-            self.warning("set fs application'schema")
+            self.warning("set fs instance'schema")
             config.bootstrap_cubes()
             self.set_schema(self.config.load_schema())
         if not config.creating:
@@ -217,15 +216,19 @@
         # close initialization pool and reopen fresh ones for proper
         # initialization now that we know cubes
         self._get_pool().close(True)
+        # list of available pools (we can't iterated on Queue instance)
+        self.pools = []
         for i in xrange(config['connections-pool-size']):
-            self._available_pools.put_nowait(ConnectionsPool(self.sources))
+            self.pools.append(ConnectionsPool(self.sources))
+            self._available_pools.put_nowait(self.pools[-1])
         self._shutting_down = False
-        if not config.creating:
-            # call application level initialisation hooks
+        if not (config.creating or config.repairing):
+            # call instance level initialisation hooks
             self.hm.call_hooks('server_startup', repo=self)
             # register a task to cleanup expired session
             self.looping_task(self.config['session-time']/3.,
                               self.clean_sessions)
+        CW_EVENT_MANAGER.bind('after-registry-load', self.reset_hooks)
 
     # internals ###############################################################
 
@@ -245,11 +248,14 @@
             # full reload of all appobjects
             self.vreg.reset()
             self.vreg.set_schema(schema)
-        self.hm.set_schema(schema)
+        self.reset_hooks()
+
+    def reset_hooks(self):
+        self.hm.set_schema(self.schema)
         self.hm.register_system_hooks(self.config)
-        # application specific hooks
-        if self.config.application_hooks:
-            self.info('loading application hooks')
+        # instance specific hooks
+        if self.config.instance_hooks:
+            self.info('loading instance hooks')
             self.hm.register_hooks(self.config.load_hooks(self.vreg))
 
     def fill_schema(self):
@@ -297,32 +303,32 @@
         config.usergroup_hooks = False
         config.schema_hooks = False
         config.notification_hooks = False
-        config.application_hooks = False
+        config.instance_hooks = False
         self.set_schema(schema, resetvreg=False)
         config.core_hooks = True
         config.usergroup_hooks = True
         config.schema_hooks = True
         config.notification_hooks = True
-        config.application_hooks = True
+        config.instance_hooks = True
 
     def start_looping_tasks(self):
         assert isinstance(self._looping_tasks, list), 'already started'
-        for i, (interval, func) in enumerate(self._looping_tasks):
-            self._looping_tasks[i] = task = LoopTask(interval, func)
+        for i, (interval, func, args) in enumerate(self._looping_tasks):
+            self._looping_tasks[i] = task = LoopTask(interval, func, args)
             self.info('starting task %s with interval %.2fs', task.name,
                       interval)
             task.start()
         # ensure no tasks will be further added
         self._looping_tasks = tuple(self._looping_tasks)
 
-    def looping_task(self, interval, func):
+    def looping_task(self, interval, func, *args):
         """register a function to be called every `interval` seconds.
 
         looping tasks can only be registered during repository initialization,
         once done this method will fail.
         """
         try:
-            self._looping_tasks.append( (interval, func) )
+            self._looping_tasks.append( (interval, func, args) )
         except AttributeError:
             raise RuntimeError("can't add looping task once the repository is started")
 
@@ -426,7 +432,7 @@
 
     def _build_user(self, session, eid):
         """return a CWUser entity for user with the given eid"""
-        cls = self.vreg.etype_class('CWUser')
+        cls = self.vreg['etypes'].etype_class('CWUser')
         rql = cls.fetch_rql(session.user, ['X eid %(x)s'])
         rset = session.execute(rql, {'x': eid}, 'x')
         assert len(rset) == 1, rset
@@ -441,7 +447,7 @@
     # public (dbapi) interface ################################################
 
     def get_schema(self):
-        """return the application schema. This is a public method, not
+        """return the instance schema. This is a public method, not
         requiring a session id
         """
         try:
@@ -452,17 +458,18 @@
             self.schema.__hashmode__ = None
 
     def get_cubes(self):
-        """return the list of cubes used by this application. This is a
+        """return the list of cubes used by this instance. This is a
         public method, not requiring a session id.
         """
-        versions = self.get_versions(not self.config.creating)
+        versions = self.get_versions(not (self.config.creating
+                                          or self.config.repairing))
         cubes = list(versions)
         cubes.remove('cubicweb')
         return cubes
 
     @cached
     def get_versions(self, checkversions=False):
-        """return the a dictionary containing cubes used by this application
+        """return the a dictionary containing cubes used by this instance
         as key with their version as value, including cubicweb version. This is a
         public method, not requiring a session id.
         """
@@ -485,7 +492,7 @@
                     else:
                         fsversion = self.config.cubicweb_version()
                     if version < fsversion:
-                        msg = ('application has %s version %s but %s '
+                        msg = ('instance has %s version %s but %s '
                                'is installed. Run "cubicweb-ctl upgrade".')
                         raise ExecutionError(msg % (cube, version, fsversion))
         finally:
@@ -529,7 +536,7 @@
                                    {'login': login})):
                 raise ValidationError(None, {'login': errmsg % login})
             # we have to create the user
-            user = self.vreg.etype_class('CWUser')(session, None)
+            user = self.vreg['etypes'].etype_class('CWUser')(session, None)
             if isinstance(password, unicode):
                 # password should *always* be utf8 encoded
                 password = password.encode('UTF8')
@@ -929,9 +936,10 @@
         """
         rql = []
         eschema = self.schema.eschema(etype)
+        pendingrtypes = session.transaction_data.get('pendingrtypes', ())
         for rschema, targetschemas, x in eschema.relation_definitions():
             rtype = rschema.type
-            if rtype == 'identity':
+            if rtype in VIRTUAL_RTYPES or rtype in pendingrtypes:
                 continue
             var = '%s%s' % (rtype.upper(), x.upper())
             if x == 'subject':
@@ -984,6 +992,8 @@
         source = self.locate_etype_source(etype)
         # attribute an eid to the entity before calling hooks
         entity.set_eid(self.system_source.create_eid(session))
+        if server.DEBUG & server.DBG_REPO:
+            print 'ADD entity', etype, entity.eid, dict(entity)
         entity._is_saved = False # entity has an eid but is not yet saved
         relations = []
         # if inlined relations are specified, fill entity's related cache to
@@ -991,11 +1001,10 @@
         for attr in entity.keys():
             rschema = eschema.subject_relation(attr)
             if not rschema.is_final(): # inlined relation
-                entity.set_related_cache(attr, 'subject',
-                                         entity.req.eid_rset(entity[attr]))
                 relations.append((attr, entity[attr]))
         if source.should_call_hooks:
             self.hm.call_hooks('before_add_entity', etype, session, entity)
+        entity.edited_attributes = entity.keys()
         entity.set_defaults()
         entity.check(creation=True)
         source.add_entity(session, entity)
@@ -1006,7 +1015,21 @@
             extid = None
         self.add_info(session, entity, source, extid, complete=False)
         entity._is_saved = True # entity has an eid and is saved
-        #print 'added', entity#, entity.items()
+        # prefill entity relation caches
+        session.set_entity_cache(entity)
+        for rschema in eschema.subject_relations():
+            rtype = str(rschema)
+            if rtype in VIRTUAL_RTYPES:
+                continue
+            if rschema.is_final():
+                entity.setdefault(rtype, None)
+            else:
+                entity.set_related_cache(rtype, 'subject', session.empty_rset())
+        for rschema in eschema.object_relations():
+            rtype = str(rschema)
+            if rtype in VIRTUAL_RTYPES:
+                continue
+            entity.set_related_cache(rtype, 'object', session.empty_rset())
         # trigger after_add_entity after after_add_relation
         if source.should_call_hooks:
             self.hm.call_hooks('after_add_entity', etype, session, entity)
@@ -1014,18 +1037,23 @@
             for attr, value in relations:
                 self.hm.call_hooks('before_add_relation', attr, session,
                                     entity.eid, attr, value)
+                session.update_rel_cache_add(entity.eid, attr, value)
                 self.hm.call_hooks('after_add_relation', attr, session,
                                     entity.eid, attr, value)
         return entity.eid
 
-    def glob_update_entity(self, session, entity):
+    def glob_update_entity(self, session, entity, edited_attributes):
         """replace an entity in the repository
         the type and the eid of an entity must not be changed
         """
-        #print 'update', entity
+        etype = str(entity.e_schema)
+        if server.DEBUG & server.DBG_REPO:
+            print 'UPDATE entity', etype, entity.eid, \
+                  dict(entity), edited_attributes
+        entity.edited_attributes = edited_attributes
         entity.check()
-        etype = str(entity.e_schema)
         eschema = entity.e_schema
+        session.set_entity_cache(entity)
         only_inline_rels, need_fti_update = True, False
         relations = []
         for attr in entity.keys():
@@ -1041,10 +1069,12 @@
                 previous_value = entity.related(attr)
                 if previous_value:
                     previous_value = previous_value[0][0] # got a result set
-                    self.hm.call_hooks('before_delete_relation', attr, session,
-                                       entity.eid, attr, previous_value)
-                entity.set_related_cache(attr, 'subject',
-                                         entity.req.eid_rset(entity[attr]))
+                    if previous_value == entity[attr]:
+                        previous_value = None
+                    else:
+                        self.hm.call_hooks('before_delete_relation', attr,
+                                           session, entity.eid, attr,
+                                           previous_value)
                 relations.append((attr, entity[attr], previous_value))
         source = self.source_from_eid(entity.eid, session)
         if source.should_call_hooks:
@@ -1066,19 +1096,31 @@
                                     entity)
         if source.should_call_hooks:
             for attr, value, prevvalue in relations:
+                # if the relation is already cached, update existant cache
+                relcache = entity.relation_cached(attr, 'subject')
                 if prevvalue:
                     self.hm.call_hooks('after_delete_relation', attr, session,
                                        entity.eid, attr, prevvalue)
+                    if relcache is not None:
+                        session.update_rel_cache_del(entity.eid, attr, prevvalue)
                 del_existing_rel_if_needed(session, entity.eid, attr, value)
+                if relcache is not None:
+                    session.update_rel_cache_add(entity.eid, attr, value)
+                else:
+                    entity.set_related_cache(attr, 'subject',
+                                             session.eid_rset(value))
                 self.hm.call_hooks('after_add_relation', attr, session,
                                     entity.eid, attr, value)
 
     def glob_delete_entity(self, session, eid):
         """delete an entity and all related entities from the repository"""
-        #print 'deleting', eid
         # call delete_info before hooks
         self._prepare_delete_info(session, eid)
         etype, uri, extid = self.type_and_source_from_eid(eid, session)
+        if server.DEBUG & server.DBG_REPO:
+            print 'DELETE entity', etype, eid
+            if eid == 937:
+                server.DEBUG |= (server.DBG_SQL | server.DBG_RQL | server.DBG_MORE)
         source = self.sources_by_uri[uri]
         if source.should_call_hooks:
             self.hm.call_hooks('before_delete_entity', etype, session, eid)
@@ -1090,32 +1132,32 @@
 
     def glob_add_relation(self, session, subject, rtype, object):
         """add a relation to the repository"""
-        assert subject is not None
-        assert rtype
-        assert object is not None
+        if server.DEBUG & server.DBG_REPO:
+            print 'ADD relation', subject, rtype, object
         source = self.locate_relation_source(session, subject, rtype, object)
-        #print 'adding', subject, rtype, object, 'to', source
         if source.should_call_hooks:
             del_existing_rel_if_needed(session, subject, rtype, object)
             self.hm.call_hooks('before_add_relation', rtype, session,
                                subject, rtype, object)
         source.add_relation(session, subject, rtype, object)
+        rschema = self.schema.rschema(rtype)
+        session.update_rel_cache_add(subject, rtype, object, rschema.symetric)
         if source.should_call_hooks:
             self.hm.call_hooks('after_add_relation', rtype, session,
                                subject, rtype, object)
 
     def glob_delete_relation(self, session, subject, rtype, object):
         """delete a relation from the repository"""
-        assert subject is not None
-        assert rtype
-        assert object is not None
+        if server.DEBUG & server.DBG_REPO:
+            print 'DELETE relation', subject, rtype, object
         source = self.locate_relation_source(session, subject, rtype, object)
-        #print 'delete rel', subject, rtype, object
         if source.should_call_hooks:
             self.hm.call_hooks('before_delete_relation', rtype, session,
                                subject, rtype, object)
         source.delete_relation(session, subject, rtype, object)
-        if self.schema.rschema(rtype).symetric:
+        rschema = self.schema.rschema(rtype)
+        session.update_rel_cache_del(subject, rtype, object, rschema.symetric)
+        if rschema.symetric:
             # on symetric relation, we can't now in which sense it's
             # stored so try to delete both
             source.delete_relation(session, object, rtype, subject)
@@ -1128,36 +1170,16 @@
 
     def pyro_register(self, host=''):
         """register the repository as a pyro object"""
-        from Pyro import core
-        port = self.config['pyro-port']
-        nshost, nsgroup = self.config['pyro-ns-host'], self.config['pyro-ns-group']
-        nsgroup = ':' + nsgroup
-        core.initServer(banner=0)
-        daemon = core.Daemon(host=host, port=port)
-        daemon.useNameServer(self.pyro_nameserver(nshost, nsgroup))
-        # use Delegation approach
-        impl = core.ObjBase()
-        impl.delegateTo(self)
-        nsid = self.config['pyro-id'] or self.config.appid
-        daemon.connect(impl, '%s.%s' % (nsgroup, nsid))
+        from logilab.common.pyro_ext import register_object
+        appid = self.config['pyro-id'] or self.config.appid
+        daemon = register_object(self, appid, self.config['pyro-ns-group'],
+                                 self.config['pyro-host'],
+                                 self.config['pyro-ns-host'])
         msg = 'repository registered as a pyro object using group %s and id %s'
-        self.info(msg, nsgroup, nsid)
+        self.info(msg, self.config['pyro-ns-group'], appid)
         self.pyro_registered = True
         return daemon
 
-    def pyro_nameserver(self, host=None, group=None):
-        """locate and bind the the name server to the daemon"""
-        from Pyro import naming, errors
-        # locate the name server
-        nameserver = naming.NameServerLocator().getNS(host)
-        if group is not None:
-            # make sure our namespace group exists
-            try:
-                nameserver.createGroup(group)
-            except errors.NamingError:
-                pass
-        return nameserver
-
     # multi-sources planner helpers ###########################################
 
     @cached
@@ -1181,21 +1203,9 @@
 
 def pyro_unregister(config):
     """unregister the repository from the pyro name server"""
-    nshost, nsgroup = config['pyro-ns-host'], config['pyro-ns-group']
+    from logilab.common.pyro_ext import ns_unregister
     appid = config['pyro-id'] or config.appid
-    from Pyro import core, naming, errors
-    core.initClient(banner=False)
-    try:
-        nameserver = naming.NameServerLocator().getNS(nshost)
-    except errors.PyroError, ex:
-        # name server not responding
-        config.error('can\'t locate pyro name server: %s', ex)
-        return
-    try:
-        nameserver.unregister(':%s.%s' % (nsgroup, appid))
-        config.info('%s unregistered from pyro name server', appid)
-    except errors.NamingError:
-        config.warning('%s already unregistered from pyro name server', appid)
+    ns_unregister(appid, config['pyro-ns-group'], config['pyro-ns-host'])
 
 
 from logging import getLogger
--- a/server/schemahooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/schemahooks.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,17 +16,31 @@
 from yams.buildobjs import EntityType, RelationType, RelationDefinition
 from yams.schema2sql import eschema2sql, rschema2sql, type_from_constraints
 
+
 from cubicweb import ValidationError, RepositoryError
+from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CONSTRAINTS
 from cubicweb.server import schemaserial as ss
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.pool import Operation, SingleLastOperation, PreCommitOperation
 from cubicweb.server.hookhelper import (entity_attr, entity_name,
-                                     check_internal_entity)
+                                        check_internal_entity)
+
+
+TYPE_CONVERTER = { # XXX
+    'Boolean': bool,
+    'Int': int,
+    'Float': float,
+    'Password': str,
+    'String': unicode,
+    'Date' : unicode,
+    'Datetime' : unicode,
+    'Time' : unicode,
+    }
 
 # core entity and relation types which can't be removed
 CORE_ETYPES = list(BASE_TYPES) + ['CWEType', 'CWRType', 'CWUser', 'CWGroup',
                                   'CWConstraint', 'CWAttribute', 'CWRelation']
-CORE_RTYPES = ['eid', 'creation_date', 'modification_date',
+CORE_RTYPES = ['eid', 'creation_date', 'modification_date', 'cwuri',
                'login', 'upassword', 'name',
                'is', 'instanceof', 'owned_by', 'created_by', 'in_group',
                'relation_type', 'from_entity', 'to_entity',
@@ -50,7 +64,7 @@
     column = SQL_PREFIX + rtype
     try:
         session.system_sql(str('ALTER TABLE %s ADD COLUMN %s integer'
-                               % (table, column)))
+                               % (table, column)), rollback_on_failure=False)
         session.info('added column %s to table %s', column, table)
     except:
         # silent exception here, if this error has not been raised because the
@@ -66,29 +80,49 @@
         '%s.%s' % (etype, rtype))
 
 
-class SchemaOperation(Operation):
-    """base class for schema operations"""
-    def __init__(self, session, kobj=None, **kwargs):
-        self.schema = session.repo.schema
-        self.kobj = kobj
-        # once Operation.__init__ has been called, event may be triggered, so
-        # do this last !
-        Operation.__init__(self, session, **kwargs)
-        # every schema operation is triggering a schema update
-        UpdateSchemaOp(session)
+# operations for low-level database alteration  ################################
+
+class DropTable(PreCommitOperation):
+    """actually remove a database from the instance's schema"""
+    table = None # make pylint happy
+    def precommit_event(self):
+        dropped = self.session.transaction_data.setdefault('droppedtables',
+                                                           set())
+        if self.table in dropped:
+            return # already processed
+        dropped.add(self.table)
+        self.session.system_sql('DROP TABLE %s' % self.table)
+        self.info('dropped table %s', self.table)
+
+
+class DropRelationTable(DropTable):
+    def __init__(self, session, rtype):
+        super(DropRelationTable, self).__init__(
+            session, table='%s_relation' % rtype)
+        session.transaction_data.setdefault('pendingrtypes', set()).add(rtype)
+
 
-class EarlySchemaOperation(SchemaOperation):
-    def insert_index(self):
-        """schema operation which are inserted at the begining of the queue
-        (typically to add/remove entity or relation types)
-        """
-        i = -1
-        for i, op in enumerate(self.session.pending_operations):
-            if not isinstance(op, EarlySchemaOperation):
-                return i
-        return i + 1
+class DropColumn(PreCommitOperation):
+    """actually remove the attribut's column from entity table in the system
+    database
+    """
+    table = column = None # make pylint happy
+    def precommit_event(self):
+        session, table, column = self.session, self.table, self.column
+        # drop index if any
+        session.pool.source('system').drop_index(session, table, column)
+        try:
+            session.system_sql('ALTER TABLE %s DROP COLUMN %s'
+                               % (table, column), rollback_on_failure=False)
+            self.info('dropped column %s from table %s', column, table)
+        except Exception, ex:
+            # not supported by sqlite for instance
+            self.error('error while altering table %s: %s', table, ex)
 
-class UpdateSchemaOp(SingleLastOperation):
+
+# base operations for in-memory schema synchronization  ########################
+
+class MemSchemaNotifyChanges(SingleLastOperation):
     """the update schema operation:
 
     special operation which should be called once and after all other schema
@@ -104,434 +138,51 @@
         self.repo.set_schema(self.repo.schema)
 
 
-class DropTableOp(PreCommitOperation):
-    """actually remove a database from the application's schema"""
-    table = None # make pylint happy
-    def precommit_event(self):
-        dropped = self.session.transaction_data.setdefault('droppedtables',
-                                                           set())
-        if self.table in dropped:
-            return # already processed
-        dropped.add(self.table)
-        self.session.system_sql('DROP TABLE %s' % self.table)
-        self.info('dropped table %s', self.table)
-
-class DropColumnOp(PreCommitOperation):
-    """actually remove the attribut's column from entity table in the system
-    database
-    """
-    table = column = None # make pylint happy
-    def precommit_event(self):
-        session, table, column = self.session, self.table, self.column
-        # drop index if any
-        session.pool.source('system').drop_index(session, table, column)
-        try:
-            session.system_sql('ALTER TABLE %s DROP COLUMN %s'
-                               % (table, column))
-            self.info('dropped column %s from table %s', column, table)
-        except Exception, ex:
-            # not supported by sqlite for instance
-            self.error('error while altering table %s: %s', table, ex)
-
-
-# deletion ####################################################################
-
-class DeleteCWETypeOp(SchemaOperation):
-    """actually remove the entity type from the application's schema"""
-    def commit_event(self):
-        try:
-            # del_entity_type also removes entity's relations
-            self.schema.del_entity_type(self.kobj)
-        except KeyError:
-            # s/o entity type have already been deleted
-            pass
-
-def before_del_eetype(session, eid):
-    """before deleting a CWEType entity:
-    * check that we don't remove a core entity type
-    * cascade to delete related CWAttribute and CWRelation entities
-    * instantiate an operation to delete the entity type on commit
-    """
-    # final entities can't be deleted, don't care about that
-    name = check_internal_entity(session, eid, CORE_ETYPES)
-    # delete every entities of this type
-    session.unsafe_execute('DELETE %s X' % name)
-    DropTableOp(session, table=SQL_PREFIX + name)
-    DeleteCWETypeOp(session, name)
-
-def after_del_eetype(session, eid):
-    # workflow cleanup
-    session.execute('DELETE State X WHERE NOT X state_of Y')
-    session.execute('DELETE Transition X WHERE NOT X transition_of Y')
-
-
-class DeleteCWRTypeOp(SchemaOperation):
-    """actually remove the relation type from the application's schema"""
-    def commit_event(self):
-        try:
-            self.schema.del_relation_type(self.kobj)
-        except KeyError:
-            # s/o entity type have already been deleted
-            pass
-
-def before_del_ertype(session, eid):
-    """before deleting a CWRType entity:
-    * check that we don't remove a core relation type
-    * cascade to delete related CWAttribute and CWRelation entities
-    * instantiate an operation to delete the relation type on commit
-    """
-    name = check_internal_entity(session, eid, CORE_RTYPES)
-    # delete relation definitions using this relation type
-    session.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s',
-                    {'x': eid})
-    session.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
-                    {'x': eid})
-    DeleteCWRTypeOp(session, name)
-
-
-class DelRelationDefOp(SchemaOperation):
-    """actually remove the relation definition from the application's schema"""
-    def commit_event(self):
-        subjtype, rtype, objtype = self.kobj
-        try:
-            self.schema.del_relation_def(subjtype, rtype, objtype)
-        except KeyError:
-            # relation type may have been already deleted
-            pass
+class MemSchemaOperation(Operation):
+    """base class for schema operations"""
+    def __init__(self, session, kobj=None, **kwargs):
+        self.schema = session.schema
+        self.kobj = kobj
+        # once Operation.__init__ has been called, event may be triggered, so
+        # do this last !
+        Operation.__init__(self, session, **kwargs)
+        # every schema operation is triggering a schema update
+        MemSchemaNotifyChanges(session)
 
-def after_del_relation_type(session, rdefeid, rtype, rteid):
-    """before deleting a CWAttribute or CWRelation entity:
-    * if this is a final or inlined relation definition, instantiate an
-      operation to drop necessary column, else if this is the last instance
-      of a non final relation, instantiate an operation to drop necessary
-      table
-    * instantiate an operation to delete the relation definition on commit
-    * delete the associated relation type when necessary
-    """
-    subjschema, rschema, objschema = session.repo.schema.schema_by_eid(rdefeid)
-    pendings = session.transaction_data.get('pendingeids', ())
-    # first delete existing relation if necessary
-    if rschema.is_final():
-        rdeftype = 'CWAttribute'
-    else:
-        rdeftype = 'CWRelation'
-        if not (subjschema.eid in pendings or objschema.eid in pendings):
-            session.execute('DELETE X %s Y WHERE X is %s, Y is %s'
-                            % (rschema, subjschema, objschema))
-    execute = session.unsafe_execute
-    rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R,'
-                   'R eid %%(x)s' % rdeftype, {'x': rteid})
-    lastrel = rset[0][0] == 0
-    # we have to update physical schema systematically for final and inlined
-    # relations, but only if it's the last instance for this relation type
-    # for other relations
-
-    if (rschema.is_final() or rschema.inlined):
-        rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, '
-                       'R eid %%(x)s, X from_entity E, E name %%(name)s'
-                       % rdeftype, {'x': rteid, 'name': str(subjschema)})
-        if rset[0][0] == 0 and not subjschema.eid in pendings:
-            DropColumnOp(session, table=SQL_PREFIX + subjschema.type,
-                         column=SQL_PREFIX + rschema.type)
-    elif lastrel:
-        DropTableOp(session, table='%s_relation' % rschema.type)
-    # if this is the last instance, drop associated relation type
-    if lastrel and not rteid in pendings:
-        execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
-    DelRelationDefOp(session, (subjschema, rschema, objschema))
-
-
-# addition ####################################################################
-
-class AddCWETypeOp(EarlySchemaOperation):
-    """actually add the entity type to the application's schema"""
-    eid = None # make pylint happy
-    def commit_event(self):
-        self.schema.add_entity_type(self.kobj)
-
-def before_add_eetype(session, entity):
-    """before adding a CWEType entity:
-    * check that we are not using an existing entity type,
-    """
-    name = entity['name']
-    schema = session.repo.schema
-    if name in schema and schema[name].eid is not None:
-        raise RepositoryError('an entity type %s already exists' % name)
-
-def after_add_eetype(session, entity):
-    """after adding a CWEType entity:
-    * create the necessary table
-    * set creation_date and modification_date by creating the necessary
-      CWAttribute entities
-    * add owned_by relation by creating the necessary CWRelation entity
-    * register an operation to add the entity type to the application's
-      schema on commit
-    """
-    if entity.get('final'):
-        return
-    schema = session.repo.schema
-    name = entity['name']
-    etype = EntityType(name=name, description=entity.get('description'),
-                       meta=entity.get('meta')) # don't care about final
-    # fake we add it to the schema now to get a correctly initialized schema
-    # but remove it before doing anything more dangerous...
-    schema = session.repo.schema
-    eschema = schema.add_entity_type(etype)
-    eschema.set_default_groups()
-    # generate table sql and rql to add metadata
-    tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema,
-                           prefix=SQL_PREFIX)
-    relrqls = []
-    for rtype in ('is', 'is_instance_of', 'creation_date', 'modification_date',
-                  'created_by', 'owned_by'):
-        rschema = schema[rtype]
-        sampletype = rschema.subjects()[0]
-        desttype = rschema.objects()[0]
-        props = rschema.rproperties(sampletype, desttype)
-        relrqls += list(ss.rdef2rql(rschema, name, desttype, props))
-    # now remove it !
-    schema.del_entity_type(name)
-    # create the necessary table
-    for sql in tablesql.split(';'):
-        if sql.strip():
-            session.system_sql(sql)
-    # register operation to modify the schema on commit
-    # this have to be done before adding other relations definitions
-    # or permission settings
-    etype.eid = entity.eid
-    AddCWETypeOp(session, etype)
-    # add meta creation_date, modification_date and owned_by relations
-    for rql, kwargs in relrqls:
-        session.execute(rql, kwargs)
+    def prepare_constraints(self, subjtype, rtype, objtype):
+        constraints = rtype.rproperty(subjtype, objtype, 'constraints')
+        self.constraints = list(constraints)
+        rtype.set_rproperty(subjtype, objtype, 'constraints', self.constraints)
 
 
-class AddCWRTypeOp(EarlySchemaOperation):
-    """actually add the relation type to the application's schema"""
-    eid = None # make pylint happy
-    def commit_event(self):
-        rschema = self.schema.add_relation_type(self.kobj)
-        rschema.set_default_groups()
-
-def before_add_ertype(session, entity):
-    """before adding a CWRType entity:
-    * check that we are not using an existing relation type,
-    * register an operation to add the relation type to the application's
-      schema on commit
-
-    We don't know yeat this point if a table is necessary
-    """
-    name = entity['name']
-    if name in session.repo.schema.relations():
-        raise RepositoryError('a relation type %s already exists' % name)
-
-def after_add_ertype(session, entity):
-    """after a CWRType entity has been added:
-    * register an operation to add the relation type to the application's
-      schema on commit
-    We don't know yeat this point if a table is necessary
-    """
-    rtype = RelationType(name=entity['name'],
-                         description=entity.get('description'),
-                         meta=entity.get('meta', False),
-                         inlined=entity.get('inlined', False),
-                         symetric=entity.get('symetric', False))
-    rtype.eid = entity.eid
-    AddCWRTypeOp(session, rtype)
-
-
-class AddErdefOp(EarlySchemaOperation):
-    """actually add the attribute relation definition to the application's
-    schema
-    """
-    def commit_event(self):
-        self.schema.add_relation_def(self.kobj)
-
-TYPE_CONVERTER = {
-    'Boolean': bool,
-    'Int': int,
-    'Float': float,
-    'Password': str,
-    'String': unicode,
-    'Date' : unicode,
-    'Datetime' : unicode,
-    'Time' : unicode,
-    }
+class MemSchemaEarlyOperation(MemSchemaOperation):
+    def insert_index(self):
+        """schema operation which are inserted at the begining of the queue
+        (typically to add/remove entity or relation types)
+        """
+        i = -1
+        for i, op in enumerate(self.session.pending_operations):
+            if not isinstance(op, MemSchemaEarlyOperation):
+                return i
+        return i + 1
 
 
-class AddCWAttributePreCommitOp(PreCommitOperation):
-    """an attribute relation (CWAttribute) has been added:
-    * add the necessary column
-    * set default on this column if any and possible
-    * register an operation to add the relation definition to the
-      application's schema on commit
-
-    constraints are handled by specific hooks
-    """
-    entity = None # make pylint happy
-    def precommit_event(self):
-        session = self.session
-        entity = self.entity
-        fromentity = entity.from_entity[0]
-        relationtype = entity.relation_type[0]
-        session.execute('SET X ordernum Y+1 WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, X ordernum >= %(order)s, NOT X eid %(x)s',
-                        {'x': entity.eid, 'se': fromentity.eid, 'order': entity.ordernum or 0})
-        subj, rtype = str(fromentity.name), str(relationtype.name)
-        obj = str(entity.to_entity[0].name)
-        # at this point default is a string or None, but we need a correctly
-        # typed value
-        default = entity.defaultval
-        if default is not None:
-            default = TYPE_CONVERTER[obj](default)
-        constraints = get_constraints(session, entity)
-        rdef = RelationDefinition(subj, rtype, obj,
-                                  cardinality=entity.cardinality,
-                                  order=entity.ordernum,
-                                  description=entity.description,
-                                  default=default,
-                                  indexed=entity.indexed,
-                                  fulltextindexed=entity.fulltextindexed,
-                                  internationalizable=entity.internationalizable,
-                                  constraints=constraints,
-                                  eid=entity.eid)
-        sysource = session.pool.source('system')
-        attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
-                                         constraints)
-        # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
-        # add a new column with UNIQUE, it should be added after the ALTER TABLE
-        # using ADD INDEX
-        if sysource.dbdriver == 'sqlite' and 'UNIQUE' in attrtype:
-            extra_unique_index = True
-            attrtype = attrtype.replace(' UNIQUE', '')
+class MemSchemaPermissionOperation(MemSchemaOperation):
+    """base class to synchronize schema permission definitions"""
+    def __init__(self, session, perm, etype_eid):
+        self.perm = perm
+        try:
+            self.name = entity_name(session, etype_eid)
+        except IndexError:
+            self.error('changing permission of a no more existant type #%s',
+                etype_eid)
         else:
-            extra_unique_index = False
-        # added some str() wrapping query since some backend (eg psycopg) don't
-        # allow unicode queries
-        table = SQL_PREFIX + subj
-        column = SQL_PREFIX + rtype
-        try:
-            session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s'
-                                   % (table, column, attrtype)))
-            self.info('added column %s to table %s', table, column)
-        except Exception, ex:
-            # the column probably already exists. this occurs when
-            # the entity's type has just been added or if the column
-            # has not been previously dropped
-            self.error('error while altering table %s: %s', table, ex)
-        if extra_unique_index or entity.indexed:
-            try:
-                sysource.create_index(session, table, column,
-                                      unique=extra_unique_index)
-            except Exception, ex:
-                self.error('error while creating index for %s.%s: %s',
-                           table, column, ex)
-        AddErdefOp(session, rdef)
-
-def after_add_efrdef(session, entity):
-    AddCWAttributePreCommitOp(session, entity=entity)
+            Operation.__init__(self, session)
 
 
-class AddCWRelationPreCommitOp(PreCommitOperation):
-    """an actual relation has been added:
-    * if this is an inlined relation, add the necessary column
-      else if it's the first instance of this relation type, add the
-      necessary table and set default permissions
-    * register an operation to add the relation definition to the
-      application's schema on commit
+# operations for high-level source database alteration  ########################
 
-    constraints are handled by specific hooks
-    """
-    entity = None # make pylint happy
-    def precommit_event(self):
-        session = self.session
-        entity = self.entity
-        fromentity = entity.from_entity[0]
-        relationtype = entity.relation_type[0]
-        session.execute('SET X ordernum Y+1 WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, X ordernum >= %(order)s, NOT X eid %(x)s',
-                        {'x': entity.eid, 'se': fromentity.eid, 'order': entity.ordernum or 0})
-        subj, rtype = str(fromentity.name), str(relationtype.name)
-        obj = str(entity.to_entity[0].name)
-        card = entity.get('cardinality')
-        rdef = RelationDefinition(subj, rtype, obj,
-                                  cardinality=card,
-                                  order=entity.ordernum,
-                                  composite=entity.composite,
-                                  description=entity.description,
-                                  constraints=get_constraints(session, entity),
-                                  eid=entity.eid)
-        schema = session.repo.schema
-        rschema = schema.rschema(rtype)
-        # this have to be done before permissions setting
-        AddErdefOp(session, rdef)
-        if rschema.inlined:
-            # need to add a column if the relation is inlined and if this is the
-            # first occurence of "Subject relation Something" whatever Something
-            # and if it has not been added during other event of the same
-            # transaction
-            key = '%s.%s' % (subj, rtype)
-            try:
-                alreadythere = bool(rschema.objects(subj))
-            except KeyError:
-                alreadythere = False
-            if not (alreadythere or
-                    key in session.transaction_data.get('createdattrs', ())):
-                add_inline_relation_column(session, subj, rtype)
-        else:
-            # need to create the relation if no relation definition in the
-            # schema and if it has not been added during other event of the same
-            # transaction
-            if not (rschema.subjects() or
-                    rtype in session.transaction_data.get('createdtables', ())):
-                try:
-                    rschema = schema[rtype]
-                    tablesql = rschema2sql(rschema)
-                except KeyError:
-                    # fake we add it to the schema now to get a correctly
-                    # initialized schema but remove it before doing anything
-                    # more dangerous...
-                    rschema = schema.add_relation_type(rdef)
-                    tablesql = rschema2sql(rschema)
-                    schema.del_relation_type(rtype)
-                # create the necessary table
-                for sql in tablesql.split(';'):
-                    if sql.strip():
-                        self.session.system_sql(sql)
-                session.transaction_data.setdefault('createdtables', []).append(
-                    rtype)
-
-def after_add_enfrdef(session, entity):
-    AddCWRelationPreCommitOp(session, entity=entity)
-
-
-# update ######################################################################
-
-def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
-    errors = {}
-    # don't use getattr(entity, attr), we would get the modified value if any
-    for attr in ro_attrs:
-        origval = entity_attr(session, entity.eid, attr)
-        if entity.get(attr, origval) != origval:
-            errors[attr] = session._("can't change the %s attribute") % \
-                           display_name(session, attr)
-    if errors:
-        raise ValidationError(entity.eid, errors)
-
-def before_update_eetype(session, entity):
-    """check name change, handle final"""
-    check_valid_changes(session, entity, ro_attrs=('final',))
-    # don't use getattr(entity, attr), we would get the modified value if any
-    oldname = entity_attr(session, entity.eid, 'name')
-    newname = entity.get('name', oldname)
-    if newname.lower() != oldname.lower():
-        eschema = session.repo.schema[oldname]
-        UpdateEntityTypeName(session, eschema=eschema,
-                             oldname=oldname, newname=newname)
-
-def before_update_ertype(session, entity):
-    """check name change, handle final"""
-    check_valid_changes(session, entity)
-
-
-class UpdateEntityTypeName(SchemaOperation):
+class SourceDbCWETypeRename(PreCommitOperation):
     """this operation updates physical storage accordingly"""
     oldname = newname = None # make pylint happy
 
@@ -546,11 +197,211 @@
         sqlexec('UPDATE deleted_entities SET type=%s WHERE type=%s',
                 (self.newname, self.oldname))
 
-    def commit_event(self):
-        self.session.repo.schema.rename_entity_type(self.oldname, self.newname)
+
+class SourceDbCWRTypeUpdate(PreCommitOperation):
+    """actually update some properties of a relation definition"""
+    rschema = values = entity = None # make pylint happy
+
+    def precommit_event(self):
+        session = self.session
+        rschema = self.rschema
+        if rschema.is_final() or not 'inlined' in self.values:
+            return # nothing to do
+        inlined = self.values['inlined']
+        entity = self.entity
+        # check in-lining is necessary / possible
+        if not entity.inlined_changed(inlined):
+            return # nothing to do
+        # inlined changed, make necessary physical changes!
+        sqlexec = self.session.system_sql
+        rtype = rschema.type
+        eidcolumn = SQL_PREFIX + 'eid'
+        if not inlined:
+            # need to create the relation if it has not been already done by
+            # another event of the same transaction
+            if not rschema.type in session.transaction_data.get('createdtables', ()):
+                tablesql = rschema2sql(rschema)
+                # create the necessary table
+                for sql in tablesql.split(';'):
+                    if sql.strip():
+                        sqlexec(sql)
+                session.transaction_data.setdefault('createdtables', []).append(
+                    rschema.type)
+            # copy existant data
+            column = SQL_PREFIX + rtype
+            for etype in rschema.subjects():
+                table = SQL_PREFIX + str(etype)
+                sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL'
+                        % (rtype, eidcolumn, column, table, column))
+            # drop existant columns
+            for etype in rschema.subjects():
+                DropColumn(session, table=SQL_PREFIX + str(etype),
+                             column=SQL_PREFIX + rtype)
+        else:
+            for etype in rschema.subjects():
+                try:
+                    add_inline_relation_column(session, str(etype), rtype)
+                except Exception, ex:
+                    # the column probably already exists. this occurs when the
+                    # entity's type has just been added or if the column has not
+                    # been previously dropped
+                    self.error('error while altering table %s: %s', etype, ex)
+                # copy existant data.
+                # XXX don't use, it's not supported by sqlite (at least at when i tried it)
+                #sqlexec('UPDATE %(etype)s SET %(rtype)s=eid_to '
+                #        'FROM %(rtype)s_relation '
+                #        'WHERE %(etype)s.eid=%(rtype)s_relation.eid_from'
+                #        % locals())
+                table = SQL_PREFIX + str(etype)
+                cursor = sqlexec('SELECT eid_from, eid_to FROM %(table)s, '
+                                 '%(rtype)s_relation WHERE %(table)s.%(eidcolumn)s='
+                                 '%(rtype)s_relation.eid_from' % locals())
+                args = [{'val': eid_to, 'x': eid} for eid, eid_to in cursor.fetchall()]
+                if args:
+                    column = SQL_PREFIX + rtype
+                    cursor.executemany('UPDATE %s SET %s=%%(val)s WHERE %s=%%(x)s'
+                                       % (table, column, eidcolumn), args)
+                # drop existant table
+                DropRelationTable(session, rtype)
 
 
-class UpdateRelationDefOp(SchemaOperation):
+class SourceDbCWAttributeAdd(PreCommitOperation):
+    """an attribute relation (CWAttribute) has been added:
+    * add the necessary column
+    * set default on this column if any and possible
+    * register an operation to add the relation definition to the
+      instance's schema on commit
+
+    constraints are handled by specific hooks
+    """
+    entity = None # make pylint happy
+
+    def init_rdef(self, **kwargs):
+        entity = self.entity
+        fromentity = entity.stype
+        self.session.execute('SET X ordernum Y+1 '
+                             'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, '
+                             'X ordernum >= %(order)s, NOT X eid %(x)s',
+                             {'x': entity.eid, 'se': fromentity.eid,
+                              'order': entity.ordernum or 0})
+        subj = str(fromentity.name)
+        rtype = entity.rtype.name
+        obj = str(entity.otype.name)
+        constraints = get_constraints(self.session, entity)
+        rdef = RelationDefinition(subj, rtype, obj,
+                                  description=entity.description,
+                                  cardinality=entity.cardinality,
+                                  constraints=constraints,
+                                  order=entity.ordernum,
+                                  eid=entity.eid,
+                                  **kwargs)
+        MemSchemaRDefAdd(self.session, rdef)
+        return rdef
+
+    def precommit_event(self):
+        session = self.session
+        entity = self.entity
+        # entity.defaultval is a string or None, but we need a correctly typed
+        # value
+        default = entity.defaultval
+        if default is not None:
+            default = TYPE_CONVERTER[entity.otype.name](default)
+        rdef = self.init_rdef(default=default,
+                              indexed=entity.indexed,
+                              fulltextindexed=entity.fulltextindexed,
+                              internationalizable=entity.internationalizable)
+        sysource = session.pool.source('system')
+        attrtype = type_from_constraints(sysource.dbhelper, rdef.object,
+                                         rdef.constraints)
+        # XXX should be moved somehow into lgc.adbh: sqlite doesn't support to
+        # add a new column with UNIQUE, it should be added after the ALTER TABLE
+        # using ADD INDEX
+        if sysource.dbdriver == 'sqlite' and 'UNIQUE' in attrtype:
+            extra_unique_index = True
+            attrtype = attrtype.replace(' UNIQUE', '')
+        else:
+            extra_unique_index = False
+        # added some str() wrapping query since some backend (eg psycopg) don't
+        # allow unicode queries
+        table = SQL_PREFIX + rdef.subject
+        column = SQL_PREFIX + rdef.name
+        try:
+            session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s'
+                                   % (table, column, attrtype)),
+                               rollback_on_failure=False)
+            self.info('added column %s to table %s', table, column)
+        except Exception, ex:
+            # the column probably already exists. this occurs when
+            # the entity's type has just been added or if the column
+            # has not been previously dropped
+            self.error('error while altering table %s: %s', table, ex)
+        if extra_unique_index or entity.indexed:
+            try:
+                sysource.create_index(session, table, column,
+                                      unique=extra_unique_index)
+            except Exception, ex:
+                self.error('error while creating index for %s.%s: %s',
+                           table, column, ex)
+
+
+class SourceDbCWRelationAdd(SourceDbCWAttributeAdd):
+    """an actual relation has been added:
+    * if this is an inlined relation, add the necessary column
+      else if it's the first instance of this relation type, add the
+      necessary table and set default permissions
+    * register an operation to add the relation definition to the
+      instance's schema on commit
+
+    constraints are handled by specific hooks
+    """
+    entity = None # make pylint happy
+
+    def precommit_event(self):
+        session = self.session
+        entity = self.entity
+        rdef = self.init_rdef(composite=entity.composite)
+        schema = session.schema
+        rtype = rdef.name
+        rschema = session.schema.rschema(rtype)
+        # this have to be done before permissions setting
+        if rschema.inlined:
+            # need to add a column if the relation is inlined and if this is the
+            # first occurence of "Subject relation Something" whatever Something
+            # and if it has not been added during other event of the same
+            # transaction
+            key = '%s.%s' % (rdef.subject, rtype)
+            try:
+                alreadythere = bool(rschema.objects(rdef.subject))
+            except KeyError:
+                alreadythere = False
+            if not (alreadythere or
+                    key in session.transaction_data.get('createdattrs', ())):
+                add_inline_relation_column(session, rdef.subject, rtype)
+        else:
+            # need to create the relation if no relation definition in the
+            # schema and if it has not been added during other event of the same
+            # transaction
+            if not (rschema.subjects() or
+                    rtype in session.transaction_data.get('createdtables', ())):
+                try:
+                    rschema = session.schema.rschema(rtype)
+                    tablesql = rschema2sql(rschema)
+                except KeyError:
+                    # fake we add it to the schema now to get a correctly
+                    # initialized schema but remove it before doing anything
+                    # more dangerous...
+                    rschema = session.schema.add_relation_type(rdef)
+                    tablesql = rschema2sql(rschema)
+                    session.schema.del_relation_type(rtype)
+                # create the necessary table
+                for sql in tablesql.split(';'):
+                    if sql.strip():
+                        session.system_sql(sql)
+                session.transaction_data.setdefault('createdtables', []).append(
+                    rtype)
+
+
+class SourceDbRDefUpdate(PreCommitOperation):
     """actually update some properties of a relation definition"""
     rschema = values = None # make pylint happy
 
@@ -579,181 +430,51 @@
                                             self.values['cardinality'][0] != '1')
             self.session.system_sql(sql)
 
-    def commit_event(self):
-        # structure should be clean, not need to remove entity's relations
-        # at this point
-        self.rschema._rproperties[self.kobj].update(self.values)
 
-
-def after_update_erdef(session, entity):
-    desttype = entity.to_entity[0].name
-    rschema = session.repo.schema[entity.relation_type[0].name]
-    newvalues = {}
-    for prop in rschema.rproperty_defs(desttype):
-        if prop == 'constraints':
-            continue
-        if prop == 'order':
-            prop = 'ordernum'
-        if prop in entity:
-            newvalues[prop] = entity[prop]
-    if newvalues:
-        subjtype = entity.from_entity[0].name
-        UpdateRelationDefOp(session, (subjtype, desttype),
-                            rschema=rschema, values=newvalues)
-
-
-class UpdateRtypeOp(SchemaOperation):
-    """actually update some properties of a relation definition"""
-    rschema = values = entity = None # make pylint happy
-
-    def precommit_event(self):
-        session = self.session
-        rschema = self.rschema
-        if rschema.is_final() or not 'inlined' in self.values:
-            return # nothing to do
-        inlined = self.values['inlined']
-        entity = self.entity
-        if not entity.inlined_changed(inlined): # check in-lining is necessary/possible
-            return # nothing to do
-        # inlined changed, make necessary physical changes!
-        sqlexec = self.session.system_sql
-        rtype = rschema.type
-        eidcolumn = SQL_PREFIX + 'eid'
-        if not inlined:
-            # need to create the relation if it has not been already done by another
-            # event of the same transaction
-            if not rschema.type in session.transaction_data.get('createdtables', ()):
-                tablesql = rschema2sql(rschema)
-                # create the necessary table
-                for sql in tablesql.split(';'):
-                    if sql.strip():
-                        sqlexec(sql)
-                session.transaction_data.setdefault('createdtables', []).append(
-                    rschema.type)
-            # copy existant data
-            column = SQL_PREFIX + rtype
-            for etype in rschema.subjects():
-                table = SQL_PREFIX + str(etype)
-                sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL'
-                        % (rtype, eidcolumn, column, table, column))
-            # drop existant columns
-            for etype in rschema.subjects():
-                DropColumnOp(session, table=SQL_PREFIX + str(etype),
-                             column=SQL_PREFIX + rtype)
-        else:
-            for etype in rschema.subjects():
-                try:
-                    add_inline_relation_column(session, str(etype), rtype)
-                except Exception, ex:
-                    # the column probably already exists. this occurs when
-                    # the entity's type has just been added or if the column
-                    # has not been previously dropped
-                    self.error('error while altering table %s: %s', etype, ex)
-                # copy existant data.
-                # XXX don't use, it's not supported by sqlite (at least at when i tried it)
-                #sqlexec('UPDATE %(etype)s SET %(rtype)s=eid_to '
-                #        'FROM %(rtype)s_relation '
-                #        'WHERE %(etype)s.eid=%(rtype)s_relation.eid_from'
-                #        % locals())
-                table = SQL_PREFIX + str(etype)
-                cursor = sqlexec('SELECT eid_from, eid_to FROM %(table)s, '
-                                 '%(rtype)s_relation WHERE %(table)s.%(eidcolumn)s='
-                                 '%(rtype)s_relation.eid_from' % locals())
-                args = [{'val': eid_to, 'x': eid} for eid, eid_to in cursor.fetchall()]
-                if args:
-                    column = SQL_PREFIX + rtype
-                    cursor.executemany('UPDATE %s SET %s=%%(val)s WHERE %s=%%(x)s'
-                                       % (table, column, eidcolumn), args)
-                # drop existant table
-                DropTableOp(session, table='%s_relation' % rtype)
-
-    def commit_event(self):
-        # structure should be clean, not need to remove entity's relations
-        # at this point
-        self.rschema.__dict__.update(self.values)
-
-def after_update_ertype(session, entity):
-    rschema = session.repo.schema.rschema(entity.name)
-    newvalues = {}
-    for prop in ('meta', 'symetric', 'inlined'):
-        if prop in entity:
-            newvalues[prop] = entity[prop]
-    if newvalues:
-        UpdateRtypeOp(session, entity=entity, rschema=rschema, values=newvalues)
-
-# constraints synchronization #################################################
-
-from cubicweb.schema import CONSTRAINTS
-
-class ConstraintOp(SchemaOperation):
+class SourceDbCWConstraintAdd(PreCommitOperation):
     """actually update constraint of a relation definition"""
     entity = None # make pylint happy
-
-    def prepare_constraints(self, rtype, subjtype, objtype):
-        constraints = rtype.rproperty(subjtype, objtype, 'constraints')
-        self.constraints = list(constraints)
-        rtype.set_rproperty(subjtype, objtype, 'constraints', self.constraints)
-        return self.constraints
+    cancelled = False
 
     def precommit_event(self):
         rdef = self.entity.reverse_constrained_by[0]
         session = self.session
-        # when the relation is added in the same transaction, the constraint object
-        # is created by AddEN?FRDefPreCommitOp, there is nothing to do here
+        # when the relation is added in the same transaction, the constraint
+        # object is created by the operation adding the attribute or relation,
+        # so there is nothing to do here
         if rdef.eid in session.transaction_data.get('neweids', ()):
-            self.cancelled = True
             return
-        self.cancelled = False
-        schema = session.repo.schema
-        subjtype, rtype, objtype = schema.schema_by_eid(rdef.eid)
-        self.prepare_constraints(rtype, subjtype, objtype)
+        subjtype, rtype, objtype = session.schema.schema_by_eid(rdef.eid)
         cstrtype = self.entity.type
-        self.cstr = rtype.constraint_by_type(subjtype, objtype, cstrtype)
-        self._cstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
-        self._cstr.eid = self.entity.eid
+        oldcstr = rtype.constraint_by_type(subjtype, objtype, cstrtype)
+        newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
         table = SQL_PREFIX + str(subjtype)
         column = SQL_PREFIX + str(rtype)
         # alter the physical schema on size constraint changes
-        if self._cstr.type() == 'SizeConstraint' and (
-            self.cstr is None or self.cstr.max != self._cstr.max):
+        if newcstr.type() == 'SizeConstraint' and (
+            oldcstr is None or oldcstr.max != newcstr.max):
             adbh = self.session.pool.source('system').dbhelper
             card = rtype.rproperty(subjtype, objtype, 'cardinality')
-            coltype = type_from_constraints(adbh, objtype, [self._cstr],
+            coltype = type_from_constraints(adbh, objtype, [newcstr],
                                             creating=False)
             sql = adbh.sql_change_col_type(table, column, coltype, card != '1')
             try:
-                session.system_sql(sql)
+                session.system_sql(sql, rollback_on_failure=False)
                 self.info('altered column %s of table %s: now VARCHAR(%s)',
-                          column, table, self._cstr.max)
+                          column, table, newcstr.max)
             except Exception, ex:
                 # not supported by sqlite for instance
                 self.error('error while altering table %s: %s', table, ex)
-        elif cstrtype == 'UniqueConstraint':
+        elif cstrtype == 'UniqueConstraint' and oldcstr is None:
             session.pool.source('system').create_index(
                 self.session, table, column, unique=True)
 
-    def commit_event(self):
-        if self.cancelled:
-            return
-        # in-place modification
-        if not self.cstr is None:
-            self.constraints.remove(self.cstr)
-        self.constraints.append(self._cstr)
 
-
-def after_add_econstraint(session, entity):
-    ConstraintOp(session, entity=entity)
-
-def after_update_econstraint(session, entity):
-    ConstraintOp(session, entity=entity)
-
-
-class DelConstraintOp(ConstraintOp):
+class SourceDbCWConstraintDel(PreCommitOperation):
     """actually remove a constraint of a relation definition"""
     rtype = subjtype = objtype = None # make pylint happy
 
     def precommit_event(self):
-        self.prepare_constraints(self.rtype, self.subjtype, self.objtype)
         cstrtype = self.cstr.type()
         table = SQL_PREFIX + str(self.subjtype)
         column = SQL_PREFIX + str(self.rtype)
@@ -761,7 +482,8 @@
         if cstrtype == 'SizeConstraint':
             try:
                 self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
-                                        % (table, column))
+                                        % (table, column),
+                                        rollback_on_failure=False)
                 self.info('altered column %s of table %s: now TEXT',
                           column, table)
             except Exception, ex:
@@ -771,48 +493,143 @@
             self.session.pool.source('system').drop_index(
                 self.session, table, column, unique=True)
 
+
+# operations for in-memory schema synchronization  #############################
+
+class MemSchemaCWETypeAdd(MemSchemaEarlyOperation):
+    """actually add the entity type to the instance's schema"""
+    eid = None # make pylint happy
+    def commit_event(self):
+        self.schema.add_entity_type(self.kobj)
+
+
+class MemSchemaCWETypeRename(MemSchemaOperation):
+    """this operation updates physical storage accordingly"""
+    oldname = newname = None # make pylint happy
+
+    def commit_event(self):
+        self.session.schema.rename_entity_type(self.oldname, self.newname)
+
+
+class MemSchemaCWETypeDel(MemSchemaOperation):
+    """actually remove the entity type from the instance's schema"""
+    def commit_event(self):
+        try:
+            # del_entity_type also removes entity's relations
+            self.schema.del_entity_type(self.kobj)
+        except KeyError:
+            # s/o entity type have already been deleted
+            pass
+
+
+class MemSchemaCWRTypeAdd(MemSchemaEarlyOperation):
+    """actually add the relation type to the instance's schema"""
+    eid = None # make pylint happy
+    def commit_event(self):
+        rschema = self.schema.add_relation_type(self.kobj)
+        rschema.set_default_groups()
+
+
+class MemSchemaCWRTypeUpdate(MemSchemaOperation):
+    """actually update some properties of a relation definition"""
+    rschema = values = None # make pylint happy
+
+    def commit_event(self):
+        # structure should be clean, not need to remove entity's relations
+        # at this point
+        self.rschema.__dict__.update(self.values)
+
+
+class MemSchemaCWRTypeDel(MemSchemaOperation):
+    """actually remove the relation type from the instance's schema"""
+    def commit_event(self):
+        try:
+            self.schema.del_relation_type(self.kobj)
+        except KeyError:
+            # s/o entity type have already been deleted
+            pass
+
+
+class MemSchemaRDefAdd(MemSchemaEarlyOperation):
+    """actually add the attribute relation definition to the instance's
+    schema
+    """
+    def commit_event(self):
+        self.schema.add_relation_def(self.kobj)
+
+
+class MemSchemaRDefUpdate(MemSchemaOperation):
+    """actually update some properties of a relation definition"""
+    rschema = values = None # make pylint happy
+
+    def commit_event(self):
+        # structure should be clean, not need to remove entity's relations
+        # at this point
+        self.rschema._rproperties[self.kobj].update(self.values)
+
+
+class MemSchemaRDefDel(MemSchemaOperation):
+    """actually remove the relation definition from the instance's schema"""
+    def commit_event(self):
+        subjtype, rtype, objtype = self.kobj
+        try:
+            self.schema.del_relation_def(subjtype, rtype, objtype)
+        except KeyError:
+            # relation type may have been already deleted
+            pass
+
+
+class MemSchemaCWConstraintAdd(MemSchemaOperation):
+    """actually update constraint of a relation definition
+
+    has to be called before SourceDbCWConstraintAdd
+    """
+    cancelled = False
+
+    def precommit_event(self):
+        rdef = self.entity.reverse_constrained_by[0]
+        # when the relation is added in the same transaction, the constraint
+        # object is created by the operation adding the attribute or relation,
+        # so there is nothing to do here
+        if rdef.eid in self.session.transaction_data.get('neweids', ()):
+            self.cancelled = True
+            return
+        subjtype, rtype, objtype = self.session.schema.schema_by_eid(rdef.eid)
+        self.prepare_constraints(subjtype, rtype, objtype)
+        cstrtype = self.entity.type
+        self.cstr = rtype.constraint_by_type(subjtype, objtype, cstrtype)
+        self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
+        self.newcstr.eid = self.entity.eid
+
+    def commit_event(self):
+        if self.cancelled:
+            return
+        # in-place modification
+        if not self.cstr is None:
+            self.constraints.remove(self.cstr)
+        self.constraints.append(self.newcstr)
+
+
+class MemSchemaCWConstraintDel(MemSchemaOperation):
+    """actually remove a constraint of a relation definition
+
+    has to be called before SourceDbCWConstraintDel
+    """
+    rtype = subjtype = objtype = None # make pylint happy
+    def precommit_event(self):
+        self.prepare_constraints(self.subjtype, self.rtype, self.objtype)
+
     def commit_event(self):
         self.constraints.remove(self.cstr)
 
 
-def before_delete_constrained_by(session, fromeid, rtype, toeid):
-    if not fromeid in session.transaction_data.get('pendingeids', ()):
-        schema = session.repo.schema
-        entity = session.eid_rset(toeid).get_entity(0, 0)
-        subjtype, rtype, objtype = schema.schema_by_eid(fromeid)
-        try:
-            cstr = rtype.constraint_by_type(subjtype, objtype, entity.cstrtype[0].name)
-            DelConstraintOp(session, subjtype=subjtype, rtype=rtype, objtype=objtype,
-                            cstr=cstr)
-        except IndexError:
-            session.critical('constraint type no more accessible')
-
-
-def after_add_constrained_by(session, fromeid, rtype, toeid):
-    if fromeid in session.transaction_data.get('neweids', ()):
-        session.transaction_data.setdefault(fromeid, []).append(toeid)
-
-
-# schema permissions synchronization ##########################################
-
-class PermissionOp(Operation):
-    """base class to synchronize schema permission definitions"""
-    def __init__(self, session, perm, etype_eid):
-        self.perm = perm
-        try:
-            self.name = entity_name(session, etype_eid)
-        except IndexError:
-            self.error('changing permission of a no more existant type #%s',
-                etype_eid)
-        else:
-            Operation.__init__(self, session)
-
-class AddGroupPermissionOp(PermissionOp):
+class MemSchemaPermissionCWGroupAdd(MemSchemaPermissionOperation):
     """synchronize schema when a *_permission relation has been added on a group
     """
     def __init__(self, session, perm, etype_eid, group_eid):
         self.group = entity_name(session, group_eid)
-        PermissionOp.__init__(self, session, perm, etype_eid)
+        super(MemSchemaPermissionCWGroupAdd, self).__init__(
+            session, perm, etype_eid)
 
     def commit_event(self):
         """the observed connections pool has been commited"""
@@ -831,40 +648,11 @@
             groups.append(self.group)
             erschema.set_groups(self.perm, groups)
 
-class AddRQLExpressionPermissionOp(PermissionOp):
-    """synchronize schema when a *_permission relation has been added on a rql
-    expression
+
+class MemSchemaPermissionCWGroupDel(MemSchemaPermissionCWGroupAdd):
+    """synchronize schema when a *_permission relation has been deleted from a
+    group
     """
-    def __init__(self, session, perm, etype_eid, expression):
-        self.expr = expression
-        PermissionOp.__init__(self, session, perm, etype_eid)
-
-    def commit_event(self):
-        """the observed connections pool has been commited"""
-        try:
-            erschema = self.schema[self.name]
-        except KeyError:
-            # duh, schema not found, log error and skip operation
-            self.error('no schema for %s', self.name)
-            return
-        exprs = list(erschema.get_rqlexprs(self.perm))
-        exprs.append(erschema.rql_expression(self.expr))
-        erschema.set_rqlexprs(self.perm, exprs)
-
-def after_add_permission(session, subject, rtype, object):
-    """added entity/relation *_permission, need to update schema"""
-    perm = rtype.split('_', 1)[0]
-    if session.describe(object)[0] == 'CWGroup':
-        AddGroupPermissionOp(session, perm, subject, object)
-    else: # RQLExpression
-        expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
-                               {'x': object}, 'x')[0][0]
-        AddRQLExpressionPermissionOp(session, perm, subject, expr)
-
-
-
-class DelGroupPermissionOp(AddGroupPermissionOp):
-    """synchronize schema when a *_permission relation has been deleted from a group"""
 
     def commit_event(self):
         """the observed connections pool has been commited"""
@@ -883,8 +671,32 @@
                 self.perm, erschema.type, self.group)
 
 
-class DelRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
-    """synchronize schema when a *_permission relation has been deleted from an rql expression"""
+class MemSchemaPermissionRQLExpressionAdd(MemSchemaPermissionOperation):
+    """synchronize schema when a *_permission relation has been added on a rql
+    expression
+    """
+    def __init__(self, session, perm, etype_eid, expression):
+        self.expr = expression
+        super(MemSchemaPermissionRQLExpressionAdd, self).__init__(
+            session, perm, etype_eid)
+
+    def commit_event(self):
+        """the observed connections pool has been commited"""
+        try:
+            erschema = self.schema[self.name]
+        except KeyError:
+            # duh, schema not found, log error and skip operation
+            self.error('no schema for %s', self.name)
+            return
+        exprs = list(erschema.get_rqlexprs(self.perm))
+        exprs.append(erschema.rql_expression(self.expr))
+        erschema.set_rqlexprs(self.perm, exprs)
+
+
+class MemSchemaPermissionRQLExpressionDel(MemSchemaPermissionRQLExpressionAdd):
+    """synchronize schema when a *_permission relation has been deleted from an
+    rql expression
+    """
 
     def commit_event(self):
         """the observed connections pool has been commited"""
@@ -906,6 +718,283 @@
         erschema.set_rqlexprs(self.perm, rqlexprs)
 
 
+# deletion hooks ###############################################################
+
+def before_del_eetype(session, eid):
+    """before deleting a CWEType entity:
+    * check that we don't remove a core entity type
+    * cascade to delete related CWAttribute and CWRelation entities
+    * instantiate an operation to delete the entity type on commit
+    """
+    # final entities can't be deleted, don't care about that
+    name = check_internal_entity(session, eid, CORE_ETYPES)
+    # delete every entities of this type
+    session.unsafe_execute('DELETE %s X' % name)
+    DropTable(session, table=SQL_PREFIX + name)
+    MemSchemaCWETypeDel(session, name)
+
+
+def after_del_eetype(session, eid):
+    # workflow cleanup
+    session.execute('DELETE State X WHERE NOT X state_of Y')
+    session.execute('DELETE Transition X WHERE NOT X transition_of Y')
+
+
+def before_del_ertype(session, eid):
+    """before deleting a CWRType entity:
+    * check that we don't remove a core relation type
+    * cascade to delete related CWAttribute and CWRelation entities
+    * instantiate an operation to delete the relation type on commit
+    """
+    name = check_internal_entity(session, eid, CORE_RTYPES)
+    # delete relation definitions using this relation type
+    session.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s',
+                    {'x': eid})
+    session.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
+                    {'x': eid})
+    MemSchemaCWRTypeDel(session, name)
+
+
+def after_del_relation_type(session, rdefeid, rtype, rteid):
+    """before deleting a CWAttribute or CWRelation entity:
+    * if this is a final or inlined relation definition, instantiate an
+      operation to drop necessary column, else if this is the last instance
+      of a non final relation, instantiate an operation to drop necessary
+      table
+    * instantiate an operation to delete the relation definition on commit
+    * delete the associated relation type when necessary
+    """
+    subjschema, rschema, objschema = session.schema.schema_by_eid(rdefeid)
+    pendings = session.transaction_data.get('pendingeids', ())
+    # first delete existing relation if necessary
+    if rschema.is_final():
+        rdeftype = 'CWAttribute'
+    else:
+        rdeftype = 'CWRelation'
+        if not (subjschema.eid in pendings or objschema.eid in pendings):
+            session.execute('DELETE X %s Y WHERE X is %s, Y is %s'
+                            % (rschema, subjschema, objschema))
+    execute = session.unsafe_execute
+    rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R,'
+                   'R eid %%(x)s' % rdeftype, {'x': rteid})
+    lastrel = rset[0][0] == 0
+    # we have to update physical schema systematically for final and inlined
+    # relations, but only if it's the last instance for this relation type
+    # for other relations
+
+    if (rschema.is_final() or rschema.inlined):
+        rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, '
+                       'R eid %%(x)s, X from_entity E, E name %%(name)s'
+                       % rdeftype, {'x': rteid, 'name': str(subjschema)})
+        if rset[0][0] == 0 and not subjschema.eid in pendings:
+            ptypes = session.transaction_data.setdefault('pendingrtypes', set())
+            ptypes.add(rschema.type)
+            DropColumn(session, table=SQL_PREFIX + subjschema.type,
+                         column=SQL_PREFIX + rschema.type)
+    elif lastrel:
+        DropRelationTable(session, rschema.type)
+    # if this is the last instance, drop associated relation type
+    if lastrel and not rteid in pendings:
+        execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
+    MemSchemaRDefDel(session, (subjschema, rschema, objschema))
+
+
+# addition hooks ###############################################################
+
+def before_add_eetype(session, entity):
+    """before adding a CWEType entity:
+    * check that we are not using an existing entity type,
+    """
+    name = entity['name']
+    schema = session.schema
+    if name in schema and schema[name].eid is not None:
+        raise RepositoryError('an entity type %s already exists' % name)
+
+def after_add_eetype(session, entity):
+    """after adding a CWEType entity:
+    * create the necessary table
+    * set creation_date and modification_date by creating the necessary
+      CWAttribute entities
+    * add owned_by relation by creating the necessary CWRelation entity
+    * register an operation to add the entity type to the instance's
+      schema on commit
+    """
+    if entity.get('final'):
+        return
+    schema = session.schema
+    name = entity['name']
+    etype = EntityType(name=name, description=entity.get('description'),
+                       meta=entity.get('meta')) # don't care about final
+    # fake we add it to the schema now to get a correctly initialized schema
+    # but remove it before doing anything more dangerous...
+    schema = session.schema
+    eschema = schema.add_entity_type(etype)
+    eschema.set_default_groups()
+    # generate table sql and rql to add metadata
+    tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema,
+                           prefix=SQL_PREFIX)
+    relrqls = []
+    for rtype in (META_RTYPES - VIRTUAL_RTYPES):
+        rschema = schema[rtype]
+        sampletype = rschema.subjects()[0]
+        desttype = rschema.objects()[0]
+        props = rschema.rproperties(sampletype, desttype)
+        relrqls += list(ss.rdef2rql(rschema, name, desttype, props))
+    # now remove it !
+    schema.del_entity_type(name)
+    # create the necessary table
+    for sql in tablesql.split(';'):
+        if sql.strip():
+            session.system_sql(sql)
+    # register operation to modify the schema on commit
+    # this have to be done before adding other relations definitions
+    # or permission settings
+    etype.eid = entity.eid
+    MemSchemaCWETypeAdd(session, etype)
+    # add meta relations
+    for rql, kwargs in relrqls:
+        session.execute(rql, kwargs)
+
+
+def before_add_ertype(session, entity):
+    """before adding a CWRType entity:
+    * check that we are not using an existing relation type,
+    * register an operation to add the relation type to the instance's
+      schema on commit
+
+    We don't know yeat this point if a table is necessary
+    """
+    name = entity['name']
+    if name in session.schema.relations():
+        raise RepositoryError('a relation type %s already exists' % name)
+
+
+def after_add_ertype(session, entity):
+    """after a CWRType entity has been added:
+    * register an operation to add the relation type to the instance's
+      schema on commit
+    We don't know yeat this point if a table is necessary
+    """
+    rtype = RelationType(name=entity['name'],
+                         description=entity.get('description'),
+                         meta=entity.get('meta', False),
+                         inlined=entity.get('inlined', False),
+                         symetric=entity.get('symetric', False))
+    rtype.eid = entity.eid
+    MemSchemaCWRTypeAdd(session, rtype)
+
+
+def after_add_efrdef(session, entity):
+    SourceDbCWAttributeAdd(session, entity=entity)
+
+def after_add_enfrdef(session, entity):
+    SourceDbCWRelationAdd(session, entity=entity)
+
+
+# update hooks #################################################################
+
+def check_valid_changes(session, entity, ro_attrs=('name', 'final')):
+    errors = {}
+    # don't use getattr(entity, attr), we would get the modified value if any
+    for attr in ro_attrs:
+        origval = entity_attr(session, entity.eid, attr)
+        if entity.get(attr, origval) != origval:
+            errors[attr] = session._("can't change the %s attribute") % \
+                           display_name(session, attr)
+    if errors:
+        raise ValidationError(entity.eid, errors)
+
+def before_update_eetype(session, entity):
+    """check name change, handle final"""
+    check_valid_changes(session, entity, ro_attrs=('final',))
+    # don't use getattr(entity, attr), we would get the modified value if any
+    oldname = entity_attr(session, entity.eid, 'name')
+    newname = entity.get('name', oldname)
+    if newname.lower() != oldname.lower():
+        SourceDbCWETypeRename(session, oldname=oldname, newname=newname)
+        MemSchemaCWETypeRename(session, oldname=oldname, newname=newname)
+
+def before_update_ertype(session, entity):
+    """check name change, handle final"""
+    check_valid_changes(session, entity)
+
+
+def after_update_erdef(session, entity):
+    desttype = entity.otype.name
+    rschema = session.schema[entity.rtype.name]
+    newvalues = {}
+    for prop in rschema.rproperty_defs(desttype):
+        if prop == 'constraints':
+            continue
+        if prop == 'order':
+            prop = 'ordernum'
+        if prop in entity:
+            newvalues[prop] = entity[prop]
+    if newvalues:
+        subjtype = entity.stype.name
+        MemSchemaRDefUpdate(session, kobj=(subjtype, desttype),
+                            rschema=rschema, values=newvalues)
+        SourceDbRDefUpdate(session, kobj=(subjtype, desttype),
+                           rschema=rschema, values=newvalues)
+
+def after_update_ertype(session, entity):
+    rschema = session.schema.rschema(entity.name)
+    newvalues = {}
+    for prop in ('meta', 'symetric', 'inlined'):
+        if prop in entity:
+            newvalues[prop] = entity[prop]
+    if newvalues:
+        MemSchemaCWRTypeUpdate(session, rschema=rschema, values=newvalues)
+        SourceDbCWRTypeUpdate(session, rschema=rschema, values=newvalues,
+                              entity=entity)
+
+# constraints synchronization hooks ############################################
+
+def after_add_econstraint(session, entity):
+    MemSchemaCWConstraintAdd(session, entity=entity)
+    SourceDbCWConstraintAdd(session, entity=entity)
+
+
+def after_update_econstraint(session, entity):
+    MemSchemaCWConstraintAdd(session, entity=entity)
+    SourceDbCWConstraintAdd(session, entity=entity)
+
+
+def before_delete_constrained_by(session, fromeid, rtype, toeid):
+    if not fromeid in session.transaction_data.get('pendingeids', ()):
+        schema = session.schema
+        entity = session.entity_from_eid(toeid)
+        subjtype, rtype, objtype = schema.schema_by_eid(fromeid)
+        try:
+            cstr = rtype.constraint_by_type(subjtype, objtype,
+                                            entity.cstrtype[0].name)
+        except IndexError:
+            session.critical('constraint type no more accessible')
+        else:
+            SourceDbCWConstraintDel(session, subjtype=subjtype, rtype=rtype,
+                                    objtype=objtype, cstr=cstr)
+            MemSchemaCWConstraintDel(session, subjtype=subjtype, rtype=rtype,
+                                     objtype=objtype, cstr=cstr)
+
+
+def after_add_constrained_by(session, fromeid, rtype, toeid):
+    if fromeid in session.transaction_data.get('neweids', ()):
+        session.transaction_data.setdefault(fromeid, []).append(toeid)
+
+
+# permissions synchronization hooks ############################################
+
+def after_add_permission(session, subject, rtype, object):
+    """added entity/relation *_permission, need to update schema"""
+    perm = rtype.split('_', 1)[0]
+    if session.describe(object)[0] == 'CWGroup':
+        MemSchemaPermissionCWGroupAdd(session, perm, subject, object)
+    else: # RQLExpression
+        expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
+                               {'x': object}, 'x')[0][0]
+        MemSchemaPermissionRQLExpressionAdd(session, perm, subject, expr)
+
+
 def before_del_permission(session, subject, rtype, object):
     """delete entity/relation *_permission, need to update schema
 
@@ -915,18 +1004,18 @@
         return
     perm = rtype.split('_', 1)[0]
     if session.describe(object)[0] == 'CWGroup':
-        DelGroupPermissionOp(session, perm, subject, object)
+        MemSchemaPermissionCWGroupDel(session, perm, subject, object)
     else: # RQLExpression
         expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
                                {'x': object}, 'x')[0][0]
-        DelRQLExpressionPermissionOp(session, perm, subject, expr)
+        MemSchemaPermissionRQLExpressionDel(session, perm, subject, expr)
 
 
 def rebuild_infered_relations(session, subject, rtype, object):
     # registering a schema operation will trigger a call to
     # repo.set_schema() on commit which will in turn rebuild
     # infered relation definitions
-    UpdateSchemaOp(session)
+    MemSchemaNotifyChanges(session)
 
 
 def _register_schema_hooks(hm):
--- a/server/schemaserial.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/schemaserial.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 
 from yams import schema as schemamod, buildobjs as ybo
 
-from cubicweb.schema import CONSTRAINTS, ETYPE_NAME_MAP
+from cubicweb.schema import CONSTRAINTS, ETYPE_NAME_MAP, VIRTUAL_RTYPES
 from cubicweb.server import sqlutils
 
 def group_mapping(cursor, interactive=True):
@@ -114,10 +114,10 @@
     index = {}
     permsdict = deserialize_ertype_permissions(session)
     schema.reading_from_database = True
-    for eid, etype, desc, meta in session.execute('Any X, N, D, M WHERE '
-                                                  'X is CWEType, X name N, '
-                                                  'X description D, X meta M',
-                                                  build_descr=False):
+    for eid, etype, desc in session.execute('Any X, N, D WHERE '
+                                            'X is CWEType, X name N, '
+                                            'X description D',
+                                            build_descr=False):
         # base types are already in the schema, skip them
         if etype in schemamod.BASE_TYPES:
             # just set the eid
@@ -152,7 +152,7 @@
             repo.clear_caches(tocleanup)
             session.commit(False)
             etype = netype
-        etype = ybo.EntityType(name=etype, description=desc, meta=meta, eid=eid)
+        etype = ybo.EntityType(name=etype, description=desc, eid=eid)
         eschema = schema.add_entity_type(etype)
         index[eid] = eschema
         set_perms(eschema, permsdict.get(eid, {}))
@@ -167,9 +167,9 @@
             seschema = schema.eschema(stype)
             eschema._specialized_type = stype
             seschema._specialized_by.append(etype)
-    for eid, rtype, desc, meta, sym, il in session.execute(
-        'Any X,N,D,M,S,I WHERE X is CWRType, X name N, X description D, '
-        'X meta M, X symetric S, X inlined I', build_descr=False):
+    for eid, rtype, desc, sym, il in session.execute(
+        'Any X,N,D,S,I WHERE X is CWRType, X name N, X description D, '
+        'X symetric S, X inlined I', build_descr=False):
         try:
             # bw compat: fulltext_container added in 2.47
             ft_container = session.execute('Any FTC WHERE X eid %(x)s, X fulltext_container FTC',
@@ -177,7 +177,7 @@
         except:
             ft_container = None
             session.rollback(False)
-        rtype = ybo.RelationType(name=rtype, description=desc, meta=bool(meta),
+        rtype = ybo.RelationType(name=rtype, description=desc,
                                  symetric=bool(sym), inlined=bool(il),
                                  fulltext_container=ft_container, eid=eid)
         rschema = schema.add_relation_type(rtype)
@@ -284,17 +284,17 @@
     if not verbose:
         pb_size = len(aller) + len(CONSTRAINTS) + len([x for x in eschemas if x.specializes()])
         pb = ProgressBar(pb_size, title=_title)
+    rql = 'INSERT CWConstraintType X: X name %(ct)s'
     for cstrtype in CONSTRAINTS:
-        rql = 'INSERT CWConstraintType X: X name "%s"' % cstrtype
         if verbose:
             print rql
-        cursor.execute(rql)
+        cursor.execute(rql, {'ct': unicode(cstrtype)})
         if not verbose:
             pb.update()
     groupmap = group_mapping(cursor, interactive=False)
     for ertype in aller:
         # skip eid and has_text relations
-        if ertype in ('eid', 'identity', 'has_text',):
+        if ertype in VIRTUAL_RTYPES:
             pb.update()
             continue
         for rql, kwargs in erschema2rql(schema[ertype]):
@@ -327,7 +327,6 @@
         raise Exception("can't decode %s [was %s]" % (erschema.description, e))
     return {
         'name': type_,
-        'meta': erschema.meta,
         'final': erschema.is_final(),
         'description': desc,
         }
@@ -550,12 +549,12 @@
     relations, values = frdef_relations_values(rschema, objtype, props)
     values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
     yield 'SET %s WHERE %s, %s, X is CWAttribute' % (','.join(relations),
-                                                 _LOCATE_RDEF_RQL0,
-                                                 _LOCATE_RDEF_RQL1), values
+                                                     _LOCATE_RDEF_RQL0,
+                                                     _LOCATE_RDEF_RQL1), values
 
 def updatenfrdef2rql(rschema, subjtype, objtype, props):
     relations, values = nfrdef_relations_values(rschema, objtype, props)
     values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
     yield 'SET %s WHERE %s, %s, X is CWRelation' % (','.join(relations),
-                                                 _LOCATE_RDEF_RQL0,
-                                                 _LOCATE_RDEF_RQL1), values
+                                                    _LOCATE_RDEF_RQL0,
+                                                    _LOCATE_RDEF_RQL1), values
--- a/server/securityhooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/securityhooks.py	Fri Aug 07 12:20:50 2009 +0200
@@ -18,7 +18,11 @@
     # ._default_set is only there on entity creation to indicate unspecified
     # attributes which has been set to a default value defined in the schema
     defaults = getattr(entity, '_default_set', ())
-    for attr in entity.keys():
+    try:
+        editedattrs = entity.edited_attributes
+    except AttributeError:
+        editedattrs = entity.keys()
+    for attr in editedattrs:
         if attr in defaults:
             continue
         rschema = eschema.subject_relation(attr)
--- a/server/serverconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/serverconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -85,8 +85,8 @@
         SCHEMAS_LIB_DIR = '/usr/share/cubicweb/schemas/'
         BACKUP_DIR = '/var/lib/cubicweb/backup/'
 
-    cubicweb_vobject_path = CubicWebConfiguration.cubicweb_vobject_path | set(['sobjects'])
-    cube_vobject_path = CubicWebConfiguration.cube_vobject_path | set(['sobjects', 'hooks'])
+    cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['sobjects'])
+    cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['sobjects', 'hooks'])
 
     options = merge_options((
         # ctl configuration
@@ -165,13 +165,15 @@
           'group': 'email', 'inputlevel': 2,
           }),
         # pyro server.serverconfig
-        ('pyro-port',
+        ('pyro-host',
          {'type' : 'int',
           'default': None,
-          'help': 'Pyro server port. If not set, it will be choosen randomly',
+          'help': 'Pyro server host, if not detectable correctly through \
+gethostname(). It may contains port information using <host>:<port> notation, \
+and if not set, it will be choosen randomly',
           'group': 'pyro-server', 'inputlevel': 2,
           }),
-        ('pyro-id', # XXX reuse pyro-application-id
+        ('pyro-id', # XXX reuse pyro-instance-id
          {'type' : 'string',
           'default': None,
           'help': 'identifier of the repository in the pyro name server',
@@ -180,7 +182,7 @@
         ) + CubicWebConfiguration.options)
 
     # read the schema from the database
-    read_application_schema = True
+    read_instance_schema = True
     bootstrap_schema = True
 
     # check user's state at login time
@@ -193,7 +195,7 @@
     schema_hooks = True
     notification_hooks = True
     security_hooks = True
-    application_hooks = True
+    instance_hooks = True
 
     # should some hooks be deactivated during [pre|post]create script execution
     free_wheel = False
@@ -208,21 +210,16 @@
 
     @classmethod
     def schemas_lib_dir(cls):
-        """application schema directory"""
+        """instance schema directory"""
         return env_path('CW_SCHEMA_LIB', cls.SCHEMAS_LIB_DIR, 'schemas')
 
-    @classmethod
-    def backup_dir(cls):
-        """backup directory where a stored db backups before migration"""
-        return env_path('CW_BACKUP', cls.BACKUP_DIR, 'run time')
-
     def bootstrap_cubes(self):
-        from logilab.common.textutils import get_csv
+        from logilab.common.textutils import splitstrip
         for line in file(join(self.apphome, 'bootstrap_cubes')):
             line = line.strip()
             if not line or line.startswith('#'):
                 continue
-            self.init_cubes(self.expand_cubes(get_csv(line)))
+            self.init_cubes(self.expand_cubes(splitstrip(line)))
             break
         else:
             # no cubes
@@ -269,25 +266,8 @@
 
     def load_hooks(self, vreg):
         hooks = {}
-        for path in reversed([self.apphome] + self.cubes_path()):
-            hooksfile = join(path, 'application_hooks.py')
-            if exists(hooksfile):
-                self.warning('application_hooks.py is deprecated, use dynamic '
-                             'objects to register hooks (%s)', hooksfile)
-                context = {}
-                # Use execfile rather than `load_module_from_name` because
-                # the latter gets fooled by the `sys.modules` cache when
-                # loading different configurations one after the other
-                # (another fix would have been to do :
-                #    sys.modules.pop('applications_hooks')
-                #  or to modify load_module_from_name so that it provides
-                #  a use_cache optional parameter
-                execfile(hooksfile, context, context)
-                for event, hooksdef in context['HOOKS'].items():
-                    for ertype, hookcbs in hooksdef.items():
-                        hooks.setdefault(event, {}).setdefault(ertype, []).extend(hookcbs)
         try:
-            apphookdefs = vreg.registry_objects('hooks')
+            apphookdefs = vreg['hooks'].all_objects()
         except RegistryNotFound:
             return hooks
         for hookdef in apphookdefs:
@@ -342,9 +322,11 @@
         clear_cache(self, 'sources')
 
     def migration_handler(self, schema=None, interactive=True,
-                          cnx=None, repo=None, connect=True):
+                          cnx=None, repo=None, connect=True, verbosity=None):
         """return a migration handler instance"""
         from cubicweb.server.migractions import ServerMigrationHelper
+        if verbosity is None:
+            verbosity = getattr(self, 'verbosity', 0)
         return ServerMigrationHelper(self, schema, interactive=interactive,
                                      cnx=cnx, repo=repo, connect=connect,
-                                     verbosity=getattr(self, 'verbosity', 0))
+                                     verbosity=verbosity)
--- a/server/serverctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/serverctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,16 +5,17 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-__docformat__ = "restructuredtext en"
+__docformat__ = 'restructuredtext en'
 
 import sys
 import os
 
 from logilab.common.configuration import Configuration
 from logilab.common.clcommands import register_commands, cmd_run, pop_arg
+from logilab.common.shellutils import ASK
 
 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError, underline_title
-from cubicweb.toolsutils import Command, CommandHandler, confirm
+from cubicweb.toolsutils import Command, CommandHandler
 from cubicweb.server import SOURCE_TYPES
 from cubicweb.server.utils import ask_source_config
 from cubicweb.server.serverconfig import USER_OPTIONS, ServerConfiguration
@@ -58,10 +59,10 @@
 
 def system_source_cnx(source, dbms_system_base=False,
                       special_privs='CREATE/DROP DATABASE', verbose=True):
-    """shortcut to get a connextion to the application system database
+    """shortcut to get a connextion to the instance system database
     defined in the given config. If <dbms_system_base> is True,
     connect to the dbms system database instead (for task such as
-    create/drop the application database)
+    create/drop the instance database)
     """
     if dbms_system_base:
         from logilab.common.adbh import get_adv_func_helper
@@ -73,7 +74,9 @@
     """return a connection on the RDMS system table (to create/drop a user
     or a database
     """
+    import logilab.common as lgp
     from logilab.common.adbh import get_adv_func_helper
+    lgp.USE_MX_DATETIME = False
     special_privs = ''
     driver = source['db-driver']
     helper = get_adv_func_helper(driver)
@@ -117,7 +120,7 @@
     cfgname = 'repository'
 
     def bootstrap(self, cubes, inputlevel=0):
-        """create an application by copying files from the given cube and by
+        """create an instance by copying files from the given cube and by
         asking information necessary to build required configuration files
         """
         config = self.config
@@ -137,7 +140,7 @@
             if cube in SOURCE_TYPES:
                 sourcescfg[cube] = ask_source_config(cube, inputlevel)
         print
-        while confirm('Enter another source ?', default_is_yes=False):
+        while ASK.confirm('Enter another source ?', default_is_yes=False):
             available = sorted(stype for stype in SOURCE_TYPES
                                if not stype in cubes)
             while True:
@@ -167,7 +170,7 @@
         config.write_bootstrap_cubes_file(cubes)
 
     def postcreate(self):
-        if confirm('Do you want to run db-create to create the "system database" ?'):
+        if ASK.confirm('Run db-create to create the system database ?'):
             verbosity = (self.config.mode == 'installed') and 'y' or 'n'
             cmd_run('db-create', self.config.appid, '--verbose=%s' % verbosity)
         else:
@@ -180,12 +183,12 @@
     cfgname = 'repository'
 
     def cleanup(self):
-        """remove application's configuration and database"""
+        """remove instance's configuration and database"""
         from logilab.common.adbh import get_adv_func_helper
         source = self.config.sources()['system']
         dbname = source['db-name']
         helper = get_adv_func_helper(source['db-driver'])
-        if confirm('Delete database %s ?' % dbname):
+        if ASK.confirm('Delete database %s ?' % dbname):
             user = source['db-user'] or None
             cnx = _db_sys_cnx(source, 'DROP DATABASE', user=user)
             cursor = cnx.cursor()
@@ -194,7 +197,7 @@
                 print '-> database %s dropped.' % dbname
                 # XXX should check we are not connected as user
                 if user and helper.users_support and \
-                       confirm('Delete user %s ?' % user, default_is_yes=False):
+                       ASK.confirm('Delete user %s ?' % user, default_is_yes=False):
                     cursor.execute('DROP USER %s' % user)
                     print '-> user %s dropped.' % user
                 cnx.commit()
@@ -229,26 +232,26 @@
 
 
 # repository specific commands ################################################
-class CreateApplicationDBCommand(Command):
-    """Create the system database of an application (run after 'create').
+class CreateInstanceDBCommand(Command):
+    """Create the system database of an instance (run after 'create').
 
     You will be prompted for a login / password to use to connect to
     the system database.  The given user should have almost all rights
     on the database (ie a super user on the dbms allowed to create
     database, users, languages...).
 
-    <application>
-      the identifier of the application to initialize.
+    <instance>
+      the identifier of the instance to initialize.
     """
     name = 'db-create'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = (
-        ("create-db",
-         {'short': 'c', 'type': "yn", 'metavar': '<y or n>',
+        ('create-db',
+         {'short': 'c', 'type': 'yn', 'metavar': '<y or n>',
           'default': True,
           'help': 'create the database (yes by default)'}),
-        ("verbose",
+        ('verbose',
          {'short': 'v', 'type' : 'yn', 'metavar': '<verbose>',
           'default': 'n',
           'help': 'verbose mode: will ask all possible configuration questions',
@@ -260,14 +263,14 @@
         from logilab.common.adbh import get_adv_func_helper
         from indexer import get_indexer
         verbose = self.get('verbose')
-        appid = pop_arg(args, msg="No application specified !")
+        appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         create_db = self.config.create_db
         source = config.sources()['system']
         driver = source['db-driver']
         helper = get_adv_func_helper(driver)
         if create_db:
-            print '\n'+underline_title('Creating the "system database"')
+            print '\n'+underline_title('Creating the system database')
             # connect on the dbms system base to create our base
             dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose)
             cursor = dbcnx.cursor()
@@ -275,12 +278,12 @@
                 if helper.users_support:
                     user = source['db-user']
                     if not helper.user_exists(cursor, user) and \
-                           confirm('Create db user %s ?' % user, default_is_yes=False):
+                           ASK.confirm('Create db user %s ?' % user, default_is_yes=False):
                         helper.create_user(source['db-user'], source['db-password'])
                         print '-> user %s created.' % user
                 dbname = source['db-name']
                 if dbname in helper.list_databases(cursor):
-                    if confirm('Database %s already exists -- do you want to drop it ?' % dbname):
+                    if ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname):
                         cursor.execute('DROP DATABASE %s' % dbname)
                     else:
                         return
@@ -306,30 +309,30 @@
                 helper.create_language(cursor, extlang)
         cursor.close()
         cnx.commit()
-        print '-> database for application %s created and necessary extensions installed.' % appid
+        print '-> database for instance %s created and necessary extensions installed.' % appid
         print
-        if confirm('Do you want to run db-init to initialize the "system database" ?'):
+        if ASK.confirm('Run db-init to initialize the system database ?'):
             cmd_run('db-init', config.appid)
         else:
             print ('-> nevermind, you can do it later with '
                    '"cubicweb-ctl db-init %s".' % self.config.appid)
 
 
-class InitApplicationCommand(Command):
-    """Initialize the system database of an application (run after 'db-create').
+class InitInstanceCommand(Command):
+    """Initialize the system database of an instance (run after 'db-create').
 
     You will be prompted for a login / password to use to connect to
     the system database.  The given user should have the create tables,
     and grant permissions.
 
-    <application>
-      the identifier of the application to initialize.
+    <instance>
+      the identifier of the instance to initialize.
     """
     name = 'db-init'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = (
-        ("drop",
+        ('drop',
          {'short': 'd', 'action': 'store_true',
           'default': False,
           'help': 'insert drop statements to remove previously existant \
@@ -337,27 +340,27 @@
         )
 
     def run(self, args):
-        print '\n'+underline_title('Initializing the "system database"')
+        print '\n'+underline_title('Initializing the system database')
         from cubicweb.server import init_repository
-        appid = pop_arg(args, msg="No application specified !")
+        appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         init_repository(config, drop=self.config.drop)
 
 
-class GrantUserOnApplicationCommand(Command):
+class GrantUserOnInstanceCommand(Command):
     """Grant a database user on a repository system database.
 
-    <application>
-      the identifier of the application
+    <instance>
+      the identifier of the instance
     <user>
       the database's user requiring grant access
     """
     name = 'db-grant-user'
-    arguments = '<application> <user>'
+    arguments = '<instance> <user>'
 
     options = (
-        ("set-owner",
-         {'short': 'o', 'type' : "yn", 'metavar' : '<yes or no>',
+        ('set-owner',
+         {'short': 'o', 'type' : 'yn', 'metavar' : '<yes or no>',
           'default' : False,
           'help': 'Set the user as tables owner if yes (no by default).'}
          ),
@@ -365,8 +368,8 @@
     def run(self, args):
         """run the command with its specific arguments"""
         from cubicweb.server.sqlutils import sqlexec, sqlgrants
-        appid = pop_arg(args, 1, msg="No application specified !")
-        user = pop_arg(args, msg="No user specified !")
+        appid = pop_arg(args, 1, msg='No instance specified !')
+        user = pop_arg(args, msg='No user specified !')
         config = ServerConfiguration.config_for(appid)
         source = config.sources()['system']
         set_owner = self.config.set_owner
@@ -383,22 +386,22 @@
             print '-> an error occured:', ex
         else:
             cnx.commit()
-            print '-> rights granted to %s on application %s.' % (appid, user)
+            print '-> rights granted to %s on instance %s.' % (appid, user)
 
 class ResetAdminPasswordCommand(Command):
     """Reset the administrator password.
 
-    <application>
-      the identifier of the application
+    <instance>
+      the identifier of the instance
     """
     name = 'reset-admin-pwd'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     def run(self, args):
         """run the command with its specific arguments"""
         from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX
         from cubicweb.server.utils import crypt_password, manager_userpasswd
-        appid = pop_arg(args, 1, msg="No application specified !")
+        appid = pop_arg(args, 1, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         sourcescfg = config.read_sources_file()
         try:
@@ -431,31 +434,37 @@
 
 
 class StartRepositoryCommand(Command):
-    """Start an CubicWeb RQL server for a given application.
+    """Start an CubicWeb RQL server for a given instance.
 
     The server will be accessible through pyro
 
-    <application>
-      the identifier of the application to initialize.
+    <instance>
+      the identifier of the instance to initialize.
     """
     name = 'start-repository'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = (
-        ("debug",
+        ('debug',
          {'short': 'D', 'action' : 'store_true',
           'help': 'start server in debug mode.'}),
         )
 
     def run(self, args):
         from cubicweb.server.server import RepositoryServer
-        appid = pop_arg(args, msg="No application specified !")
+        appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         debug = self.config.debug
         # create the server
         server = RepositoryServer(config, debug)
         # go ! (don't daemonize in debug mode)
-        if not debug and server.daemonize(config['pid-file']) == -1:
+        pidfile = config['pid-file']
+        # ensure the directory where the pid-file should be set exists (for
+        # instance /var/run/cubicweb may be deleted on computer restart)
+        piddir = os.path.dirname(pidfile)
+        if not os.path.exists(piddir):
+            os.makedirs(piddir)
+        if not debug and server.daemonize(pidfile) == -1:
             return
         uid = config['uid']
         if uid is not None:
@@ -471,6 +480,7 @@
 
 
 def _remote_dump(host, appid, output, sudo=False):
+    # XXX generate unique/portable file name
     dmpcmd = 'cubicweb-ctl db-dump -o /tmp/%s.dump %s' % (appid, appid)
     if sudo:
         dmpcmd = 'sudo %s' % (dmpcmd)
@@ -488,21 +498,24 @@
         raise ExecutionError('Error while retrieving the dump')
     rmcmd = 'ssh -t %s "rm -f /tmp/%s.dump"' % (host, appid)
     print rmcmd
-    if os.system(rmcmd) and not confirm(
+    if os.system(rmcmd) and not ASK.confirm(
         'An error occured while deleting remote dump. Continue anyway?'):
         raise ExecutionError('Error while deleting remote dump')
 
 def _local_dump(appid, output):
     config = ServerConfiguration.config_for(appid)
     # schema=1 to avoid unnecessary schema loading
-    mih = config.migration_handler(connect=False, schema=1)
+    mih = config.migration_handler(connect=False, schema=1, verbosity=1)
     mih.backup_database(output, askconfirm=False)
+    mih.shutdown()
 
-def _local_restore(appid, backupfile, drop):
+def _local_restore(appid, backupfile, drop, systemonly=True):
     config = ServerConfiguration.config_for(appid)
+    config.verbosity = 1 # else we won't be asked for confirmation on problems
+    config.repairing = 1 # don't check versions
     # schema=1 to avoid unnecessary schema loading
-    mih = config.migration_handler(connect=False, schema=1)
-    mih.restore_database(backupfile, drop)
+    mih = config.migration_handler(connect=False, schema=1, verbosity=1)
+    mih.restore_database(backupfile, drop, systemonly, askconfirm=False)
     repo = mih.repo_connect()
     # version of the database
     dbversions = repo.get_versions()
@@ -512,7 +525,7 @@
         return
     # version of installed software
     eversion = dbversions['cubicweb']
-    status = application_status(config, eversion, dbversions)
+    status = instance_status(config, eversion, dbversions)
     # * database version > installed software
     if status == 'needsoftupgrade':
         print "database is using some earlier version than installed software!"
@@ -530,7 +543,7 @@
     #   ok!
 
 
-def application_status(config, cubicwebapplversion, vcconf):
+def instance_status(config, cubicwebapplversion, vcconf):
     cubicwebversion = config.cubicweb_version()
     if cubicwebapplversion > cubicwebversion:
         return 'needsoftupgrade'
@@ -540,12 +553,12 @@
         try:
             softversion = config.cube_version(cube)
         except ConfigurationError:
-            print "-> Error: no cube version information for %s, please check that the cube is installed." % cube
+            print '-> Error: no cube version information for %s, please check that the cube is installed.' % cube
             continue
         try:
             applversion = vcconf[cube]
         except KeyError:
-            print "-> Error: no cube version information for %s in version configuration." % cube
+            print '-> Error: no cube version information for %s in version configuration.' % cube
             continue
         if softversion == applversion:
             continue
@@ -557,18 +570,18 @@
 
 
 class DBDumpCommand(Command):
-    """Backup the system database of an application.
+    """Backup the system database of an instance.
 
-    <application>
-      the identifier of the application to backup
+    <instance>
+      the identifier of the instance to backup
       format [[user@]host:]appname
     """
     name = 'db-dump'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = (
-        ("output",
-         {'short': 'o', 'type' : "string", 'metavar' : '<file>',
+        ('output',
+         {'short': 'o', 'type' : 'string', 'metavar' : '<file>',
           'default' : None,
           'help': 'Specify the backup file where the backup will be stored.'}
          ),
@@ -580,7 +593,7 @@
         )
 
     def run(self, args):
-        appid = pop_arg(args, 1, msg="No application specified !")
+        appid = pop_arg(args, 1, msg='No instance specified !')
         if ':' in appid:
             host, appid = appid.split(':')
             _remote_dump(host, appid, self.config.output, self.config.sudo)
@@ -589,50 +602,58 @@
 
 
 class DBRestoreCommand(Command):
-    """Restore the system database of an application.
+    """Restore the system database of an instance.
 
-    <application>
-      the identifier of the application to restore
+    <instance>
+      the identifier of the instance to restore
     """
     name = 'db-restore'
-    arguments = '<application> <backupfile>'
+    arguments = '<instance> <backupfile>'
 
     options = (
-        ("no-drop",
-         {'short': 'n', 'action' : 'store_true',
-          'default' : False,
+        ('no-drop',
+         {'short': 'n', 'action' : 'store_true', 'default' : False,
           'help': 'for some reason the database doesn\'t exist and so '
           'should not be dropped.'}
          ),
+        ('restore-all',
+         {'short': 'r', 'action' : 'store_true', 'default' : False,
+          'help': 'restore everything, eg not only the system source database '
+          'but also data for all sources supporting backup/restore and custom '
+          'instance data. In that case, <backupfile> is expected to be the '
+          'timestamp of the backup to restore, not a file'}
+         ),
         )
 
     def run(self, args):
-        appid = pop_arg(args, 1, msg="No application specified !")
-        backupfile = pop_arg(args, msg="No backup file specified !")
-        _local_restore(appid, backupfile, not self.config.no_drop)
+        appid = pop_arg(args, 1, msg='No instance specified !')
+        backupfile = pop_arg(args, msg='No backup file or timestamp specified !')
+        _local_restore(appid, backupfile,
+                       drop=not self.config.no_drop,
+                       systemonly=not self.config.restore_all)
 
 
 class DBCopyCommand(Command):
-    """Copy the system database of an application (backup and restore).
+    """Copy the system database of an instance (backup and restore).
 
-    <src-application>
-      the identifier of the application to backup
+    <src-instance>
+      the identifier of the instance to backup
       format [[user@]host:]appname
 
-    <dest-application>
-      the identifier of the application to restore
+    <dest-instance>
+      the identifier of the instance to restore
     """
     name = 'db-copy'
-    arguments = '<src-application> <dest-application>'
+    arguments = '<src-instance> <dest-instance>'
 
     options = (
-        ("no-drop",
+        ('no-drop',
          {'short': 'n', 'action' : 'store_true',
           'default' : False,
           'help': 'For some reason the database doesn\'t exist and so '
           'should not be dropped.'}
          ),
-        ("keep-dump",
+        ('keep-dump',
          {'short': 'k', 'action' : 'store_true',
           'default' : False,
           'help': 'Specify that the dump file should not be automatically removed.'}
@@ -646,9 +667,11 @@
 
     def run(self, args):
         import tempfile
-        srcappid = pop_arg(args, 1, msg="No source application specified !")
-        destappid = pop_arg(args, msg="No destination application specified !")
-        output = tempfile.mktemp()
+        srcappid = pop_arg(args, 1, msg='No source instance specified !')
+        destappid = pop_arg(args, msg='No destination instance specified !')
+        # XXX -system necessary to match file name modified on source restore.
+        # should not have to expect this.
+        _, output = tempfile.mkstemp('-system.sql')
         if ':' in srcappid:
             host, srcappid = srcappid.split(':')
             _remote_dump(host, srcappid, output, self.config.sudo)
@@ -662,60 +685,66 @@
 
 
 class CheckRepositoryCommand(Command):
-    """Check integrity of the system database of an application.
+    """Check integrity of the system database of an instance.
 
-    <application>
-      the identifier of the application to check
+    <instance>
+      the identifier of the instance to check
     """
     name = 'db-check'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = (
-        ("checks",
-         {'short': 'c', 'type' : "csv", 'metavar' : '<check list>',
+        ('checks',
+         {'short': 'c', 'type' : 'csv', 'metavar' : '<check list>',
           'default' : ('entities', 'relations', 'metadata', 'schema', 'text_index'),
           'help': 'Comma separated list of check to run. By default run all \
 checks, i.e. entities, relations, text_index and metadata.'}
          ),
 
-        ("autofix",
-         {'short': 'a', 'type' : "yn", 'metavar' : '<yes or no>',
+        ('autofix',
+         {'short': 'a', 'type' : 'yn', 'metavar' : '<yes or no>',
           'default' : False,
           'help': 'Automatically correct integrity problems if this option \
 is set to "y" or "yes", else only display them'}
          ),
-        ("reindex",
-         {'short': 'r', 'type' : "yn", 'metavar' : '<yes or no>',
+        ('reindex',
+         {'short': 'r', 'type' : 'yn', 'metavar' : '<yes or no>',
           'default' : False,
           'help': 're-indexes the database for full text search if this \
 option is set to "y" or "yes" (may be long for large database).'}
          ),
+        ('force',
+         {'short': 'f', 'action' : 'store_true',
+          'default' : False,
+          'help': 'don\'t check instance is up to date.'}
+         ),
 
         )
 
     def run(self, args):
         from cubicweb.server.checkintegrity import check
-        appid = pop_arg(args, 1, msg="No application specified !")
+        appid = pop_arg(args, 1, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
+        config.repairing = self.config.force
         repo, cnx = repo_cnx(config)
         check(repo, cnx,
               self.config.checks, self.config.reindex, self.config.autofix)
 
 
 class RebuildFTICommand(Command):
-    """Rebuild the full-text index of the system database of an application.
+    """Rebuild the full-text index of the system database of an instance.
 
-    <application>
-      the identifier of the application to rebuild
+    <instance>
+      the identifier of the instance to rebuild
     """
     name = 'db-rebuild-fti'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     options = ()
 
     def run(self, args):
         from cubicweb.server.checkintegrity import reindex_entities
-        appid = pop_arg(args, 1, msg="No application specified !")
+        appid = pop_arg(args, 1, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         repo, cnx = repo_cnx(config)
         session = repo._get_session(cnx.sessionid, setpool=True)
@@ -723,28 +752,28 @@
         cnx.commit()
 
 
-class SynchronizeApplicationSchemaCommand(Command):
+class SynchronizeInstanceSchemaCommand(Command):
     """Synchronize persistent schema with cube schema.
 
     Will synchronize common stuff between the cube schema and the
     actual persistent schema, but will not add/remove any entity or relation.
 
-    <application>
-      the identifier of the application to synchronize.
+    <instance>
+      the identifier of the instance to synchronize.
     """
     name = 'schema-sync'
-    arguments = '<application>'
+    arguments = '<instance>'
 
     def run(self, args):
-        appid = pop_arg(args, msg="No application specified !")
+        appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         mih = config.migration_handler()
         mih.cmd_synchronize_schema()
 
 
-register_commands( (CreateApplicationDBCommand,
-                    InitApplicationCommand,
-                    GrantUserOnApplicationCommand,
+register_commands( (CreateInstanceDBCommand,
+                    InitInstanceCommand,
+                    GrantUserOnInstanceCommand,
                     ResetAdminPasswordCommand,
                     StartRepositoryCommand,
                     DBDumpCommand,
@@ -752,5 +781,5 @@
                     DBCopyCommand,
                     CheckRepositoryCommand,
                     RebuildFTICommand,
-                    SynchronizeApplicationSchemaCommand,
+                    SynchronizeInstanceSchemaCommand,
                     ) )
--- a/server/session.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/session.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,7 +11,7 @@
 import threading
 from time import time
 
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 from rql.nodes import VariableRef, Function, ETYPE_PYOBJ_MAP, etype_from_pyobj
 from yams import BASE_TYPES
 
@@ -40,8 +40,6 @@
         description.append(term.get_type(solution, args))
     return description
 
-from rql import stmts
-assert hasattr(stmts.Union, 'get_variable_variables'), "You need RQL > 0.18.3"
 
 class Session(RequestSessionMixIn):
     """tie session id, user, connections pool and other session data all
@@ -75,21 +73,81 @@
     def __str__(self):
         return '<%ssession %s (%s 0x%x)>' % (self.cnxtype, self.user.login,
                                              self.id, id(self))
+
+    @property
+    def schema(self):
+        return self.repo.schema
+
+    def add_relation(self, fromeid, rtype, toeid):
+        if self.is_super_session:
+            self.repo.glob_add_relation(self, fromeid, rtype, toeid)
+            return
+        self.is_super_session = True
+        try:
+            self.repo.glob_add_relation(self, fromeid, rtype, toeid)
+        finally:
+            self.is_super_session = False
+
+    def update_rel_cache_add(self, subject, rtype, object, symetric=False):
+        self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
+        if symetric:
+            self._update_entity_rel_cache_add(object, rtype, 'subject', subject)
+        else:
+            self._update_entity_rel_cache_add(object, rtype, 'object', subject)
+
+    def update_rel_cache_del(self, subject, rtype, object, symetric=False):
+        self._update_entity_rel_cache_del(subject, rtype, 'subject', object)
+        if symetric:
+            self._update_entity_rel_cache_del(object, rtype, 'object', object)
+        else:
+            self._update_entity_rel_cache_del(object, rtype, 'object', subject)
+
+    def _rel_cache(self, eid, rtype, role):
+        try:
+            entity = self.entity_cache(eid)
+        except KeyError:
+            return
+        return entity.relation_cached(rtype, role)
+
+    def _update_entity_rel_cache_add(self, eid, rtype, role, targeteid):
+        rcache = self._rel_cache(eid, rtype, role)
+        if rcache is not None:
+            rset, entities = rcache
+            rset.rows.append([targeteid])
+            if isinstance(rset.description, list): # else description not set
+                rset.description.append([self.describe(targeteid)[0]])
+            rset.rowcount += 1
+            targetentity = self.entity_from_eid(targeteid)
+            entities.append(targetentity)
+
+    def _update_entity_rel_cache_del(self, eid, rtype, role, targeteid):
+        rcache = self._rel_cache(eid, rtype, role)
+        if rcache is not None:
+            rset, entities = rcache
+            for idx, row in enumerate(rset.rows):
+                if row[0] == targeteid:
+                    break
+            else:
+                raise Exception('cache inconsistency for %s %s %s %s' %
+                                (eid, rtype, role, targeteid))
+            del rset.rows[idx]
+            if isinstance(rset.description, list): # else description not set
+                del rset.description[idx]
+            del entities[idx]
+            rset.rowcount -= 1
+
     # resource accessors ######################################################
 
     def actual_session(self):
         """return the original parent session if any, else self"""
         return self
 
-    def etype_class(self, etype):
-        """return an entity class for the given entity type"""
-        return self.vreg.etype_class(etype)
-
-    def system_sql(self, sql, args=None):
+    def system_sql(self, sql, args=None, rollback_on_failure=True):
         """return a sql cursor on the system database"""
         if not sql.split(None, 1)[0].upper() == 'SELECT':
             self.mode = 'write'
-        return self.pool.source('system').doexec(self, sql, args)
+        return self.pool.source('system').doexec(self, sql, args,
+                                                 rollback=rollback_on_failure)
 
     def set_language(self, language):
         """i18n configuration for translation"""
@@ -207,15 +265,40 @@
     # request interface #######################################################
 
     def set_entity_cache(self, entity):
-        # no entity cache in the server, too high risk of inconsistency
-        # between pre/post hooks
-        pass
+        # XXX session level caching may be a pb with multiple repository
+        #     instances, but 1. this is probably not the only one :$ and 2. it
+        #     may be an acceptable risk. Anyway we could activate it or not
+        #     according to a configuration option
+        try:
+            self.transaction_data['ecache'].setdefault(entity.eid, entity)
+        except KeyError:
+            self.transaction_data['ecache'] = ecache = {}
+            ecache[entity.eid] = entity
 
     def entity_cache(self, eid):
-        raise KeyError(eid)
+        try:
+            return self.transaction_data['ecache'][eid]
+        except:
+            raise
+
+    def cached_entities(self):
+        return self.transaction_data.get('ecache', {}).values()
+
+    def drop_entity_cache(self, eid=None):
+        if eid is None:
+            self.transaction_data.pop('ecache', None)
+        else:
+            del self.transaction_data['ecache'][eid]
 
     def base_url(self):
-        return self.repo.config['base-url'] or u''
+        url = self.repo.config['base-url']
+        if not url:
+            try:
+                url = self.repo.config.default_base_url()
+            except AttributeError: # default_base_url() might not be available
+                self.warning('missing base-url definition in server config')
+                url = u''
+        return url
 
     def from_controller(self):
         """return the id (string) of the controller issuing the request (no
@@ -255,7 +338,7 @@
         self.set_pool()
         return csession
 
-    def unsafe_execute(self, rql, kwargs=None, eid_key=None, build_descr=False,
+    def unsafe_execute(self, rql, kwargs=None, eid_key=None, build_descr=True,
                        propagate=False):
         """like .execute but with security checking disabled (this method is
         internal to the server, it's not part of the db-api)
@@ -468,7 +551,12 @@
             description.append(tuple(row_descr))
         return description
 
-    @obsolete('use direct access to session.transaction_data')
+    @deprecated("use vreg['etypes'].etype_class(etype)")
+    def etype_class(self, etype):
+        """return an entity class for the given entity type"""
+        return self.vreg['etypes'].etype_class(etype)
+
+    @deprecated('use direct access to session.transaction_data')
     def query_data(self, key, default=None, setdefault=False, pop=False):
         if setdefault:
             assert not pop
@@ -478,10 +566,10 @@
         else:
             return self.transaction_data.get(key, default)
 
-    @obsolete('use entity_from_eid(eid, etype=None)')
+    @deprecated('use entity_from_eid(eid, etype=None)')
     def entity(self, eid):
         """return a result set for the given eid"""
-        return self.eid_rset(eid).get_entity(0, 0)
+        return self.entity_from_eid(eid)
 
 
 class ChildSession(Session):
--- a/server/sources/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sources/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,13 +7,37 @@
 """
 __docformat__ = "restructuredtext en"
 
+from os.path import join, splitext
 from datetime import datetime, timedelta
 from logging import getLogger
 
-from cubicweb import set_log_methods
+from cubicweb import set_log_methods, server
+from cubicweb.schema import VIRTUAL_RTYPES
 from cubicweb.server.sqlutils import SQL_PREFIX
 
 
+def dbg_st_search(uri, union, varmap, args, cachekey=None, prefix='rql for'):
+    if server.DEBUG & server.DBG_RQL:
+        print '  %s %s source: %s' % (prefix, uri, union.as_string())
+        if varmap:
+            print '    using varmap', varmap
+        if server.DEBUG & server.DBG_MORE:
+            print '    args', args
+            print '    cache key', cachekey
+            print '    solutions', ','.join(str(s.solutions)
+                                            for s in union.children)
+    # return true so it can be used as assertion (and so be killed by python -O)
+    return True
+
+def dbg_results(results):
+    if server.DEBUG & server.DBG_RQL:
+        if len(results) > 10:
+            print '  -->', results[:10], '...', len(results)
+        else:
+            print '  -->', results
+    # return true so it can be used as assertion (and so be killed by python -O)
+    return True
+
 class TimedCache(dict):
     def __init__(self, ttlm, ttls=0):
         # time to live in minutes
@@ -53,7 +77,7 @@
     uri = None
     # a reference to the system information helper
     repo = None
-    # a reference to the application'schema (may differs from the source'schema)
+    # a reference to the instance'schema (may differs from the source'schema)
     schema = None
 
     def __init__(self, repo, appschema, source_config, *args, **kwargs):
@@ -71,6 +95,42 @@
         """method called by the repository once ready to handle request"""
         pass
 
+    def backup_file(self, backupfile=None, timestamp=None):
+        """return a unique file name for a source's dump
+
+        either backupfile or timestamp (used to generated a backup file name if
+        needed) should be specified.
+        """
+        if backupfile is None:
+            config = self.repo.config
+            return join(config.appdatahome, 'backup',
+                        '%s-%s-%s.dump' % (config.appid, timestamp, self.uri))
+        # backup file is the system database backup file, add uri to it if not
+        # already there
+        base, ext = splitext(backupfile)
+        if not base.endswith('-%s' % self.uri):
+            return '%s-%s%s' % (base, self.uri, ext)
+        return backupfile
+
+    def backup(self, confirm, backupfile=None, timestamp=None,
+               askconfirm=False):
+        """method called to create a backup of source's data"""
+        pass
+
+    def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+               askconfirm=False):
+        """method called to restore a backup of source's data"""
+        pass
+
+    def close_pool_connections(self):
+        for pool in self.repo.pools:
+            pool._cursors.pop(self.uri, None)
+            pool.source_cnxs[self.uri][1].close()
+
+    def open_pool_connections(self):
+        for pool in self.repo.pools:
+            pool.source_cnxs[self.uri] = (self, self.get_connection())
+
     def reset_caches(self):
         """method called during test to reset potential source caches"""
         pass
@@ -95,7 +155,7 @@
         return cmp(self.uri, other.uri)
 
     def set_schema(self, schema):
-        """set the application'schema"""
+        """set the instance'schema"""
         self.schema = schema
 
     def support_entity(self, etype, write=False):
@@ -163,7 +223,7 @@
         # delete relations referencing one of those eids
         eidcolum = SQL_PREFIX + 'eid'
         for rschema in self.schema.relations():
-            if rschema.is_final() or rschema.type == 'identity':
+            if rschema.is_final() or rschema.type in VIRTUAL_RTYPES:
                 continue
             if rschema.inlined:
                 column = SQL_PREFIX + rschema.type
@@ -253,8 +313,7 @@
         .executemany().
         """
         res = self.syntax_tree_search(session, union, args, varmap=varmap)
-        session.pool.source('system')._manual_insert(res, table, session)
-
+        session.pool.source('system').manual_insert(res, table, session)
 
     # system source don't have to implement the two methods below
 
@@ -266,7 +325,7 @@
         This method must return the an Entity instance representation of this
         entity.
         """
-        entity = self.repo.vreg.etype_class(etype)(session, None)
+        entity = self.repo.vreg['etypes'].etype_class(etype)(session)
         entity.set_eid(eid)
         return entity
 
--- a/server/sources/extlite.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sources/extlite.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,9 +11,10 @@
 from os.path import join, exists
 
 from cubicweb import server
-from cubicweb.server.sqlutils import SQL_PREFIX, sqlexec, SQLAdapterMixIn
-from cubicweb.server.sources import AbstractSource, native
-from cubicweb.server.sources.rql2sql import SQLGenerator
+from cubicweb.server.sqlutils import (SQL_PREFIX, SQLAdapterMixIn, sqlexec,
+                                      sql_source_backup, sql_source_restore)
+from cubicweb.server.sources import native, rql2sql
+from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results
 
 class ConnectionWrapper(object):
     def __init__(self, source=None):
@@ -29,18 +30,26 @@
     def cursor(self):
         if self._cnx is None:
             self._cnx = self.source._sqlcnx
+            if server.DEBUG & server.DBG_SQL:
+                print 'sql cnx OPEN', self._cnx
         return self._cnx.cursor()
 
     def commit(self):
         if self._cnx is not None:
+            if server.DEBUG & server.DBG_SQL:
+                print 'sql cnx COMMIT', self._cnx
             self._cnx.commit()
 
     def rollback(self):
         if self._cnx is not None:
+            if server.DEBUG & server.DBG_SQL:
+                print 'sql cnx ROLLBACK', self._cnx
             self._cnx.rollback()
 
     def close(self):
         if self._cnx is not None:
+            if server.DEBUG & server.DBG_SQL:
+                print 'sql cnx CLOSE', self._cnx
             self._cnx.close()
             self._cnx = None
 
@@ -48,7 +57,7 @@
 class SQLiteAbstractSource(AbstractSource):
     """an abstract class for external sources using a sqlite database helper
     """
-    sqlgen_class = SQLGenerator
+    sqlgen_class = rql2sql.SQLGenerator
     @classmethod
     def set_nonsystem_types(cls):
         # those entities are only in this source, we don't want them in the
@@ -85,6 +94,19 @@
         AbstractSource.__init__(self, repo, appschema, source_config,
                                 *args, **kwargs)
 
+    def backup(self, confirm, backupfile=None, timestamp=None, askconfirm=False):
+        """method called to create a backup of source's data"""
+        backupfile = self.backup_file(backupfile, timestamp)
+        sql_source_backup(self, self.sqladapter, confirm, backupfile,
+                          askconfirm)
+
+    def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+               askconfirm=False):
+        """method called to restore a backup of source's data"""
+        backupfile = self.backup_file(backupfile, timestamp)
+        sql_source_restore(self, self.sqladapter, confirm, backupfile, drop,
+                           askconfirm)
+
     @property
     def _sqlcnx(self):
         # XXX: sqlite connections can only be used in the same thread, so
@@ -155,14 +177,12 @@
         attached session: release the connection lock if the connection wrapper
         has a connection set
         """
-        if cnx._cnx is not None:
-            cnx._cnx.close()
-            # reset _cnx to ensure next thread using cnx will get a new
-            # connection
-            cnx._cnx = None
+        # reset _cnx to ensure next thread using cnx will get a new
+        # connection
+        cnx.close()
 
-    def syntax_tree_search(self, session, union,
-                           args=None, cachekey=None, varmap=None, debug=0):
+    def syntax_tree_search(self, session, union, args=None, cachekey=None,
+                           varmap=None):
         """return result from this source for a rql query (actually from a rql
         syntax tree and a solution dictionary mapping each used variable to a
         possible type). If cachekey is given, the query necessary to fetch the
@@ -170,14 +190,12 @@
         """
         if self._need_sql_create:
             return []
+        assert dbg_st_search(self.uri, union, varmap, args, cachekey)
         sql, query_args = self.rqlsqlgen.generate(union, args)
-        if server.DEBUG:
-            print self.uri, 'SOURCE RQL', union.as_string()
         args = self.sqladapter.merge_args(args, query_args)
-        res = self.sqladapter.process_result(self.doexec(session, sql, args))
-        if server.DEBUG:
-            print '------>', res
-        return res
+        results = self.sqladapter.process_result(self.doexec(session, sql, args))
+        assert dbg_results(results)
+        return results
 
     def local_add_entity(self, session, entity):
         """insert the entity in the local database.
--- a/server/sources/ldapuser.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sources/ldapuser.py	Fri Aug 07 12:20:50 2009 +0200
@@ -23,7 +23,7 @@
 
 from base64 import b64decode
 
-from logilab.common.textutils import get_csv
+from logilab.common.textutils import splitstrip
 from rql.nodes import Relation, VariableRef, Constant, Function
 
 import ldap
@@ -41,35 +41,61 @@
 ONELEVEL = ldap.SCOPE_ONELEVEL
 SUBTREE = ldap.SCOPE_SUBTREE
 
-# XXX only for edition ??
-## password encryption possibilities
-#ENCRYPTIONS = ('SHA', 'CRYPT', 'MD5', 'CLEAR') # , 'SSHA'
-
-# mode identifier : (port, protocol)
-MODES = {
-    0: (389, 'ldap'),
-    1: (636, 'ldaps'),
-    2: (0,   'ldapi'),
-    }
+# map ldap protocol to their standard port
+PROTO_PORT = {'ldap': 389,
+              'ldaps': 636,
+              'ldapi': None,
+              }
 
 
 class LDAPUserSource(AbstractSource):
     """LDAP read-only CWUser source"""
     support_entities = {'CWUser': False}
 
-    port = None
-
-    cnx_mode = 0
-    cnx_dn = ''
-    cnx_pwd = ''
-
     options = (
         ('host',
          {'type' : 'string',
           'default': 'ldap',
-          'help': 'ldap host',
+          'help': 'ldap host. It may contains port information using \
+<host>:<port> notation.',
+          'group': 'ldap-source', 'inputlevel': 1,
+          }),
+        ('protocol',
+         {'type' : 'choice',
+          'default': 'ldap',
+          'choices': ('ldap', 'ldaps', 'ldapi'),
+          'help': 'ldap protocol',
+          'group': 'ldap-source', 'inputlevel': 1,
+          }),
+
+        ('auth-mode',
+         {'type' : 'choice',
+          'default': 'simple',
+          'choices': ('simple', 'cram_md5', 'digest_md5', 'gssapi'),
+          'help': 'authentication mode used to authenticate user to the ldap.',
           'group': 'ldap-source', 'inputlevel': 1,
           }),
+        ('auth-realm',
+         {'type' : 'string',
+          'default': None,
+          'help': 'realm to use when using gssapp/kerberos authentication.',
+          'group': 'ldap-source', 'inputlevel': 1,
+          }),
+
+        ('data-cnx-dn',
+         {'type' : 'string',
+          'default': '',
+          'help': 'user dn to use to open data connection to the ldap (eg used \
+to respond to rql queries).',
+          'group': 'ldap-source', 'inputlevel': 1,
+          }),
+        ('data-cnx-password',
+         {'type' : 'string',
+          'default': '',
+          'help': 'password to use to open data connection to the ldap (eg used to respond to rql queries).',
+          'group': 'ldap-source', 'inputlevel': 1,
+          }),
+
         ('user-base-dn',
          {'type' : 'string',
           'default': 'ou=People,dc=logilab,dc=fr',
@@ -129,12 +155,18 @@
         AbstractSource.__init__(self, repo, appschema, source_config,
                                 *args, **kwargs)
         self.host = source_config['host']
+        self.protocol = source_config.get('protocol', 'ldap')
+        self.authmode = source_config.get('auth-mode', 'simple')
+        self._authenticate = getattr(self, '_auth_%s' % self.authmode)
+        self.cnx_dn = source_config.get('data-cnx-dn') or ''
+        self.cnx_pwd = source_config.get('data-cnx-password') or ''
+        self.user_base_scope = globals()[source_config['user-scope']]
         self.user_base_dn = source_config['user-base-dn']
         self.user_base_scope = globals()[source_config['user-scope']]
-        self.user_classes = get_csv(source_config['user-classes'])
+        self.user_classes = splitstrip(source_config['user-classes'])
         self.user_login_attr = source_config['user-login-attr']
-        self.user_default_groups = get_csv(source_config['user-default-group'])
-        self.user_attrs = dict(v.split(':', 1) for v in get_csv(source_config['user-attrs-map']))
+        self.user_default_groups = splitstrip(source_config['user-default-group'])
+        self.user_attrs = dict(v.split(':', 1) for v in splitstrip(source_config['user-attrs-map']))
         self.user_rev_attrs = {'eid': 'dn'}
         for ldapattr, cwattr in self.user_attrs.items():
             self.user_rev_attrs[cwattr] = ldapattr
@@ -225,8 +257,9 @@
             raise AuthenticationError()
         # check password by establishing a (unused) connection
         try:
-            self._connect(user['dn'], password)
-        except:
+            self._connect(user, password)
+        except Exception, ex:
+            self.info('while trying to authenticate %s: %s', user, ex)
             # Something went wrong, most likely bad credentials
             raise AuthenticationError()
         return self.extid2eid(user['dn'], 'CWUser', session)
@@ -368,15 +401,16 @@
         return result
 
 
-    def _connect(self, userdn=None, userpwd=None):
-        port, protocol = MODES[self.cnx_mode]
-        if protocol == 'ldapi':
+    def _connect(self, user=None, userpwd=None):
+        if self.protocol == 'ldapi':
             hostport = self.host
+        elif not ':' in self.host:
+            hostport = '%s:%s' % (self.host, PROTO_PORT[self.protocol])
         else:
-            hostport = '%s:%s' % (self.host, self.port or port)
-        self.info('connecting %s://%s as %s', protocol, hostport,
-                  userdn or 'anonymous')
-        url = LDAPUrl(urlscheme=protocol, hostport=hostport)
+            hostport = self.host
+        self.info('connecting %s://%s as %s', self.protocol, hostport,
+                  user and user['dn'] or 'anonymous')
+        url = LDAPUrl(urlscheme=self.protocol, hostport=hostport)
         conn = ReconnectLDAPObject(url.initializeUrl())
         # Set the protocol version - version 3 is preferred
         try:
@@ -391,14 +425,42 @@
         #conn.set_option(ldap.OPT_NETWORK_TIMEOUT, conn_timeout)
         #conn.timeout = op_timeout
         # Now bind with the credentials given. Let exceptions propagate out.
-        if userdn is None:
+        if user is None:
+            # no user specified, we want to initialize the 'data' connection,
             assert self._conn is None
             self._conn = conn
-            userdn = self.cnx_dn
-            userpwd = self.cnx_pwd
-        conn.simple_bind_s(userdn, userpwd)
+            # XXX always use simple bind for data connection
+            if not self.cnx_dn:
+                conn.simple_bind_s(self.cnx_dn, self.cnx_pwd)
+            else:
+                self._authenticate(conn, {'dn': self.cnx_dn}, self.cnx_pwd)
+        else:
+            # user specified, we want to check user/password, no need to return
+            # the connection which will be thrown out
+            self._authenticate(conn, user, userpwd)
         return conn
 
+    def _auth_simple(self, conn, user, userpwd):
+        conn.simple_bind_s(user['dn'], userpwd)
+
+    def _auth_cram_md5(self, conn, user, userpwd):
+        from ldap import sasl
+        auth_token = sasl.cram_md5(user['dn'], userpwd)
+        conn.sasl_interactive_bind_s('', auth_tokens)
+
+    def _auth_digest_md5(self, conn, user, userpwd):
+        from ldap import sasl
+        auth_token = sasl.digest_md5(user['dn'], userpwd)
+        conn.sasl_interactive_bind_s('', auth_tokens)
+
+    def _auth_gssapi(self, conn, user, userpwd):
+        # print XXX not proper sasl/gssapi
+        import kerberos
+        if not kerberos.checkPassword(user[self.user_login_attr], userpwd):
+            raise Exception('BAD login / mdp')
+        #from ldap import sasl
+        #conn.sasl_interactive_bind_s('', sasl.gssapi())
+
     def _search(self, session, base, scope,
                 searchstr='(objectClass=*)', attrs=()):
         """make an ldap query"""
--- a/server/sources/native.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sources/native.py	Fri Aug 07 12:20:50 2009 +0200
@@ -25,9 +25,10 @@
 
 from cubicweb import UnknownEid, AuthenticationError, Binary, server
 from cubicweb.server.utils import crypt_password
-from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn
+from cubicweb.server.sqlutils import (SQL_PREFIX, SQLAdapterMixIn,
+                                      sql_source_backup, sql_source_restore)
 from cubicweb.server.rqlannotation import set_qdata
-from cubicweb.server.sources import AbstractSource
+from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results
 from cubicweb.server.sources.rql2sql import SQLGenerator
 
 
@@ -43,7 +44,7 @@
         """Execute a query.
         it's a function just so that it shows up in profiling
         """
-        if server.DEBUG:
+        if server.DEBUG & server.DBG_SQL:
             print 'exec', query, args
         try:
             self.cu.execute(str(query), args)
@@ -58,6 +59,7 @@
     def fetchone(self):
         return self.cu.fetchone()
 
+
 def make_schema(selected, solution, table, typemap):
     """return a sql schema to store RQL query result"""
     sql = []
@@ -74,6 +76,7 @@
             sql.append('%s %s' % (name, typemap['Int']))
     return ','.join(sql), varmap
 
+
 def _modified_sql(table, etypes):
     # XXX protect against sql injection
     if len(etypes) > 1:
@@ -170,9 +173,7 @@
             self.get_connection = lambda: ConnectionWrapper(self)
             self.check_connection = lambda cnx: cnx
             def pool_reset(cnx):
-                if cnx._cnx is not None:
-                    cnx._cnx.close()
-                    cnx._cnx = None
+                cnx.close()
             self.pool_reset = pool_reset
 
     @property
@@ -188,8 +189,9 @@
 
     def clear_eid_cache(self, eid, etype):
         """clear potential caches for the given eid"""
-        self._cache.pop('%s X WHERE X eid %s' % (etype, eid), None)
+        self._cache.pop('Any X WHERE X eid %s, X is %s' % (eid, etype), None)
         self._cache.pop('Any X WHERE X eid %s' % eid, None)
+        self._cache.pop('Any %s' % eid, None)
 
     def sqlexec(self, session, sql, args=None):
         """execute the query and return its result"""
@@ -205,6 +207,18 @@
         pool.pool_reset()
         self.repo._free_pool(pool)
 
+    def backup(self, confirm, backupfile=None, timestamp=None,
+               askconfirm=False):
+        """method called to create a backup of source's data"""
+        backupfile = self.backup_file(backupfile, timestamp)
+        sql_source_backup(self, self, confirm, backupfile, askconfirm)
+
+    def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+               askconfirm=False):
+        """method called to restore a backup of source's data"""
+        backupfile = self.backup_file(backupfile, timestamp)
+        sql_source_restore(self, self, confirm, backupfile, drop, askconfirm)
+
     def init(self):
         self.init_creating()
         pool = self.repo._get_pool()
@@ -219,7 +233,7 @@
 
     def map_attribute(self, etype, attr, cb):
         self._rql_sqlgen.attr_map['%s.%s' % (etype, attr)] = cb
-        
+
     # ISource interface #######################################################
 
     def compile_rql(self, rql):
@@ -231,7 +245,7 @@
         return rqlst
 
     def set_schema(self, schema):
-        """set the application'schema"""
+        """set the instance'schema"""
         self._cache = Cache(self.repo.config['rql-cache-size'])
         self.cache_hit, self.cache_miss, self.no_cache = 0, 0, 0
         self.schema = schema
@@ -292,13 +306,7 @@
         necessary to fetch the results (but not the results themselves)
         may be cached using this key.
         """
-        if server.DEBUG:
-            print 'RQL FOR NATIVE SOURCE', self.uri, cachekey
-            if varmap:
-                print 'USING VARMAP', varmap
-            print union.as_string()
-            if args: print 'ARGS', args
-            print 'SOLUTIONS', ','.join(str(s.solutions) for s in union.children)
+        assert dbg_st_search(self.uri, union, varmap, args, cachekey)
         # remember number of actually selected term (sql generation may append some)
         if cachekey is None:
             self.no_cache += 1
@@ -323,10 +331,9 @@
             self.info("request failed '%s' ... retry with a new cursor", sql)
             session.pool.reconnect(self)
             cursor = self.doexec(session, sql, args)
-        res = self.process_result(cursor)
-        if server.DEBUG:
-            print '------>', res
-        return res
+        results = self.process_result(cursor)
+        assert dbg_results(results)
+        return results
 
     def flying_insert(self, table, session, union, args=None, varmap=None):
         """similar as .syntax_tree_search, but inserts data in the
@@ -334,23 +341,18 @@
         source whose the given cursor come from). If not possible,
         inserts all data by calling .executemany().
         """
-        if self.uri == 'system':
-            if server.DEBUG:
-                print 'FLYING RQL FOR SOURCE', self.uri
-                if varmap:
-                    print 'USING VARMAP', varmap
-                print union.as_string()
-                print 'SOLUTIONS', ','.join(str(s.solutions) for s in union.children)
-            # generate sql queries if we are able to do so
-            sql, query_args = self._rql_sqlgen.generate(union, args, varmap)
-            query = 'INSERT INTO %s %s' % (table, sql.encode(self.encoding))
-            self.doexec(session, query, self.merge_args(args, query_args))
-        else:
-            super(NativeSQLSource, self).flying_insert(table, session, union,
-                                                       args, varmap)
+        assert dbg_st_search(
+            self.uri, union, varmap, args,
+            prefix='ON THE FLY temp data insertion into %s from' % table)
+        # generate sql queries if we are able to do so
+        sql, query_args = self._rql_sqlgen.generate(union, args, varmap)
+        query = 'INSERT INTO %s %s' % (table, sql.encode(self.encoding))
+        self.doexec(session, query, self.merge_args(args, query_args))
 
-    def _manual_insert(self, results, table, session):
+    def manual_insert(self, results, table, session):
         """insert given result into a temporary table on the system source"""
+        if server.DEBUG & server.DBG_RQL:
+            print '  manual insertion of', res, 'into', table
         if not results:
             return
         query_args = ['%%(%s)s' % i for i in xrange(len(results[0]))]
@@ -417,24 +419,28 @@
             sql = self.sqlgen.delete('%s_relation' % rtype, attrs)
         self.doexec(session, sql, attrs)
 
-    def doexec(self, session, query, args=None):
+    def doexec(self, session, query, args=None, rollback=True):
         """Execute a query.
         it's a function just so that it shows up in profiling
         """
-        if server.DEBUG:
-            print 'exec', query, args
         cursor = session.pool[self.uri]
+        if server.DEBUG & server.DBG_SQL:
+            cnx = session.pool.connection(self.uri)
+            # getattr to get the actual connection if cnx is a ConnectionWrapper
+            # instance
+            print 'exec', query, args, getattr(cnx, '_cnx', cnx)
         try:
             # str(query) to avoid error if it's an unicode string
             cursor.execute(str(query), args)
         except Exception, ex:
             self.critical("sql: %r\n args: %s\ndbms message: %r",
                           query, args, ex.args[0])
-            try:
-                session.pool.connection(self.uri).rollback()
-                self.critical('transaction has been rollbacked')
-            except:
-                pass
+            if rollback:
+                try:
+                    session.pool.connection(self.uri).rollback()
+                    self.critical('transaction has been rollbacked')
+                except:
+                    pass
             raise
         return cursor
 
@@ -442,7 +448,7 @@
         """Execute a query.
         it's a function just so that it shows up in profiling
         """
-        if server.DEBUG:
+        if server.DEBUG & server.DBG_SQL:
             print 'execmany', query, 'with', len(args), 'arguments'
         cursor = session.pool[self.uri]
         try:
--- a/server/sources/pyrorql.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sources/pyrorql.py	Fri Aug 07 12:20:50 2009 +0200
@@ -23,7 +23,8 @@
 from cubicweb import dbapi, server
 from cubicweb import BadConnectionId, UnknownEid, ConnectionError
 from cubicweb.cwconfig import register_persistent_options
-from cubicweb.server.sources import AbstractSource, ConnectionWrapper, TimedCache
+from cubicweb.server.sources import (AbstractSource, ConnectionWrapper,
+                                     TimedCache, dbg_st_search, dbg_results)
 
 class ReplaceByInOperator(Exception):
     def __init__(self, eids):
@@ -78,14 +79,7 @@
          {'type' : 'string',
           'default': None,
           'help': 'Pyro name server\'s host. If not set, default to the value \
-from all_in_one.conf.',
-          'group': 'pyro-source', 'inputlevel': 1,
-          }),
-        ('pyro-ns-port',
-         {'type' : 'int',
-          'default': None,
-          'help': 'Pyro name server\'s listening port. If not set, default to \
-the value from all_in_one.conf.',
+from all_in_one.conf. It may contains port information using <host>:<port> notation.',
           'group': 'pyro-source', 'inputlevel': 1,
           }),
         ('pyro-ns-group',
@@ -213,13 +207,12 @@
     def _get_connection(self):
         """open and return a connection to the source"""
         nshost = self.config.get('pyro-ns-host') or self.repo.config['pyro-ns-host']
-        nsport = self.config.get('pyro-ns-port') or self.repo.config['pyro-ns-port']
         nsgroup = self.config.get('pyro-ns-group') or self.repo.config['pyro-ns-group']
         #cnxprops = ConnectionProperties(cnxtype=self.config['cnx-type'])
         return dbapi.connect(database=self.config['pyro-ns-id'],
                              login=self.config['cubicweb-user'],
                              password=self.config['cubicweb-password'],
-                             host=nshost, port=nsport, group=nsgroup,
+                             host=nshost, group=nsgroup,
                              setvreg=False) #cnxprops=cnxprops)
 
     def get_connection(self):
@@ -253,13 +246,14 @@
 
     def syntax_tree_search(self, session, union, args=None, cachekey=None,
                            varmap=None):
-        #assert not varmap, (varmap, union)
+        assert dbg_st_search(self.uri, union, varmap, args, cachekey)
         rqlkey = union.as_string(kwargs=args)
         try:
             results = self._query_cache[rqlkey]
         except KeyError:
             results = self._syntax_tree_search(session, union, args)
             self._query_cache[rqlkey] = results
+        assert dbg_results(results)
         return results
 
     def _syntax_tree_search(self, session, union, args):
@@ -270,11 +264,6 @@
         """
         if not args is None:
             args = args.copy()
-        if server.DEBUG:
-            print 'RQL FOR PYRO SOURCE', self.uri
-            print union.as_string()
-            if args: print 'ARGS', args
-            print 'SOLUTIONS', ','.join(str(s.solutions) for s in union.children)
         # get cached cursor anyway
         cu = session.pool[self.uri]
         if cu is None:
@@ -286,10 +275,10 @@
             rql, cachekey = RQL2RQL(self).generate(session, union, args)
         except UnknownEid, ex:
             if server.DEBUG:
-                print 'unknown eid', ex, 'no results'
+                print '  unknown eid', ex, 'no results'
             return []
-        if server.DEBUG:
-            print 'TRANSLATED RQL', rql
+        if server.DEBUG & server.DBG_RQL:
+            print '  translated rql', rql
         try:
             rset = cu.execute(rql, args, cachekey)
         except Exception, ex:
@@ -325,11 +314,6 @@
             results = rows
         else:
             results = []
-        if server.DEBUG:
-            if len(results)>10:
-                print '--------------->', results[:10], '...', len(results)
-            else:
-                print '--------------->', results
         return results
 
     def _entity_relations_and_kwargs(self, session, entity):
--- a/server/sqlutils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/sqlutils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,6 +7,8 @@
 """
 __docformat__ = "restructuredtext en"
 
+import os
+from os.path import exists
 from warnings import warn
 from datetime import datetime, date, timedelta
 
@@ -21,6 +23,8 @@
 from cubicweb import Binary, ConfigurationError
 from cubicweb.utils import todate, todatetime
 from cubicweb.common.uilib import remove_html_tags
+from cubicweb.toolsutils import restrict_perms_to_user
+from cubicweb.schema import PURE_VIRTUAL_RTYPES
 from cubicweb.server import SQL_CONNECT_HOOKS
 from cubicweb.server.utils import crypt_password
 
@@ -74,7 +78,7 @@
 
 def sqlschema(schema, driver, text_index=True,
               user=None, set_owner=False,
-              skip_relations=('has_text', 'identity'), skip_entities=()):
+              skip_relations=PURE_VIRTUAL_RTYPES, skip_entities=()):
     """return the system sql schema, according to the given parameters"""
     from yams.schema2sql import schema2sql
     from cubicweb.server.sources import native
@@ -99,7 +103,7 @@
 
 
 def sqldropschema(schema, driver, text_index=True,
-                  skip_relations=('has_text', 'identity'), skip_entities=()):
+                  skip_relations=PURE_VIRTUAL_RTYPES, skip_entities=()):
     """return the sql to drop the schema, according to the given parameters"""
     from yams.schema2sql import dropschema2sql
     from cubicweb.server.sources import native
@@ -116,6 +120,39 @@
                      skip_relations=skip_relations))
     return '\n'.join(output)
 
+
+def sql_source_backup(source, sqladapter, confirm, backupfile,
+                      askconfirm=False):
+    if exists(backupfile):
+        if not confirm('Backup file %s exists, overwrite it?' % backupfile):
+            return
+    elif askconfirm and not confirm('Backup %s database?'
+                                    % source.repo.config.appid):
+        print '-> no backup done.'
+        return
+    # should close opened connection before backuping
+    source.close_pool_connections()
+    try:
+        sqladapter.backup_to_file(backupfile, confirm)
+    finally:
+        source.open_pool_connections()
+
+def sql_source_restore(source, sqladapter, confirm, backupfile, drop=True,
+                       askconfirm=False):
+    if not exists(backupfile):
+        raise Exception("backup file %s doesn't exist" % backupfile)
+    app = source.repo.config.appid
+    if askconfirm and not confirm('Restore %s %s database from %s ?'
+                                  % (app, source.uri, backupfile)):
+        return
+    # should close opened connection before restoring
+    source.close_pool_connections()
+    try:
+        sqladapter.restore_from_file(backupfile, confirm, drop=drop)
+    finally:
+        source.open_pool_connections()
+
+
 try:
     from mx.DateTime import DateTimeType, DateTimeDeltaType
 except ImportError:
@@ -159,6 +196,46 @@
         #self.dbapi_module.type_code_test(cnx.cursor())
         return cnx
 
+    def backup_to_file(self, backupfile, confirm):
+        cmd = self.dbhelper.backup_command(self.dbname, self.dbhost,
+                                           self.dbuser, backupfile,
+                                           keepownership=False)
+        backupdir = os.path.dirname(backupfile)
+        if not os.path.exists(backupdir):
+            if confirm('%s does not exist. Create it?' % backupdir,
+                       abort=False, shell=False):
+                os.mkdir(backupdir)
+            else:
+                print '-> failed to backup instance'
+                return
+        if os.system(cmd):
+            print '-> error trying to backup with command', cmd
+            if not confirm('Continue anyway?', default_is_yes=False):
+                raise SystemExit(1)
+        else:
+            print '-> backup file',  backupfile
+            restrict_perms_to_user(backupfile, self.info)
+
+    def restore_from_file(self, backupfile, confirm, drop=True):
+        for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost,
+                                                  self.dbuser, backupfile,
+                                                  self.encoding,
+                                                  keepownership=False,
+                                                  drop=drop):
+            while True:
+                print cmd
+                if os.system(cmd):
+                    print '-> error while restoring the base'
+                    answer = confirm('Continue anyway?',
+                                     shell=False, abort=False, retry=True)
+                    if not answer:
+                        raise SystemExit(1)
+                    if answer == 1: # 1: continue, 2: retry
+                        break
+                else:
+                    break
+        print '-> database restored.'
+
     def merge_args(self, args, query_args):
         if args is not None:
             args = dict(args)
--- a/server/ssplanner.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/ssplanner.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,6 +13,7 @@
 from rql.nodes import Constant
 
 from cubicweb import QueryError, typed_eid
+from cubicweb.schema import VIRTUAL_RTYPES
 
 def add_types_restriction(schema, rqlst, newroot=None, solutions=None):
     if newroot is None:
@@ -113,9 +114,10 @@
         # each variable in main variables is a new entity to insert
         to_build = {}
         session = plan.session
+        etype_class = session.vreg['etypes'].etype_class
         for etype, var in rqlst.main_variables:
             # need to do this since entity class is shared w. web client code !
-            to_build[var.name] = session.etype_class(etype)(session, None, None)
+            to_build[var.name] = etype_class(etype)(session)
             plan.add_entity_def(to_build[var.name])
         # add constant values to entity def, mark variables to be selected
         to_select = plan.relation_definitions(rqlst, to_build)
@@ -196,7 +198,7 @@
         relations, attrrelations = [], []
         getrschema = self.schema.rschema
         for relation in rqlst.main_relations:
-            if relation.r_type in ('eid', 'has_text', 'identity'):
+            if relation.r_type in VIRTUAL_RTYPES:
                 raise QueryError('can not assign to %r relation'
                                  % relation.r_type)
             lhs, rhs = relation.get_variable_parts()
@@ -480,6 +482,7 @@
         repo = session.repo
         edefs = {}
         # insert relations
+        attributes = [relation.r_type for relation in self.attribute_relations]
         for row in self.execute_child():
             for relation in self.attribute_relations:
                 lhs, rhs = relation.get_variable_parts()
@@ -487,7 +490,7 @@
                 try:
                     edef = edefs[eid]
                 except KeyError:
-                    edefs[eid] = edef = session.eid_rset(eid).get_entity(0, 0)
+                    edefs[eid] = edef = session.entity_from_eid(eid)
                 if isinstance(rhs, Constant):
                     # add constant values to entity def
                     value = rhs.eval(plan.args)
@@ -501,6 +504,6 @@
         # update entities
         result = []
         for eid, edef in edefs.iteritems():
-            repo.glob_update_entity(session, edef)
+            repo.glob_update_entity(session, edef, attributes)
             result.append( (eid,) )
         return result
--- a/server/test/data/config1/application_hooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-"""hooks for config1
-
- Copyright (c) 2003-2007 LOGILAB S.A. (Paris, FRANCE).
- http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-HOOKS = {"after_add_relation" : {"concerned_by" : [lambda: None]}}
--- a/server/test/data/config1/bootstrap_packages	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-# file generated by cubicweb-ctl
--- a/server/test/data/config1/server-ctl.conf	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-# file generated by cubicweb-ctl
-
-APPLICATION HOME=/home/adim/etc/cubicweb.d/crmadim
-DEBUG=
-HOST=
-LOG TRESHOLD=LOG_DEBUG
-NS GROUP=cubicweb
-NS HOST=
-PID FILE=/home/adim/tmp/crmadim.pid
-PORT=
-QUERY LOG FILE=
-UID=1006
-PROFILE=
--- a/server/test/data/config1/sources	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# file generated by cubicweb-ctl
-
-[system]
-ADAPTER=native
-DBHOST=crater
-DBDRIVER=postgres
-DBNAME=whatever
-ENCODING=UTF-8
-SPLIT_RELATIONS = True
-
--- a/server/test/data/config2/application_hooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-"""hooks for config2
-
- Copyright (c) 2003-2007 LOGILAB S.A. (Paris, FRANCE).
- http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-HOOKS = {"after_delete_relation" : {"todo_by" : [lambda: 1]}}
--- a/server/test/data/config2/bootstrap_packages	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-# file generated by cubicweb-ctl
--- a/server/test/data/config2/server-ctl.conf	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-# file generated by cubicweb-ctl
-
-APPLICATION HOME=/home/adim/etc/cubicweb.d/crmadim
-DEBUG=
-HOST=
-LOG TRESHOLD=LOG_DEBUG
-NS GROUP=cubicweb
-NS HOST=
-PID FILE=/home/adim/tmp/crmadim.pid
-PORT=
-QUERY LOG FILE=
-UID=1006
-PROFILE=
--- a/server/test/data/config2/sources	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# file generated by cubicweb-ctl
-
-[system]
-ADAPTER=native
-DBHOST=crater
-DBDRIVER=postgres
-DBNAME=whatever
-ENCODING=UTF-8
-SPLIT_RELATIONS = True
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/test/data/migratedapp/bootstrap_cubes	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,1 @@
+card,comment,folder,tag,basket,email,file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/test/data/migratedapp/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,119 @@
+"""
+
+:organization: Logilab
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+                            SubjectRelation, ObjectRelation,
+                            RichString, String, Int, Boolean, Datetime, Date)
+from yams.constraints import SizeConstraint, UniqueConstraint
+from cubicweb.schema import (WorkflowableEntityType, RQLConstraint,
+                             ERQLExpression, RRQLExpression)
+
+class Affaire(EntityType):
+    permissions = {
+        'read':   ('managers', 'users', 'guests'),
+        'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
+        'update': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
+        'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
+        }
+
+    ref = String(fulltextindexed=True, indexed=True,
+                 constraints=[SizeConstraint(16)])
+    sujet = String(fulltextindexed=True,
+                 constraints=[SizeConstraint(256)])
+    concerne = SubjectRelation('Societe')
+
+class concerne(RelationType):
+    permissions = {
+        'read':   ('managers', 'users', 'guests'),
+        'add':    ('managers', RRQLExpression('U has_update_permission S')),
+        'delete': ('managers', RRQLExpression('O owned_by U')),
+        }
+
+class Note(EntityType):
+    permissions = {'read':   ('managers', 'users', 'guests',),
+                   'update': ('managers', 'owners',),
+                   'delete': ('managers', ),
+                   'add':    ('managers',
+                              ERQLExpression('X ecrit_part PE, U in_group G, '
+                                             'PE require_permission P, P name "add_note", '
+                                             'P require_group G'),)}
+
+    date = Datetime()
+    type = String(maxsize=1)
+    whatever = Int()
+    mydate = Date(default='TODAY')
+    para = String(maxsize=512)
+    shortpara = String(maxsize=64)
+    ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')])
+    attachment = SubjectRelation(('File', 'Image'))
+
+class ecrit_par(RelationType):
+    permissions = {'read':   ('managers', 'users', 'guests',),
+                   'delete': ('managers', ),
+                   'add':    ('managers',
+                              RRQLExpression('O require_permission P, P name "add_note", '
+                                             'U in_group G, P require_group G'),)
+                   }
+    inlined = True
+    cardinality = '?*'
+
+
+class Folder2(EntityType):
+    """folders are used to classify entities. They may be defined as a tree.
+    When you include the Folder entity, all application specific entities
+    may then be classified using the "filed_under" relation.
+    """
+    name = String(required=True, indexed=True, internationalizable=True,
+                  constraints=[UniqueConstraint(), SizeConstraint(64)])
+    description = RichString(fulltextindexed=True)
+
+    filed_under2 = ObjectRelation('*')
+
+
+class Personne(EntityType):
+    nom    = String(fulltextindexed=True, required=True, maxsize=64)
+    prenom = String(fulltextindexed=True, maxsize=64)
+    civility   = String(maxsize=1, default='M')
+    promo  = String(vocabulary=('bon','pasbon'))
+    titre  = String(fulltextindexed=True, maxsize=128)
+    adel   = String(maxsize=128)
+    ass    = String(maxsize=128)
+    web    = String(maxsize=128)
+    tel    = Int()
+    fax    = Int()
+    datenaiss = Datetime()
+    test   = Boolean()
+
+    travaille = SubjectRelation('Societe')
+    concerne = SubjectRelation('Affaire')
+    concerne2 = SubjectRelation('Affaire')
+    connait = SubjectRelation('Personne', symetric=True)
+
+class Societe(EntityType):
+    permissions = {
+        'read': ('managers', 'users', 'guests'),
+        'update': ('managers', 'owners'),
+        'delete': ('managers', 'owners'),
+        'add': ('managers', 'users',)
+        }
+
+    nom  = String(maxsize=64, fulltextindexed=True)
+    web  = String(maxsize=128)
+    tel  = Int()
+    fax  = Int()
+    rncs = String(maxsize=128)
+    ad1  = String(maxsize=128)
+    ad2  = String(maxsize=128)
+    ad3  = String(maxsize=128)
+    cp   = String(maxsize=12)
+    ville= String(maxsize=32)
+
+    in_state = SubjectRelation('State', cardinality='?*')
+
+class evaluee(RelationDefinition):
+    subject = ('Personne', 'CWUser', 'Societe')
+    object = ('Note')
--- a/server/test/data/migrschema/Affaire.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-class Affaire(EntityType):
-    permissions = {
-        'read':   ('managers', 'users', 'guests'),
-        'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
-        'update': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
-        'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
-        }
-
-    ref = String(fulltextindexed=True, indexed=True,
-                 constraints=[SizeConstraint(16)])
-    sujet = String(fulltextindexed=True,
-                 constraints=[SizeConstraint(256)])
-
-class concerne(RelationType):
-    permissions = {
-        'read':   ('managers', 'users', 'guests'),
-        'add':    ('managers', RRQLExpression('U has_update_permission S')),
-        'delete': ('managers', RRQLExpression('O owned_by U')),
-        }
-
--- a/server/test/data/migrschema/Folder2.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-from cubicweb.schema import format_constraint
-
-class Folder2(MetaUserEntityType):
-    """folders are used to classify entities. They may be defined as a tree.
-    When you include the Folder entity, all application specific entities
-    may then be classified using the "filed_under" relation.
-    """
-    name = String(required=True, indexed=True, internationalizable=True,
-                  constraints=[UniqueConstraint(), SizeConstraint(64)])
-    description_format = String(meta=True, internationalizable=True,
-                                default='text/rest', constraints=[format_constraint])
-    description = String(fulltextindexed=True)
-
-    filed_under2 = BothWayRelation(
-        SubjectRelation('Folder2', description=_("parent folder")),
-        ObjectRelation('*'),
-        )
-
-
-class filed_under2(MetaUserRelationType):
-    """indicates that an entity is classified under a folder"""
-    # is_about has been renamed into filed_under
-    #//* is_about Folder
-    #* filed_under Folder
-
--- a/server/test/data/migrschema/Note.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-class Note(EntityType):
-
-    permissions = {'read':   ('managers', 'users', 'guests',),
-                   'update': ('managers', 'owners',),
-                   'delete': ('managers', ),
-                   'add':    ('managers',
-                              ERQLExpression('X ecrit_part PE, U in_group G, '
-                                             'PE require_permission P, P name "add_note", '
-                                             'P require_group G'),)}
-
-    date = Datetime()
-    type = String(maxsize=1)
-    whatever = Int()
-    mydate = Date(default='TODAY')
-    para = String(maxsize=512)
-    shortpara = String(maxsize=64)
-    ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')])
-
-class ecrit_par(RelationType):
-    permissions = {'read':   ('managers', 'users', 'guests',),
-                   'delete': ('managers', ),
-                   'add':    ('managers',
-                              RRQLExpression('O require_permission P, P name "add_note", '
-                                             'U in_group G, P require_group G'),)
-                   }
-    inlined = True
--- a/server/test/data/migrschema/Personne.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-nom    ivarchar(64) NOT NULL
-prenom ivarchar(64)
-civility char(1) DEFAULT 'M' 
-promo  choice('bon','pasbon')
-titre  ivarchar(128)
-adel   varchar(128)
-ass    varchar(128)
-web    varchar(128)
-tel    integer
-fax    integer
-datenaiss datetime
-test   boolean 
--- a/server/test/data/migrschema/Societe.perms	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Read: managers, users, guests
--- a/server/test/data/migrschema/Societe.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-nom  ivarchar(64)
-web varchar(128)
-tel  integer
-fax  integer
-rncs varchar(32)
-ad1  varchar(128)
-ad2  varchar(128)
-ad3  varchar(128)
-cp   varchar(12)
-ville varchar(32)
--- a/server/test/data/migrschema/relations.rel	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-Personne travaille Societe
-Personne evaluee Note
-CWUser evaluee Note
-Societe evaluee Note
-Personne concerne Affaire
-Affaire concerne Societe
-Personne concerne2 Affaire
-
-Personne connait Personne symetric
-
-Societe in_state State inline
-
-Note attachment File
-Note attachment Image
-
--- a/server/test/data/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,7 +5,12 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-from cubicweb.schema import format_constraint
+from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+                            SubjectRelation, ObjectRelation,
+                            RichString, String, Int, Boolean, Datetime)
+from yams.constraints import SizeConstraint
+from cubicweb.schema import (WorkflowableEntityType, RQLConstraint,
+                             ERQLExpression, RRQLExpression)
 
 class Affaire(WorkflowableEntityType):
     permissions = {
@@ -20,10 +25,8 @@
                  constraints=[SizeConstraint(16)])
     sujet = String(fulltextindexed=True,
                    constraints=[SizeConstraint(256)])
-    descr_format = String(meta=True, internationalizable=True,
-                                default='text/rest', constraints=[format_constraint])
-    descr = String(fulltextindexed=True,
-                   description=_('more detailed description'))
+    descr = RichString(fulltextindexed=True,
+                       description=_('more detailed description'))
 
     duration = Int()
     invoiced = Int()
@@ -63,8 +66,8 @@
     __specializes_schema__ = True
     travaille_subdivision = ObjectRelation('Personne')
 
-_euser = import_schema('base').CWUser
-_euser.__relations__[0].fulltextindexed = True
+from cubicweb.schemas.base import CWUser
+CWUser.get_relations('login').next().fulltextindexed = True
 
 class Note(EntityType):
     date = String(maxsize=10)
@@ -73,7 +76,7 @@
 
     migrated_from = SubjectRelation('Note')
     attachment = SubjectRelation(('File', 'Image'))
-    inline1 = SubjectRelation('Affaire', inlined=True)
+    inline1 = SubjectRelation('Affaire', inlined=True, cardinality='?*')
     todo_by = SubjectRelation('CWUser')
 
 class Personne(EntityType):
@@ -95,7 +98,7 @@
     travaille = SubjectRelation('Societe')
     concerne = SubjectRelation('Affaire')
     connait = SubjectRelation('Personne')
-    inline2 = SubjectRelation('Affaire', inlined=True)
+    inline2 = SubjectRelation('Affaire', inlined=True, cardinality='?*')
     comments = ObjectRelation('Comment')
 
 
@@ -131,14 +134,14 @@
         'delete': ('managers', RRQLExpression('O owned_by U')),
         }
 
-class para(AttributeRelationType):
+class para(RelationType):
     permissions = {
         'read':   ('managers', 'users', 'guests'),
         'add':    ('managers', ERQLExpression('X in_state S, S name "todo"')),
         'delete': ('managers', ERQLExpression('X in_state S, S name "todo"')),
         }
 
-class test(AttributeRelationType):
+class test(RelationType):
     permissions = {'read': ('managers', 'users', 'guests'),
                    'delete': ('managers',),
                    'add': ('managers',)}
@@ -164,7 +167,12 @@
     object = 'Note'
 
 
-class see_also(RelationDefinition):
+class see_also_1(RelationDefinition):
+    name = 'see_also'
+    subject = object = 'Folder'
+
+class see_also_2(RelationDefinition):
+    name = 'see_also'
     subject = ('Bookmark', 'Note')
     object = ('Bookmark', 'Note')
 
@@ -177,14 +185,13 @@
     subject = 'Note'
     object ='Personne'
     constraints = [RQLConstraint('E concerns P, X version_of P')]
+    cardinality = '?*'
 
 class ecrit_par_2(RelationDefinition):
     name = 'ecrit_par'
     subject = 'Note'
     object ='CWUser'
-
-class see_also(RelationDefinition):
-    subject = object = 'Folder'
+    cardinality='?*'
 
 
 class copain(RelationDefinition):
@@ -199,7 +206,7 @@
     object = 'Folder'
 
 class require_permission(RelationDefinition):
-    subject = ('Card', 'Note')
+    subject = ('Card', 'Note', 'Personne')
     object = 'CWPermission'
 
 class require_state(RelationDefinition):
--- a/server/test/unittest_config.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-"""tests for server config
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-from os.path import join, dirname
-
-from logilab.common.testlib import TestCase, unittest_main
-
-from cubicweb.devtools import TestServerConfiguration
-
-class ConfigTC(TestCase):
-
-    def test_load_hooks_twice(self):
-        class vreg:
-            @staticmethod
-            def registry_objects(registry):
-                return []
-
-        cfg1 = TestServerConfiguration('data/config1')
-        cfg1.bootstrap_cubes()
-        cfg2 = TestServerConfiguration('data/config2')
-        cfg2.bootstrap_cubes()
-        self.failIf(cfg1.load_hooks(vreg) is cfg2.load_hooks(vreg))
-        self.failUnless('after_add_relation' in cfg1.load_hooks(vreg))
-        self.failUnless('after_delete_relation' in cfg2.load_hooks(vreg))
-
-
-if __name__ == '__main__':
-    unittest_main()
--- a/server/test/unittest_extlite.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_extlite.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,7 +17,7 @@
             os.remove(self.sqlite_file)
         except:
             pass
-        
+
     def test(self):
         lock = threading.Lock()
 
--- a/server/test/unittest_hookhelper.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_hookhelper.py	Fri Aug 07 12:20:50 2009 +0200
@@ -41,10 +41,10 @@
         from cubicweb.server import hooks, schemahooks
         session = self.session
         op1 = hooks.DelayedDeleteOp(session)
-        op2 = schemahooks.DelErdefOp(session)
+        op2 = schemahooks.MemSchemaRDefDel(session)
         # equivalent operation generated by op2 but replace it here by op3 so we
         # can check the result...
-        op3 = schemahooks.UpdateSchemaOp(session)
+        op3 = schemahooks.MemSchemaNotifyChanges(session)
         op4 = hooks.DelayedDeleteOp(session)
         op5 = hooks.CheckORelationOp(session)
         self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3])
--- a/server/test/unittest_hooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_hooks.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,9 +6,13 @@
 """
 
 from logilab.common.testlib import TestCase, unittest_main
+
+from datetime import datetime
+
+from cubicweb import (ConnectionError, RepositoryError, ValidationError,
+                      AuthenticationError, BadConnectionId)
 from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
 
-from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.repository import Repository
 
@@ -58,12 +62,12 @@
 
     def test_delete_if_singlecard1(self):
         self.assertEquals(self.repo.schema['in_state'].inlined, False)
-        ueid, = self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y, X in_state S '
-                             'WHERE Y name "users", S name "activated"')[0]
+        ueid = self.create_user('toto')
         self.commit()
         self.execute('SET X in_state S WHERE S name "deactivated", X eid %(x)s', {'x': ueid})
         rset = self.execute('Any S WHERE X in_state S, X eid %(x)s', {'x': ueid})
         self.assertEquals(len(rset), 1)
+        self.commit()
         self.assertRaises(Exception, self.execute, 'SET X in_state S WHERE S name "deactivated", X eid %s' % ueid)
         rset2 = self.execute('Any S WHERE X in_state S, X eid %(x)s', {'x': ueid})
         self.assertEquals(rset.rows, rset2.rows)
@@ -242,13 +246,12 @@
 
 
 class SchemaModificationHooksTC(RepositoryBasedTC):
-    #copy_schema = True
 
     def setUp(self):
         if not hasattr(self, '_repo'):
             # first initialization
             repo = self.repo # set by the RepositoryBasedTC metaclass
-            # force to read schema from the database
+            # force to read schema from the database to get proper eid set on schema instances
             repo.config._cubes = None
             repo.fill_schema()
         RepositoryBasedTC.setUp(self)
@@ -265,8 +268,8 @@
         self.failIf(schema.has_entity('Societe2'))
         self.failIf(schema.has_entity('concerne2'))
         # schema should be update on insertion (after commit)
-        self.execute('INSERT CWEType X: X name "Societe2", X description "", X meta FALSE, X final FALSE')
-        self.execute('INSERT CWRType X: X name "concerne2", X description "", X meta FALSE, X final FALSE, X symetric FALSE')
+        self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')
+        self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symetric FALSE')
         self.failIf(schema.has_entity('Societe2'))
         self.failIf(schema.has_entity('concerne2'))
         self.execute('SET X read_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup')
@@ -614,5 +617,39 @@
         self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'"))
         cnx.commit()
 
+    def test_metadata_cwuri(self):
+        eid = self.execute('INSERT Note X')[0][0]
+        cwuri = self.execute('Any U WHERE X eid %s, X cwuri U' % eid)[0][0]
+        self.assertEquals(cwuri, self.repo.config['base-url'] + 'eid/%s' % eid)
+
+    def test_metadata_creation_modification_date(self):
+        _now = datetime.now()
+        eid = self.execute('INSERT Note X')[0][0]
+        creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, '
+                                                        'X creation_date CD, '
+                                                        'X modification_date MD' % eid)[0]
+        self.assertEquals((creation_date - _now).seconds, 0)
+        self.assertEquals((modification_date - _now).seconds, 0)
+
+    def test_metadata__date(self):
+        _now = datetime.now()
+        eid = self.execute('INSERT Note X')[0][0]
+        creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0]
+        self.assertEquals((creation_date - _now).seconds, 0)
+
+    def test_metadata_created_by(self):
+        eid = self.execute('INSERT Note X')[0][0]
+        self.commit() # fire operations
+        rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid)
+        self.assertEquals(len(rset), 1) # make sure we have only one creator
+        self.assertEquals(rset[0][0], self.session.user.eid)
+
+    def test_metadata_owned_by(self):
+        eid = self.execute('INSERT Note X')[0][0]
+        self.commit() # fire operations
+        rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid)
+        self.assertEquals(len(rset), 1) # make sure we have only one owner
+        self.assertEquals(rset[0][0], self.session.user.eid)
+
 if __name__ == '__main__':
     unittest_main()
--- a/server/test/unittest_migractions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_migractions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -3,11 +3,12 @@
 """
 
 from datetime import date
+from os.path import join
 
 from logilab.common.testlib import TestCase, unittest_main
-from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
 
 from cubicweb import ConfigurationError
+from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
 from cubicweb.schema import CubicWebSchemaLoader
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.repository import Repository
@@ -23,7 +24,6 @@
 
 
 class MigrationCommandsTC(RepositoryBasedTC):
-    copy_schema = False
 
     def setUp(self):
         if not hasattr(self, '_repo'):
@@ -33,10 +33,10 @@
             repo.config._cubes = None
             repo.fill_schema()
             # hack to read the schema from data/migrschema
-            CubicWebSchemaLoader.main_schema_directory = 'migrschema'
+            self.repo.config.appid = join('data', 'migratedapp')
             global migrschema
             migrschema = self.repo.config.load_schema()
-            del CubicWebSchemaLoader.main_schema_directory
+            self.repo.config.appid = 'data'
             assert 'Folder' in migrschema
             self.repo.hm.deactivate_verification_hooks()
         RepositoryBasedTC.setUp(self)
@@ -78,6 +78,7 @@
 
     def test_add_datetime_with_default_value_attribute(self):
         self.failIf('mydate' in self.schema)
+        self.failIf('shortpara' in self.schema)
         self.mh.cmd_add_attribute('Note', 'mydate')
         self.failUnless('mydate' in self.schema)
         self.assertEquals(self.schema['mydate'].subjects(), ('Note', ))
@@ -133,14 +134,16 @@
         self.failUnless('filed_under2' in self.schema)
         self.failUnless(self.execute('CWRType X WHERE X name "filed_under2"'))
         self.assertEquals(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()),
-                          ['created_by', 'creation_date', 'description', 'description_format', 'eid',
-                           'filed_under2', 'has_text', 'identity', 'is', 'is_instance_of',
+                          ['created_by', 'creation_date', 'cwuri',
+                           'description', 'description_format',
+                           'eid',
+                           'filed_under2', 'has_text',
+                           'identity', 'in_basket', 'is', 'is_instance_of',
                            'modification_date', 'name', 'owned_by'])
         self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()],
                           ['filed_under2', 'identity'])
         self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
-                          ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File',
-                           'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision'])
+                          sorted(str(e) for e in self.schema.entities() if not e.is_final()))
         self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',))
         eschema = self.schema.eschema('Folder2')
         for cstr in eschema.constraints('name'):
@@ -166,8 +169,7 @@
         self.mh.cmd_add_relation_type('filed_under2')
         self.failUnless('filed_under2' in self.schema)
         self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
-                          ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File',
-                           'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision'])
+                          sorted(str(e) for e in self.schema.entities() if not e.is_final()))
         self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',))
         self.mh.cmd_drop_relation_type('filed_under2')
         self.failIf('filed_under2' in self.schema)
@@ -181,26 +183,38 @@
         self.failIf('concerne2' in self.schema)
 
     def test_drop_relation_definition_existant_rtype(self):
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_add_relation_definition('Personne', 'concerne', 'Affaire')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
         self.maxeid = self.execute('Any MAX(X)')[0][0]
 
     def test_drop_relation_definition_with_specialization(self):
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Note'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Note'])
         self.mh.cmd_add_relation_definition('Affaire', 'concerne', 'Societe')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
         self.maxeid = self.execute('Any MAX(X)')[0][0]
 
@@ -233,28 +247,15 @@
             self.mh.cmd_change_relation_props('Personne', 'adel', 'String',
                                               fulltextindexed=False)
 
-    def test_synchronize_schema(self):
+    def test_sync_schema_props_perms(self):
         cursor = self.mh.rqlcursor
         nbrqlexpr_start = len(cursor.execute('RQLExpression X'))
         migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7
         migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6
         migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5
-#         expected = ['eid', 'has_text', 'creation_date', 'modification_date',
-#                     'nom', 'prenom', 'civility', 'promo', 'ass', 'adel', 'titre',
-#                     'web', 'tel', 'fax', 'datenaiss', 'test']
-#         self.assertEquals([rs.type for rs in migrschema['Personne'].ordered_relations() if rs.is_final()],
-#                           expected)
         migrschema['Personne'].description = 'blabla bla'
         migrschema['titre'].description = 'usually a title'
         migrschema['titre']._rproperties[('Personne', 'String')]['description'] = 'title for this person'
-#         rinorderbefore = cursor.execute('Any O,N WHERE X is CWAttribute, X relation_type RT, RT name N,'
-#                                         'X from_entity FE, FE name "Personne",'
-#                                         'X ordernum O ORDERBY O')
-#         expected = [u'creation_date', u'modification_date', u'nom', u'prenom',
-#                     u'sexe', u'promo', u'titre', u'adel', u'ass', u'web', u'tel',
-#                     u'fax', u'datenaiss', u'test', u'description']
-#        self.assertListEquals(rinorderbefore, map(list, zip([0, 0]+range(1, len(expected)), expected)))
-
         self.mh.cmd_sync_schema_props_perms(commit=False)
 
         self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0],
@@ -265,16 +266,13 @@
                                          'X from_entity FE, FE name "Personne",'
                                          'X description D')[0][0],
                           'title for this person')
-        # skip "sexe" and "description" since they aren't in the migration
-        # schema and so behaviour is undefined
-        # "civility" is also skipped since it may have been added by
-        # test_rename_attribut :o/
-        rinorder = [n for n, in cursor.execute('Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,'
-                                               'X from_entity FE, FE name "Personne",'
-                                               'X ordernum O') if n not in ('sexe', 'description', 'civility')]
+        rinorder = [n for n, in cursor.execute(
+            'Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,'
+            'X from_entity FE, FE name "Personne",'
+            'X ordernum O')]
         expected = [u'nom', u'prenom', u'promo', u'ass', u'adel', u'titre',
-                    u'web', u'tel', u'fax', u'datenaiss', u'test', u'firstname',
-                    u'creation_date', u'modification_date']
+                    u'web', u'tel', u'fax', u'datenaiss', u'test', 'description', u'firstname',
+                    u'creation_date', 'cwuri', u'modification_date']
         self.assertEquals(rinorder, expected)
 
         # test permissions synchronization ####################################
@@ -357,7 +355,7 @@
     def test_add_remove_cube_and_deps(self):
         cubes = set(self.config.cubes())
         schema = self.repo.schema
-        self.assertEquals(sorted(schema['see_also']._rproperties.keys()),
+        self.assertEquals(sorted((str(s), str(o)) for s, o in schema['see_also']._rproperties.keys()),
                           sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'),
                                   ('Bookmark', 'Bookmark'), ('Bookmark', 'Note'),
                                   ('Note', 'Note'), ('Note', 'Bookmark')]))
--- a/server/test/unittest_msplanner.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_msplanner.py	Fri Aug 07 12:20:50 2009 +0200
@@ -50,6 +50,7 @@
                      {'X': 'CWRelation'}, {'X': 'CWPermission'}, {'X': 'CWProperty'},
                      {'X': 'CWRType'}, {'X': 'CWUser'}, {'X': 'Email'},
                      {'X': 'EmailAddress'}, {'X': 'EmailPart'}, {'X': 'EmailThread'},
+                     {'X': 'ExternalUri'},
                      {'X': 'File'}, {'X': 'Folder'}, {'X': 'Image'},
                      {'X': 'Note'}, {'X': 'Personne'}, {'X': 'RQLExpression'},
                      {'X': 'Societe'}, {'X': 'State'}, {'X': 'SubDivision'},
@@ -873,13 +874,13 @@
                                           [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
                            [self.cards, self.system], {}, {'X': 'table0.C0'}, []),
                           ('FetchStep',
-                           [('Any X WHERE X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
+                           [('Any X WHERE X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
                              sorted([{'X': 'Bookmark'}, {'X': 'Comment'}, {'X': 'Division'},
                                       {'X': 'CWCache'}, {'X': 'CWConstraint'}, {'X': 'CWConstraintType'},
                                       {'X': 'CWEType'}, {'X': 'CWAttribute'}, {'X': 'CWGroup'},
                                       {'X': 'CWRelation'}, {'X': 'CWPermission'}, {'X': 'CWProperty'},
                                       {'X': 'CWRType'}, {'X': 'Email'}, {'X': 'EmailAddress'},
-                                      {'X': 'EmailPart'}, {'X': 'EmailThread'}, {'X': 'File'},
+                                      {'X': 'EmailPart'}, {'X': 'EmailThread'}, {'X': 'ExternalUri'}, {'X': 'File'},
                                       {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Personne'},
                                       {'X': 'RQLExpression'}, {'X': 'Societe'}, {'X': 'SubDivision'},
                                       {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'}]))],
@@ -922,7 +923,7 @@
                        [self.system], {'X': 'table3.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
                       # extra UnionFetchStep could be avoided but has no cost, so don't care
                       ('UnionFetchStep',
-                       [('FetchStep', [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
+                       [('FetchStep', [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
                                         [{'X': 'Bookmark', 'ET': 'CWEType'}, {'X': 'Comment', 'ET': 'CWEType'},
                                          {'X': 'Division', 'ET': 'CWEType'}, {'X': 'CWCache', 'ET': 'CWEType'},
                                          {'X': 'CWConstraint', 'ET': 'CWEType'}, {'X': 'CWConstraintType', 'ET': 'CWEType'},
@@ -931,7 +932,9 @@
                                          {'X': 'CWPermission', 'ET': 'CWEType'}, {'X': 'CWProperty', 'ET': 'CWEType'},
                                          {'X': 'CWRType', 'ET': 'CWEType'}, {'X': 'Email', 'ET': 'CWEType'},
                                          {'X': 'EmailAddress', 'ET': 'CWEType'}, {'X': 'EmailPart', 'ET': 'CWEType'},
-                                         {'X': 'EmailThread', 'ET': 'CWEType'}, {'X': 'File', 'ET': 'CWEType'},
+                                         {'X': 'EmailThread', 'ET': 'CWEType'},
+                                         {'ET': 'CWEType', 'X': 'ExternalUri'},
+                                         {'X': 'File', 'ET': 'CWEType'},
                                          {'X': 'Folder', 'ET': 'CWEType'}, {'X': 'Image', 'ET': 'CWEType'},
                                          {'X': 'Personne', 'ET': 'CWEType'}, {'X': 'RQLExpression', 'ET': 'CWEType'},
                                          {'X': 'Societe', 'ET': 'CWEType'}, {'X': 'SubDivision', 'ET': 'CWEType'},
@@ -958,7 +961,9 @@
                                {'ET': 'CWEType', 'X': 'CWProperty'}, {'ET': 'CWEType', 'X': 'CWRType'},
                                {'ET': 'CWEType', 'X': 'CWUser'}, {'ET': 'CWEType', 'X': 'Email'},
                                {'ET': 'CWEType', 'X': 'EmailAddress'}, {'ET': 'CWEType', 'X': 'EmailPart'},
-                               {'ET': 'CWEType', 'X': 'EmailThread'}, {'ET': 'CWEType', 'X': 'File'},
+                               {'ET': 'CWEType', 'X': 'EmailThread'},
+                               {'ET': 'CWEType', 'X': 'ExternalUri'},
+                               {'ET': 'CWEType', 'X': 'File'},
                                {'ET': 'CWEType', 'X': 'Folder'}, {'ET': 'CWEType', 'X': 'Image'},
                                {'ET': 'CWEType', 'X': 'Note'}, {'ET': 'CWEType', 'X': 'Personne'},
                                {'ET': 'CWEType', 'X': 'RQLExpression'}, {'ET': 'CWEType', 'X': 'Societe'},
--- a/server/test/unittest_querier.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_querier.py	Fri Aug 07 12:20:50 2009 +0200
@@ -110,7 +110,7 @@
                                        'ET': 'CWEType', 'ETN': 'String'}])
         rql, solutions = partrqls[1]
         self.assertEquals(rql,  'Any ETN,X WHERE X is ET, ET name ETN, ET is CWEType, '
-                          'X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Card, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Note, Personne, RQLExpression, Societe, State, SubDivision, Tag, TrInfo, Transition)')
+                          'X is IN(Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Card, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Image, Note, Personne, RQLExpression, Societe, State, SubDivision, Tag, TrInfo, Transition)')
         self.assertListEquals(sorted(solutions),
                               sorted([{'X': 'Bookmark', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'Card', 'ETN': 'String', 'ET': 'CWEType'},
@@ -131,6 +131,7 @@
                                       {'X': 'CWProperty', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'CWRType', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'CWUser', 'ETN': 'String', 'ET': 'CWEType'},
+                                      {'X': 'ExternalUri', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'File', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'Folder', 'ETN': 'String', 'ET': 'CWEType'},
                                       {'X': 'Image', 'ETN': 'String', 'ET': 'CWEType'},
@@ -226,10 +227,10 @@
 
     def test_select_2(self):
         rset = self.execute('Any X ORDERBY N WHERE X is CWGroup, X name N')
-        self.assertEquals(tuplify(rset.rows), [(3,), (1,), (4,), (2,)])
+        self.assertEquals(tuplify(rset.rows), [(1,), (2,), (3,), (4,)])
         self.assertEquals(rset.description, [('CWGroup',), ('CWGroup',), ('CWGroup',), ('CWGroup',)])
         rset = self.execute('Any X ORDERBY N DESC WHERE X is CWGroup, X name N')
-        self.assertEquals(tuplify(rset.rows), [(2,), (4,), (1,), (3,)])
+        self.assertEquals(tuplify(rset.rows), [(4,), (3,), (2,), (1,)])
 
     def test_select_3(self):
         rset = self.execute('Any N GROUPBY N WHERE X is CWGroup, X name N')
@@ -272,7 +273,7 @@
 
     def test_select_5(self):
         rset = self.execute('Any X, TMP ORDERBY TMP WHERE X name TMP, X is CWGroup')
-        self.assertEquals(tuplify(rset.rows), [(3, 'guests',), (1, 'managers',), (4, 'owners',), (2, 'users',)])
+        self.assertEquals(tuplify(rset.rows), [(1, 'guests',), (2, 'managers',), (3, 'owners',), (4, 'users',)])
         self.assertEquals(rset.description, [('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',), ('CWGroup', 'String',)])
 
     def test_select_6(self):
@@ -344,7 +345,8 @@
         peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0]
         rset = self.execute('Any X WHERE X eid %(x)s, P? connait X', {'x':peid1}, 'x')
         self.assertEquals(rset.rows, [[peid1]])
-        rset = self.execute('Any X WHERE X eid %(x)s, X require_permission P?', {'x':peid1}, 'x')
+        rset = self.execute('Any X WHERE X eid %(x)s, X require_permission P?',
+                            {'x':peid1}, 'x')
         self.assertEquals(rset.rows, [[peid1]])
 
     def test_select_left_outer_join(self):
@@ -464,10 +466,12 @@
                             'WHERE RT name N, RDEF relation_type RT '
                             'HAVING COUNT(RDEF) > 10')
         self.assertListEquals(rset.rows,
-                              [[u'description', 11], ['in_basket', 11],
-                               [u'name', 13], [u'created_by', 33],
-                               [u'creation_date', 33], [u'is', 33], [u'is_instance_of', 33],
-                               [u'modification_date', 33], [u'owned_by', 33]])
+                              [[u'description', 11],
+                               [u'name', 13], [u'created_by', 34],
+                               [u'creation_date', 34], [u'cwuri', 34],
+                               ['in_basket', 34],
+                               [u'is', 34], [u'is_instance_of', 34],
+                               [u'modification_date', 34], [u'owned_by', 34]])
 
     def test_select_aggregat_having_dumb(self):
         # dumb but should not raise an error
@@ -553,10 +557,10 @@
 
     def test_select_limit_offset(self):
         rset = self.execute('CWGroup X ORDERBY N LIMIT 2 WHERE X name N')
-        self.assertEquals(tuplify(rset.rows), [(3,), (1,)])
+        self.assertEquals(tuplify(rset.rows), [(1,), (2,)])
         self.assertEquals(rset.description, [('CWGroup',), ('CWGroup',)])
         rset = self.execute('CWGroup X ORDERBY N LIMIT 2 OFFSET 2 WHERE X name N')
-        self.assertEquals(tuplify(rset.rows), [(4,), (2,)])
+        self.assertEquals(tuplify(rset.rows), [(3,), (4,)])
 
     def test_select_symetric(self):
         self.execute("INSERT Personne X: X nom 'machin'")
--- a/server/test/unittest_repository.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_repository.py	Fri Aug 07 12:20:50 2009 +0200
@@ -20,7 +20,7 @@
 
 from cubicweb import BadConnectionId, RepositoryError, ValidationError, UnknownEid, AuthenticationError
 from cubicweb.schema import CubicWebSchema, RQLConstraint
-from cubicweb.dbapi import connect, repo_connect
+from cubicweb.dbapi import connect, repo_connect, multiple_connections_unfix
 from cubicweb.devtools.apptest import RepositoryBasedTC
 from cubicweb.devtools.repotest import tuplify
 from cubicweb.server import repository
@@ -226,12 +226,12 @@
         # check order of attributes is respected
         self.assertListEquals([r.type for r in schema.eschema('CWAttribute').ordered_relations()
                                if not r.type in ('eid', 'is', 'is_instance_of', 'identity',
-                                                 'creation_date', 'modification_date',
+                                                 'creation_date', 'modification_date', 'cwuri',
                                                  'owned_by', 'created_by')],
-                              ['relation_type', 'from_entity', 'to_entity', 'constrained_by',
+                              ['relation_type', 'from_entity', 'in_basket', 'to_entity', 'constrained_by',
                                'cardinality', 'ordernum',
                                'indexed', 'fulltextindexed', 'internationalizable',
-                               'defaultval', 'description_format', 'description'])
+                               'defaultval', 'description', 'description_format'])
 
         self.assertEquals(schema.eschema('CWEType').main_attribute(), 'name')
         self.assertEquals(schema.eschema('State').main_attribute(), 'name')
@@ -276,13 +276,17 @@
 
     def _pyro_client(self, done):
         cnx = connect(self.repo.config.appid, u'admin', 'gingkow')
-        # check we can get the schema
-        schema = cnx.get_schema()
-        self.assertEquals(schema.__hashmode__, None)
-        cu = cnx.cursor()
-        rset = cu.execute('Any U,G WHERE U in_group G')
-        cnx.close()
-        done.append(True)
+        try:
+            # check we can get the schema
+            schema = cnx.get_schema()
+            self.assertEquals(schema.__hashmode__, None)
+            cu = cnx.cursor()
+            rset = cu.execute('Any U,G WHERE U in_group G')
+            cnx.close()
+            done.append(True)
+        finally:
+            # connect monkey path some method by default, remove them
+            multiple_connections_unfix()
 
     def test_internal_api(self):
         repo = self.repo
@@ -328,6 +332,16 @@
         no_is_rset = self.execute('Any X WHERE NOT X is ET')
         self.failIf(no_is_rset, no_is_rset.description)
 
+#     def test_perfo(self):
+#         self.set_debug(True)
+#         from time import time, clock
+#         t, c = time(), clock()
+#         try:
+#             self.create_user('toto')
+#         finally:
+#             self.set_debug(False)
+#         print 'test time: %.3f (time) %.3f (cpu)' % ((time() - t), clock() - c)
+
 
 class DataHelpersTC(RepositoryBasedTC):
 
@@ -357,7 +371,7 @@
         self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, self.session)
 
     def test_add_delete_info(self):
-        entity = self.repo.vreg.etype_class('Personne')(self.session, None, None)
+        entity = self.repo.vreg['etypes'].etype_class('Personne')(self.session)
         entity.eid = -1
         entity.complete = lambda x: None
         self.repo.add_info(self.session, entity, self.repo.sources_by_uri['system'])
--- a/server/test/unittest_rql2sql.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_rql2sql.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1120,6 +1120,32 @@
     ]
 from logilab.common.adbh import ADV_FUNC_HELPER_DIRECTORY
 
+class CWRQLTC(RQLGeneratorTC):
+    schema = schema
+
+    def test_nonregr_sol(self):
+        delete = self.rqlhelper.parse(
+            'DELETE X read_permission READ_PERMISSIONSUBJECT,X add_permission ADD_PERMISSIONSUBJECT,'
+            'X in_basket IN_BASKETSUBJECT,X delete_permission DELETE_PERMISSIONSUBJECT,'
+            'X initial_state INITIAL_STATESUBJECT,X update_permission UPDATE_PERMISSIONSUBJECT,'
+            'X created_by CREATED_BYSUBJECT,X is ISSUBJECT,X is_instance_of IS_INSTANCE_OFSUBJECT,'
+            'X owned_by OWNED_BYSUBJECT,X specializes SPECIALIZESSUBJECT,ISOBJECT is X,'
+            'SPECIALIZESOBJECT specializes X,STATE_OFOBJECT state_of X,IS_INSTANCE_OFOBJECT is_instance_of X,'
+            'TO_ENTITYOBJECT to_entity X,TRANSITION_OFOBJECT transition_of X,FROM_ENTITYOBJECT from_entity X '
+            'WHERE X is CWEType')
+        self.rqlhelper.compute_solutions(delete)
+        def var_sols(var):
+            s = set()
+            for sol in delete.solutions:
+                s.add(sol.get(var))
+            return s
+        self.assertEquals(var_sols('FROM_ENTITYOBJECT'), set(('CWAttribute', 'CWRelation')))
+        self.assertEquals(var_sols('FROM_ENTITYOBJECT'), delete.defined_vars['FROM_ENTITYOBJECT'].stinfo['possibletypes'])
+        self.assertEquals(var_sols('ISOBJECT'),
+                          set(x.type for x in self.schema.entities() if not x.is_final()))
+        self.assertEquals(var_sols('ISOBJECT'), delete.defined_vars['ISOBJECT'].stinfo['possibletypes'])
+
+
 class PostgresSQLGeneratorTC(RQLGeneratorTC):
     schema = schema
 
@@ -1227,7 +1253,6 @@
                     varmap={'X': 'T00.x', 'X.login': 'T00.l'})
 
     def test_varmap3(self):
-        self.set_debug(True)
         self._check('Any %(x)s,D WHERE F data D, F is File',
                     'SELECT 728, _TDF0.C0\nFROM _TDF0',
                     args={'x': 728},
--- a/server/test/unittest_rqlrewrite.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_rqlrewrite.py	Fri Aug 07 12:20:50 2009 +0200
@@ -107,7 +107,7 @@
                              "Any S WHERE S owned_by C, C eid %(u)s, A eid %(B)s, "
                              "EXISTS((C identity A) OR (C in_state D, E identity A, "
                              "E in_state D, D name 'subscribed'), D is State, E is CWUser), "
-                             "S is IN(Affaire, Basket, Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Card, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Note, Personne, RQLExpression, Societe, State, SubDivision, Tag, TrInfo, Transition)")
+                             "S is IN(Affaire, Basket, Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Card, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Image, Note, Personne, RQLExpression, Societe, State, SubDivision, Tag, TrInfo, Transition)")
 
     def test_simplified_rqlst(self):
         card_constraint = ('X in_state S, U in_group G, P require_state S,'
--- a/server/test/unittest_schemaserial.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_schemaserial.py	Fri Aug 07 12:20:50 2009 +0200
@@ -23,15 +23,15 @@
     def test_eschema2rql1(self):
         self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))),
                               [
-            ('INSERT CWEType X: X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s',
-             {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the application schema',
-              'meta': True, 'name': u'CWAttribute', 'final': False})
+            ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
+             {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema',
+              'name': u'CWAttribute', 'final': False})
             ])
 
     def test_eschema2rql2(self):
         self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [
-                ('INSERT CWEType X: X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s',
-                 {'description': u'', 'final': True, 'meta': True, 'name': u'String'})])
+                ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
+                 {'description': u'', 'final': True, 'name': u'String'})])
 
     def test_eschema2rql_specialization(self):
         self.assertListEquals(list(specialize2rql(schema)),
@@ -44,8 +44,8 @@
     def test_rschema2rql1(self):
         self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'))),
                              [
-            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s',
-             {'description': u'link a relation definition to its relation type', 'meta': True, 'symetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
+            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s',
+             {'description': u'link a relation definition to its relation type', 'symetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
 
             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
              {'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
@@ -63,7 +63,7 @@
     def test_rschema2rql2(self):
         self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'))),
                               [
-            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s', {'description': u'core relation giving to a group the permission to add an entity or relation type', 'meta': True, 'symetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
+            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s', {'description': u'core relation giving to a group the permission to add an entity or relation type', 'symetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
 
             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
              {'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 3, 'cardinality': u'**', 'se': 'CWEType'}),
@@ -79,8 +79,8 @@
     def test_rschema2rql3(self):
         self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'))),
                              [
-            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s',
-             {'description': u'', 'meta': False, 'symetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
+            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s',
+             {'description': u'', 'symetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
 
             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
              {'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWRelation'}),
@@ -100,31 +100,31 @@
 
     def test_updateeschema2rql1(self):
         self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'))),
-                              [('SET X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
-                                {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the application schema', 'meta': True, 'et': 'CWAttribute', 'final': False, 'name': u'CWAttribute'}),
+                              [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
+                                {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema', 'et': 'CWAttribute', 'final': False, 'name': u'CWAttribute'}),
                                ])
 
     def test_updateeschema2rql2(self):
         self.assertListEquals(list(updateeschema2rql(schema.eschema('String'))),
-                              [('SET X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
-                                {'description': u'', 'meta': True, 'et': 'String', 'final': True, 'name': u'String'})
+                              [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
+                                {'description': u'', 'et': 'String', 'final': True, 'name': u'String'})
                                ])
 
     def test_updaterschema2rql1(self):
         self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'))),
                              [
-            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
+            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
              {'rt': 'relation_type', 'symetric': False,
               'description': u'link a relation definition to its relation type',
-              'meta': True, 'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
+              'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
             ])
 
     def test_updaterschema2rql2(self):
         expected = [
-            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
+            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
              {'rt': 'add_permission', 'symetric': False,
               'description': u'core relation giving to a group the permission to add an entity or relation type',
-              'meta': True, 'final': False, 'fulltext_container': None, 'inlined': False, 'name': u'add_permission'})
+              'final': False, 'fulltext_container': None, 'inlined': False, 'name': u'add_permission'})
             ]
         for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'))):
             yield self.assertEquals, (rql, args), expected[i]
--- a/server/test/unittest_security.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/test/unittest_security.py	Fri Aug 07 12:20:50 2009 +0200
@@ -499,7 +499,7 @@
         self.assertRaises(Unauthorized,
                           self.schema['Affaire'].check_perm, session, 'update', eid)
         cu = cnx.cursor()
-        cu.execute('SET X in_state S WHERE X ref "ARCT01", S name "abort"')
+        cu.execute('SET X in_state S WHERE X ref "ARCT01", S name "ben non"')
         cnx.commit()
         # though changing a user state (even logged user) is reserved to managers
         rql = u"SET X in_state S WHERE X eid %(x)s, S name 'deactivated'"
@@ -508,5 +508,26 @@
         # from the current state but Unauthorized if it exists but user can't pass it
         self.assertRaises(ValidationError, cu.execute, rql, {'x': cnx.user(self.current_session()).eid}, 'x')
 
+    def test_trinfo_security(self):
+        aff = self.execute('INSERT Affaire X: X ref "ARCT01"').get_entity(0, 0)
+        self.commit()
+        # can change tr info comment
+        self.execute('SET TI comment %(c)s WHERE TI wf_info_for X, X ref "ARCT01"',
+                     {'c': u'creation'})
+        self.commit()
+        aff.clear_related_cache('wf_info_for', 'object')
+        self.assertEquals(aff.latest_trinfo().comment, 'creation')
+        # but not from_state/to_state
+        self.execute('SET X in_state S WHERE X ref "ARCT01", S name "ben non"')
+        self.commit()
+        aff.clear_related_cache('wf_info_for', role='object')
+        trinfo = aff.latest_trinfo()
+        self.assertRaises(Unauthorized,
+                          self.execute, 'SET TI from_state S WHERE TI eid %(ti)s, S name "ben non"',
+                          {'ti': trinfo.eid}, 'ti')
+        self.assertRaises(Unauthorized,
+                          self.execute, 'SET TI to_state S WHERE TI eid %(ti)s, S name "pitetre"',
+                          {'ti': trinfo.eid}, 'ti')
+
 if __name__ == '__main__':
     unittest_main()
--- a/server/utils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/server/utils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -96,11 +96,11 @@
 
 class LoopTask(object):
     """threaded task restarting itself once executed"""
-    def __init__(self, interval, func):
+    def __init__(self, interval, func, args):
         self.interval = interval
-        def auto_restart_func(self=self, func=func):
+        def auto_restart_func(self=self, func=func, args=args):
             try:
-                func()
+                func(*args)
             finally:
                 self.start()
         self.func = auto_restart_func
--- a/sobjects/hooks.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/sobjects/hooks.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,11 +7,32 @@
 """
 __docformat__ = "restructuredtext en"
 
+from datetime import datetime
+
+from cubicweb import RepositoryError
 from cubicweb.common.uilib import soup2xhtml
 from cubicweb.server.hooksmanager import Hook
 from cubicweb.server.pool import PreCommitOperation
 
 
+class SetModificationDateOnStateChange(Hook):
+    """update entity's modification date after changing its state"""
+    events = ('after_add_relation',)
+    accepts = ('in_state',)
+
+    def call(self, session, fromeid, rtype, toeid):
+        if fromeid in session.transaction_data.get('neweids', ()):
+            # new entity, not needed
+            return
+        entity = session.entity_from_eid(fromeid)
+        try:
+            entity.set_attributes(modification_date=datetime.now())
+        except RepositoryError, ex:
+            # usually occurs if entity is coming from a read-only source
+            # (eg ldap user)
+            self.warning('cant change modification date for %s: %s', entity, ex)
+
+
 class AddUpdateCWUserHook(Hook):
     """ensure user logins are stripped"""
     events = ('before_add_entity', 'before_update_entity',)
--- a/sobjects/notification.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/sobjects/notification.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 try:
     from socket import gethostname
 except ImportError:
-    def gethostname():
+    def gethostname(): # gae
         return 'XXX'
 
 from logilab.common.textutils import normalize_text
@@ -62,7 +62,7 @@
 class RenderAndSendNotificationView(PreCommitOperation):
     """delay rendering of notification view until precommit"""
     def precommit_event(self):
-        if self.view.rset[0][0] in self.session.transaction_data.get('pendingeids', ()):
+        if self.view.rset and self.view.rset[0][0] in self.session.transaction_data.get('pendingeids', ()):
             return # entity added and deleted in the same transaction
         self.view.render_and_send(**getattr(self, 'viewargs', {}))
 
@@ -76,8 +76,8 @@
             return
         rset = entity.related('wf_info_for')
         try:
-            view = session.vreg.select_view('notif_status_change',
-                                            session, rset, row=0)
+            view = session.vreg['views'].select('notif_status_change', session,
+                                                rset=rset, row=0)
         except RegistryException:
             return
         comment = entity.printable_value('comment', format='text/plain')
@@ -100,7 +100,7 @@
         rset = session.eid_rset(fromeid)
         vid = 'notif_%s_%s' % (self.event,  rtype)
         try:
-            view = session.vreg.select_view(vid, session, rset, row=0)
+            view = session.vreg['views'].select(vid, session, rset=rset, row=0)
         except RegistryException:
             return
         RenderAndSendNotificationView(session, view=view)
@@ -117,7 +117,7 @@
         rset = entity.as_rset()
         vid = 'notif_%s' % self.event
         try:
-            view = session.vreg.select_view(vid, session, rset, row=0)
+            view = session.vreg['views'].select(vid, session, rset=rset, row=0)
         except RegistryException:
             return
         RenderAndSendNotificationView(session, view=view)
@@ -133,14 +133,17 @@
     * set a content attribute to define the content of the email (unless you
       override call)
     """
+    # XXX refactor this class to work with len(rset) > 1
+
     msgid_timestamp = True
 
     def recipients(self):
-        finder = self.vreg.select_component('recipients_finder', self.req, self.rset)
+        finder = self.vreg['components'].select('recipients_finder', self.req,
+                                  rset=self.rset)
         return finder.recipients()
 
     def subject(self):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         subject = self.req._(self.message)
         etype = entity.dc_type()
         eid = entity.eid
@@ -153,7 +156,7 @@
         return self.req.actual_session().user.login
 
     def context(self, **kwargs):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         for key, val in kwargs.iteritems():
             if val and isinstance(val, unicode) and val.strip():
                kwargs[key] = self.req._(val)
@@ -183,15 +186,19 @@
                  DeprecationWarning, stacklevel=1)
             lang = self.vreg.property_value('ui.language')
             recipients = zip(recipients, repeat(lang))
-        entity = self.entity(0, 0)
-        # if the view is using timestamp in message ids, no way to reference
-        # previous email
-        if not self.msgid_timestamp:
-            refs = [self.construct_message_id(eid)
-                    for eid in entity.notification_references(self)]
+        if self.rset is not None:
+            entity = self.entity(self.row or 0, self.col or 0)
+            # if the view is using timestamp in message ids, no way to reference
+            # previous email
+            if not self.msgid_timestamp:
+                refs = [self.construct_message_id(eid)
+                        for eid in entity.notification_references(self)]
+            else:
+                refs = ()
+            msgid = self.construct_message_id(entity.eid)
         else:
             refs = ()
-        msgid = self.construct_message_id(entity.eid)
+            msgid = None
         userdata = self.req.user_data()
         origlang = self.req.lang
         for emailaddr, lang in recipients:
@@ -277,7 +284,7 @@
 """
 
     def context(self, **kwargs):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         content = entity.printable_value(self.content_attr, format='text/plain')
         if content:
             contentformat = getattr(entity, self.content_attr + '_format', 'text/rest')
@@ -285,7 +292,7 @@
         return super(ContentAddedView, self).context(content=content, **kwargs)
 
     def subject(self):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         return  u'%s #%s (%s)' % (self.req.__('New %s' % entity.e_schema),
                                   entity.eid, self.user_login())
 
--- a/sobjects/supervising.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/sobjects/supervising.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,6 +10,7 @@
 
 from cubicweb import UnknownEid
 from cubicweb.selectors import none_rset
+from cubicweb.schema import display_name
 from cubicweb.view import Component
 from cubicweb.common.mail import format_mail
 from cubicweb.server.hooksmanager import Hook
@@ -30,12 +31,16 @@
             SupervisionMailOp(session)
 
     def _call(self, *args):
-        if self._event() == 'update_entity' and args[0].e_schema == 'CWUser':
-            updated = set(args[0].iterkeys())
-            if not (updated - frozenset(('eid', 'modification_date', 'last_login_time'))):
-                # don't record last_login_time update which are done
-                # automatically at login time
+        if self._event() == 'update_entity':
+            if args[0].eid in self.session.transaction_data.get('neweids', ()):
                 return False
+            if args[0].e_schema == 'CWUser':
+                updated = set(args[0].iterkeys())
+                if not (updated - frozenset(('eid', 'modification_date',
+                                             'last_login_time'))):
+                    # don't record last_login_time update which are done
+                    # automatically at login time
+                    return False
         self.session.transaction_data.setdefault('pendingchanges', []).append(
             (self._event(), args))
         return True
@@ -217,8 +222,8 @@
     of changes
     """
     def _get_view(self):
-        return self.session.vreg.select_component('supervision_notif',
-                                                  self.session, None)
+        return self.session.vreg['components'].select('supervision_notif',
+                                                      self.session)
 
     def _prepare_email(self):
         session = self.session
--- a/sobjects/test/data/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/sobjects/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,8 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import RelationDefinition
+
 class comments(RelationDefinition):
     subject = 'Comment'
     object = 'Card'
--- a/sobjects/test/unittest_notification.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/sobjects/test/unittest_notification.py	Fri Aug 07 12:20:50 2009 +0200
@@ -56,7 +56,8 @@
         self.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U '
                      'WHERE U eid %(x)s', {'x': urset[0][0]})
         self.commit() # commit so that admin get its properties updated
-        finder = self.vreg.select_component('recipients_finder', self.request(), urset)
+        finder = self.vreg['components'].select('recipients_finder',
+                                                self.request(), rset=urset)
         self.set_option('default-recipients-mode', 'none')
         self.assertEquals(finder.recipients(), [])
         self.set_option('default-recipients-mode', 'users')
@@ -72,8 +73,9 @@
         req = self.session()
         u = self.create_user('toto', req=req)
         assert u.req
+        assert u.rset
         self.execute('SET X in_state S WHERE X eid %s, S name "deactivated"' % u.eid)
-        v = self.vreg.select_view('notif_status_change', req, u.rset, row=0)
+        v = self.vreg['views'].select('notif_status_change', req, rset=u.rset, row=0)
         content = v.render(row=0, comment='yeah',
                            previous_state='activated',
                            current_state='deactivated')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spa2rql.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,207 @@
+"""SPARQL -> RQL translator
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+from logilab.common import make_domains
+from rql import TypeResolverException
+from fyzz.yappsparser import parse
+from fyzz import ast
+
+from cubicweb.xy import xy
+
+
+class UnsupportedQuery(Exception): pass
+
+def order_limit_offset(sparqlst):
+    addons = ''
+    if sparqlst.orderby:
+        sortterms = ', '.join('%s %s' % (var.name.upper(), ascdesc.upper())
+                              for var, ascdesc in sparqlst.orderby)
+        addons += ' ORDERBY %s' % sortterms
+    if sparqlst.limit:
+        addons += ' LIMIT %s' % sparqlst.limit
+    if sparqlst.offset:
+        addons += ' OFFSET %s' % sparqlst.offset
+    return addons
+
+
+class QueryInfo(object):
+    """wrapper class containing necessary information to generate a RQL query
+    from a sparql syntax tree
+    """
+    def __init__(self, sparqlst):
+        self.sparqlst = sparqlst
+        if sparqlst.selected == ['*']:
+            self.selection = [var.upper() for var in sparqlst.variables]
+        else:
+            self.selection = [var.name.upper() for var in sparqlst.selected]
+        self.possible_types = {}
+        self.infer_types_info = []
+        self.union_params = []
+        self.restrictions = []
+        self.literals = {}
+        self._litcount = 0
+
+    def add_literal(self, value):
+        key = chr(ord('a') + self._litcount)
+        self._litcount += 1
+        self.literals[key] = value
+        return key
+
+    def set_possible_types(self, var, varpossibletypes):
+        """set/restrict possible types for the given variable.
+
+        :return: True if something changed, else false.
+        :raise: TypeResolverException if no more type allowed
+        """
+        varpossibletypes = set(varpossibletypes)
+        try:
+            ctypes = self.possible_types[var]
+            nbctypes = len(ctypes)
+            ctypes &= varpossibletypes
+            if not ctypes:
+                raise TypeResolverException()
+            return len(ctypes) != nbctypes
+        except KeyError:
+            self.possible_types[var] = varpossibletypes
+            return True
+
+    def infer_types(self):
+        # XXX should use something similar to rql.analyze for proper type inference
+        modified = True
+        # loop to infer types until nothing changed
+        while modified:
+            modified = False
+            for yams_predicates, subjvar, obj in self.infer_types_info:
+                nbchoices = len(yams_predicates)
+                # get possible types for the subject variable, according to the
+                # current predicate
+                svptypes = set(s for s, r, o in yams_predicates)
+                if not '*' in svptypes:
+                    if self.set_possible_types(subjvar, svptypes):
+                        modified = True
+                # restrict predicates according to allowed subject var types
+                if subjvar in self.possible_types:
+                    yams_predicates = [(s, r, o) for s, r, o in yams_predicates
+                                       if s == '*' or s in self.possible_types[subjvar]]
+                if isinstance(obj, ast.SparqlVar):
+                    # make a valid rql var name
+                    objvar = obj.name.upper()
+                    # get possible types for the object variable, according to
+                    # the current predicate
+                    ovptypes = set(o for s, r, o in yams_predicates)
+                    if not '*' in ovptypes:
+                        if self.set_possible_types(objvar, ovptypes):
+                            modified = True
+                    # restrict predicates according to allowed object var types
+                    if objvar in self.possible_types:
+                        yams_predicates = [(s, r, o) for s, r, o in yams_predicates
+                                           if o == '*' or o in self.possible_types[objvar]]
+                # ensure this still make sense
+                if not yams_predicates:
+                    raise TypeResolverException()
+                if len(yams_predicates) != nbchoices:
+                    modified = True
+
+    def build_restrictions(self):
+        # now, for each predicate
+        for yams_predicates, subjvar, obj in self.infer_types_info:
+            rel = yams_predicates[0]
+            # if there are several yams relation type equivalences, we will have
+            # to generate several unioned rql queries
+            for s, r, o in yams_predicates[1:]:
+                if r != rel[1]:
+                    self.union_params.append((yams_predicates, subjvar, obj))
+                    break
+            # else we can simply add it to base rql restrictions
+            else:
+                restr = self.build_restriction(subjvar, rel[1], obj)
+                self.restrictions.append(restr)
+
+    def build_restriction(self, subjvar, rtype, obj):
+        if isinstance(obj, ast.SparqlLiteral):
+            key = self.add_literal(obj.value)
+            objvar = '%%(%s)s' % key
+        else:
+            assert isinstance(obj, ast.SparqlVar)
+            # make a valid rql var name
+            objvar = obj.name.upper()
+        # else we can simply add it to base rql restrictions
+        return '%s %s %s' % (subjvar, rtype, objvar)
+
+    def finalize(self):
+        """return corresponding rql query (string) / args (dict)"""
+        for varname, ptypes in self.possible_types.iteritems():
+            if len(ptypes) == 1:
+                self.restrictions.append('%s is %s' % (varname, iter(ptypes).next()))
+        unions = []
+        for releq, subjvar, obj in self.union_params:
+            thisunions = []
+            for st, rt, ot in releq:
+                thisunions.append([self.build_restriction(subjvar, rt, obj)])
+                if st != '*':
+                    thisunions[-1].append('%s is %s' % (subjvar, st))
+                if isinstance(obj, ast.SparqlVar) and ot != '*':
+                    objvar = obj.name.upper()
+                    thisunions[-1].append('%s is %s' % (objvar, objvar))
+            if not unions:
+                unions = thisunions
+            else:
+                unions = zip(*make_domains([unions, thisunions]))
+        selection = 'Any ' + ', '.join(self.selection)
+        sparqlst = self.sparqlst
+        if sparqlst.distinct:
+            selection = 'DISTINCT ' + selection
+        if unions:
+            baserql = '%s WHERE %s' % (selection, ', '.join(self.restrictions))
+            rqls = ['(%s, %s)' % (baserql, ', '.join(unionrestrs))
+                    for unionrestrs in unions]
+            rql = ' UNION '.join(rqls)
+            if sparqlst.orderby or sparqlst.limit or sparqlst.offset:
+                rql = '%s%s WITH %s BEING (%s)' % (
+                    selection, order_limit_offset(sparqlst),
+                    ', '.join(self.selection), rql)
+        else:
+            rql = '%s%s WHERE %s' % (selection, order_limit_offset(sparqlst),
+                                      ', '.join(self.restrictions))
+        return rql, self.literals
+
+
+class Sparql2rqlTranslator(object):
+    def __init__(self, yschema):
+        self.yschema = yschema
+
+    def translate(self, sparql):
+        sparqlst = parse(sparql)
+        if sparqlst.type != 'select':
+            raise UnsupportedQuery()
+        qi = QueryInfo(sparqlst)
+        for subj, predicate, obj in sparqlst.where:
+            if not isinstance(subj, ast.SparqlVar):
+                raise UnsupportedQuery()
+            # make a valid rql var name
+            subjvar = subj.name.upper()
+            if predicate == ('', 'a'):
+                # special 'is' relation
+                if not isinstance(obj, tuple):
+                    raise UnsupportedQuery()
+                # restrict possible types for the subject variable
+                qi.set_possible_types(
+                    subjvar, xy.yeq(':'.join(obj), isentity=True))
+            else:
+                # 'regular' relation (eg not 'is')
+                if not isinstance(predicate, tuple):
+                    raise UnsupportedQuery()
+                # list of 3-uple
+                #   (yams etype (subject), yams rtype, yams etype (object))
+                # where subject / object entity type may '*' if not specified
+                yams_predicates = xy.yeq(':'.join(predicate))
+                qi.infer_types_info.append((yams_predicates, subjvar, obj))
+                if not isinstance(obj, (ast.SparqlLiteral, ast.SparqlVar)):
+                    raise UnsupportedQuery()
+        qi.infer_types()
+        qi.build_restrictions()
+        return qi
--- a/test/data/erqlexpr_on_ertype.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/data/erqlexpr_on_ertype.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,9 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, RelationType, SubjectRelation
+from cubicweb.schema import ERQLExpression
+
 class ToTo(EntityType):
     permissions = {
         'read': ('managers',),
--- a/test/data/rqlexpr_on_ertype_read.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/data/rqlexpr_on_ertype_read.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,9 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, RelationType, SubjectRelation
+from cubicweb.schema import RRQLExpression
+
 class ToTo(EntityType):
     permissions = {
         'read': ('managers',),
--- a/test/data/rrqlexpr_on_attr.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/data/rrqlexpr_on_attr.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,9 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, RelationType, String
+from cubicweb.schema import RRQLExpression
+
 class ToTo(EntityType):
     permissions = {
         'read': ('managers',),
--- a/test/data/rrqlexpr_on_eetype.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/data/rrqlexpr_on_eetype.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,9 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, String
+from cubicweb.schema import RRQLExpression
+
 class ToTo(EntityType):
     permissions = {
         'read': ('managers', RRQLExpression('S bla Y'),),
--- a/test/data/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,6 +5,9 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+
+from yams.buildobjs import EntityType, String, SubjectRelation, RelationDefinition
+
 class Personne(EntityType):
     nom = String(required=True)
     prenom = String()
--- a/test/unittest_cwconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_cwconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,7 +8,6 @@
 import sys
 import os
 from os.path import dirname, join, abspath
-from tempfile import mktemp
 
 from logilab.common.testlib import TestCase, unittest_main
 from logilab.common.changelog import Version
--- a/test/unittest_cwctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_cwctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,9 +13,9 @@
 if os.environ.get('APYCOT_ROOT'):
     root = os.environ['APYCOT_ROOT']
     CUBES_DIR = '%s/local/share/cubicweb/cubes/' % root
-    os.environ['CW_CUBES'] = CUBES_DIR
+    os.environ['CW_CUBES_PATH'] = CUBES_DIR
     REGISTRY_DIR = '%s/etc/cubicweb.d/' % root
-    os.environ['CW_REGISTRY_DIR'] = REGISTRY_DIR
+    os.environ['CW_INSTANCES_DIR'] = REGISTRY_DIR
 
 from cubicweb.cwconfig import CubicWebConfiguration
 CubicWebConfiguration.load_cwctl_plugins()
--- a/test/unittest_entity.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_entity.py	Fri Aug 07 12:20:50 2009 +0200
@@ -55,7 +55,9 @@
         e.copy_relations(oe.eid)
         self.assertEquals(len(e.ecrit_par), 1)
         self.assertEquals(e.ecrit_par[0].eid, p.eid)
-        self.assertEquals(len(e.reverse_tags), 0)
+        self.assertEquals(len(e.reverse_tags), 1)
+        # check meta-relations are not copied, set on commit
+        self.assertEquals(len(e.created_by), 0)
 
     def test_copy_with_nonmeta_composite_inlined(self):
         p = self.add_entity('Personne', nom=u'toto')
@@ -119,9 +121,9 @@
 
     def test_fetch_rql(self):
         user = self.user()
-        Personne = self.vreg.etype_class('Personne')
-        Societe = self.vreg.etype_class('Societe')
-        Note = self.vreg.etype_class('Note')
+        Personne = self.vreg['etypes'].etype_class('Personne')
+        Societe = self.vreg['etypes'].etype_class('Societe')
+        Note = self.vreg['etypes'].etype_class('Note')
         peschema = Personne.e_schema
         seschema = Societe.e_schema
         peschema.subject_relation('travaille').set_rproperty(peschema, seschema, 'cardinality', '1*')
@@ -173,8 +175,8 @@
 
     def test_related_rql(self):
         from cubicweb.entities import fetch_config
-        Personne = self.vreg.etype_class('Personne')
-        Note = self.vreg.etype_class('Note')
+        Personne = self.vreg['etypes'].etype_class('Personne')
+        Note = self.vreg['etypes'].etype_class('Note')
         Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type'))
         Note.fetch_attrs, Note.fetch_order = fetch_config(('type',))
         aff = self.add_entity('Personne', nom=u'pouet')
@@ -215,7 +217,7 @@
         e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
                             content_format=u'text/rest')
         self.assertEquals(e.printable_value('content'),
-                          '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/managers">*ReST*</a></p>\n')
+                          '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/guests">*ReST*</a></p>\n')
         e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>'
         e['content_format'] = 'text/html'
         self.assertEquals(e.printable_value('content'),
@@ -322,19 +324,20 @@
     def test_complete_relation(self):
         self.execute('SET RT add_permission G WHERE RT name "wf_info_for", G name "managers"')
         self.commit()
+        session = self.session()
         try:
-            eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,'
-                               'X from_state S1, X to_state S2 WHERE '
-                               'U login "admin", S1 name "activated", S2 name "deactivated"')[0][0]
+            eid = session.unsafe_execute(
+                'INSERT TrInfo X: X comment "zou", X wf_info_for U, X from_state S1, X to_state S2 '
+                'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0]
             trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x')
             trinfo.complete()
             self.failUnless(trinfo.relation_cached('from_state', 'subject'))
             self.failUnless(trinfo.relation_cached('to_state', 'subject'))
             self.failUnless(trinfo.relation_cached('wf_info_for', 'subject'))
             # check with a missing relation
-            eid = self.execute('INSERT TrInfo X: X comment "zou", X wf_info_for U,'
-                               'X to_state S2 WHERE '
-                               'U login "admin", S2 name "activated"')[0][0]
+            eid = session.unsafe_execute(
+                'INSERT TrInfo X: X comment "zou", X wf_info_for U,X to_state S2 '
+                'WHERE U login "admin", S2 name "activated"')[0][0]
             trinfo = self.entity('Any X WHERE X eid %(x)s', {'x': eid}, 'x')
             trinfo.complete()
             self.failUnless(isinstance(trinfo.creation_date, datetime))
--- a/test/unittest_rset.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_rset.py	Fri Aug 07 12:20:50 2009 +0200
@@ -346,10 +346,9 @@
                           set(['CWGroup',]))
 
     def test_printable_rql(self):
-        rset = self.execute(u'CWEType X WHERE X final FALSE, X meta FALSE')
+        rset = self.execute(u'CWEType X WHERE X final FALSE')
         self.assertEquals(rset.printable_rql(),
-                          'Any X WHERE X final FALSE, X meta FALSE, X is CWEType')
-
+                          'Any X WHERE X final FALSE, X is CWEType')
 
     def test_searched_text(self):
         rset = self.execute(u'Any X WHERE X has_text "foobar"')
--- a/test/unittest_rtags.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_rtags.py	Fri Aug 07 12:20:50 2009 +0200
@@ -39,7 +39,7 @@
 #             __rtags__ = {
 #                 ('evaluee', 'Note', 'subject') : set(('inlineview',)),
 #                 }
-#         self.vreg.register_vobject_class(Personne2)
+#         self.vreg.register_appobject_class(Personne2)
 #         rtags = Personne2.rtags
 #         self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('inlineview', 'link')))
 #         self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), True)
--- a/test/unittest_schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,6 +16,7 @@
 from yams import BadSchemaDefinition
 from yams.constraints import SizeConstraint, StaticVocabularyConstraint
 from yams.buildobjs import RelationDefinition, EntityType, RelationType
+from yams.reader import PyFileReader
 
 from cubicweb.schema import CubicWebSchema, CubicWebEntitySchema, \
      RQLConstraint, CubicWebSchemaLoader, ERQLExpression, RRQLExpression, \
@@ -133,12 +134,6 @@
 
 class SQLSchemaReaderClassTest(TestCase):
 
-    def test_knownValues_include_schema_files(self):
-        schema_files = loader.include_schema_files('Bookmark')
-        for file in schema_files:
-            self.assert_(isabs(file))
-        self.assertListEquals([basename(f) for f in schema_files], ['Bookmark.py'])
-
     def test_knownValues_load_schema(self):
         schema = loader.load(config)
         self.assert_(isinstance(schema, CubicWebSchema))
@@ -150,7 +145,7 @@
                              'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType',
                              'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation',
                              'CWPermission', 'CWProperty', 'CWRType', 'CWUser',
-                             'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
+                             'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
                              'Password', 'Personne',
                              'RQLExpression',
                              'Societe', 'State', 'String', 'SubNote', 'Tag', 'Time',
@@ -163,7 +158,7 @@
 
                               'cardinality', 'comment', 'comment_format',
                               'composite', 'condition', 'connait', 'constrained_by', 'content',
-                              'content_format', 'created_by', 'creation_date', 'cstrtype',
+                              'content_format', 'created_by', 'creation_date', 'cstrtype', 'cwuri',
 
                               'data', 'data_encoding', 'data_format', 'defaultval', 'delete_permission',
                               'description', 'description_format', 'destination_state',
@@ -179,7 +174,7 @@
 
                               'label', 'last_login_time', 'login',
 
-                              'mainvars', 'meta', 'modification_date',
+                              'mainvars', 'modification_date',
 
                               'name', 'nom',
 
@@ -193,7 +188,7 @@
 
                               'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type',
 
-                              'upassword', 'update_permission', 'use_email',
+                              'upassword', 'update_permission', 'uri', 'use_email',
 
                               'value',
 
@@ -203,7 +198,7 @@
 
         eschema = schema.eschema('CWUser')
         rels = sorted(str(r) for r in eschema.subject_relations())
-        self.assertListEquals(rels, ['created_by', 'creation_date', 'eid',
+        self.assertListEquals(rels, ['created_by', 'creation_date', 'cwuri', 'eid',
                                      'evaluee', 'firstname', 'has_text', 'identity',
                                      'in_group', 'in_state', 'is',
                                      'is_instance_of', 'last_login_time',
@@ -233,7 +228,7 @@
         self.loader = CubicWebSchemaLoader()
         self.loader.defined = {}
         self.loader.loaded_files = []
-        self.loader._instantiate_handlers()
+        self.loader._pyreader = PyFileReader(self.loader)
 
     def _test(self, schemafile, msg):
         self.loader.handle_file(join(DATADIR, schemafile))
--- a/test/unittest_selectors.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_selectors.py	Fri Aug 07 12:20:50 2009 +0200
@@ -9,7 +9,7 @@
 from logilab.common.testlib import TestCase, unittest_main
 
 from cubicweb.devtools.testlib import EnvBasedTC
-from cubicweb.vregistry import Selector, AndSelector, OrSelector
+from cubicweb.appobject import Selector, AndSelector, OrSelector
 from cubicweb.selectors import implements, match_user_groups
 from cubicweb.interfaces import IDownloadable
 from cubicweb.web import action
@@ -91,7 +91,7 @@
 class ImplementsSelectorTC(EnvBasedTC):
     def test_etype_priority(self):
         req = self.request()
-        cls = self.vreg.etype_class('File')
+        cls = self.vreg['etypes'].etype_class('File')
         anyscore = implements('Any').score_class(cls, req)
         idownscore = implements(IDownloadable).score_class(cls, req)
         self.failUnless(idownscore > anyscore, (idownscore, anyscore))
@@ -99,7 +99,7 @@
         self.failUnless(filescore > idownscore, (filescore, idownscore))
 
     def test_etype_inheritance_no_yams_inheritance(self):
-        cls = self.vreg.etype_class('Personne')
+        cls = self.vreg['etypes'].etype_class('Personne')
         self.failIf(implements('Societe').score_class(cls, self.request()))
 
 
@@ -111,7 +111,7 @@
             category = 'foo'
             __select__ = match_user_groups('owners')
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(SomeAction)
+        self.vreg.register_appobject_class(SomeAction)
         self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
         try:
             # login as a simple user
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unittest_spa2rql.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,180 @@
+from logilab.common.testlib import TestCase, unittest_main
+from cubicweb.devtools import TestServerConfiguration
+from cubicweb.xy import xy
+from cubicweb.spa2rql import Sparql2rqlTranslator
+
+xy.add_equivalence('Project', 'doap:Project')
+xy.add_equivalence('Project creation_date', 'doap:Project doap:created')
+xy.add_equivalence('Project name', 'doap:Project doap:name')
+
+
+config = TestServerConfiguration('data')
+config.bootstrap_cubes()
+schema = config.load_schema()
+
+
+class XYTC(TestCase):
+    def setUp(self):
+        self.tr = Sparql2rqlTranslator(schema)
+
+    def _test(self, sparql, rql, args={}):
+        qi = self.tr.translate(sparql)
+        self.assertEquals(qi.finalize(), (rql, args))
+
+    def XXX_test_base_01(self):
+        self._test('SELECT * WHERE { }', 'Any X')
+
+
+    def test_base_is(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?project
+    WHERE  {
+      ?project a doap:Project;
+    }''', 'Any PROJECT WHERE PROJECT is Project')
+
+
+    def test_base_attr_sel(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?created
+    WHERE  {
+      ?project a doap:Project;
+              doap:created ?created.
+    }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project')
+
+
+    def test_base_attr_sel_distinct(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT DISTINCT ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }''', 'DISTINCT Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
+
+    def test_base_attr_sel_reduced(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT REDUCED ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
+
+    def test_base_attr_sel_limit_offset(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }
+    LIMIT 20''', 'Any NAME LIMIT 20 WHERE PROJECT name NAME, PROJECT is Project')
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }
+    LIMIT 20 OFFSET 10''', 'Any NAME LIMIT 20 OFFSET 10 WHERE PROJECT name NAME, PROJECT is Project')
+
+
+    def test_base_attr_sel_orderby(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name;
+              doap:created ?created.
+    }
+    ORDER BY ?name DESC(?created)''', 'Any NAME ORDERBY NAME ASC, CREATED DESC WHERE PROJECT name NAME, PROJECT creation_date CREATED, PROJECT is Project')
+
+
+    def test_base_any_attr_sel(self):
+        self._test('''
+    PREFIX dc: <http://purl.org/dc/elements/1.1/>
+    SELECT ?x ?cd
+    WHERE  {
+      ?x dc:date ?cd;
+    }''', 'Any X, CD WHERE X creation_date CD')
+
+
+    def test_base_any_attr_sel_amb(self):
+        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+        try:
+            self._test('''
+    PREFIX dc: <http://purl.org/dc/elements/1.1/>
+    SELECT ?x ?cd
+    WHERE  {
+      ?x dc:date ?cd;
+    }''', '(Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version)')
+        finally:
+            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+    def test_base_any_attr_sel_amb_limit_offset(self):
+        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+        try:
+            self._test('''
+    PREFIX dc: <http://purl.org/dc/elements/1.1/>
+    SELECT ?x ?cd
+    WHERE  {
+      ?x dc:date ?cd;
+    }
+    LIMIT 20 OFFSET 10''', 'Any X, CD LIMIT 20 OFFSET 10 WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
+        finally:
+            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+    def test_base_any_attr_sel_amb_orderby(self):
+        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+        try:
+            self._test('''
+    PREFIX dc: <http://purl.org/dc/elements/1.1/>
+    SELECT ?x ?cd
+    WHERE  {
+      ?x dc:date ?cd;
+    }
+    ORDER BY DESC(?cd)''', 'Any X, CD ORDERBY CD DESC WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
+        finally:
+            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+    def test_restr_attr(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT ?project
+    WHERE  {
+      ?project a doap:Project;
+              doap:name "cubicweb".
+    }''', 'Any PROJECT WHERE PROJECT name %(a)s, PROJECT is Project', {'a': 'cubicweb'})
+
+# # Two elements in the group
+# PREFIX :  <http://example.org/ns#>
+# SELECT *
+# { :p :q :r  OPTIONAL { :a :b :c }
+#   :p :q :r  OPTIONAL { :a :b :c }
+# }
+
+# PREFIX : <http://example.org/ns#>
+# SELECT *
+# {
+#   { ?s ?p ?o } UNION { ?a ?b ?c }
+# }
+
+# PREFIX dob: <http://placetime.com/interval/gregorian/1977-01-18T04:00:00Z/P>
+# PREFIX time: <http://www.ai.sri.com/daml/ontologies/time/Time.daml#>
+# PREFIX dc: <http://purl.org/dc/elements/1.1/>
+# SELECT ?desc
+# WHERE  {
+#   dob:1D a time:ProperInterval;
+#          dc:description ?desc.
+# }
+
+if __name__ == '__main__':
+    unittest_main()
--- a/test/unittest_utils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_utils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,7 +8,7 @@
 
 from logilab.common.testlib import TestCase, unittest_main
 
-from cubicweb.common.utils import make_uid, UStringIO, SizeConstrainedList
+from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList
 
 
 class MakeUidTC(TestCase):
--- a/test/unittest_vregistry.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/test/unittest_vregistry.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,8 +10,8 @@
 from os.path import join
 
 from cubicweb import CW_SOFTWARE_ROOT as BASE
-from cubicweb.vregistry import VObject
-from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
+from cubicweb.appobject import AppObject
+from cubicweb.cwvreg import CubicWebVRegistry, UnknownProperty
 from cubicweb.devtools import TestServerConfiguration
 from cubicweb.interfaces import IMileStone
 
@@ -27,7 +27,7 @@
 
     def setUp(self):
         config = TestServerConfiguration('data')
-        self.vreg = CubicWebRegistry(config)
+        self.vreg = CubicWebVRegistry(config)
         config.bootstrap_cubes()
         self.vreg.schema = config.load_schema()
 
@@ -43,7 +43,7 @@
     def test___selectors__compat(self):
         myselector1 = lambda *args: 1
         myselector2 = lambda *args: 1
-        class AnAppObject(VObject):
+        class AnAppObject(AppObject):
             __selectors__ = (myselector1, myselector2)
         AnAppObject.build___select__()
         self.assertEquals(AnAppObject.__select__(AnAppObject), 2)
@@ -53,7 +53,7 @@
         self.failUnless(self.vreg.property_info('system.version.cubicweb'))
         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
 
-    def test_load_subinterface_based_vobjects(self):
+    def test_load_subinterface_based_appobjects(self):
         self.vreg.reset()
         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
         # check progressbar was kicked
@@ -62,7 +62,7 @@
             __implements__ = (IMileStone,)
         self.vreg.reset()
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(MyCard)
+        self.vreg.register_appobject_class(MyCard)
         self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
                                     join(BASE, 'web', 'views', 'iprogress.py')])
         # check progressbar isn't kicked
--- a/toolsutils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/toolsutils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,7 +16,7 @@
 from logilab.common.clcommands import Command as BaseCommand, \
      main_run as base_main_run
 from logilab.common.compat import any
-from logilab.common.shellutils import confirm
+from logilab.common.shellutils import ASK
 
 from cubicweb import warning
 from cubicweb import ConfigurationError, ExecutionError
@@ -72,7 +72,7 @@
         if askconfirm:
             print
             print diffs
-            action = raw_input('replace (N/y/q) ? ').lower()
+            action = ASK.ask('Replace ?', ('N','y','q'), 'N')
         else:
             action = 'y'
         if action == 'y':
@@ -117,7 +117,7 @@
             if fname.endswith('.tmpl'):
                 tfpath = tfpath[:-5]
                 if not askconfirm or not exists(tfpath) or \
-                       confirm('%s exists, overwrite?' % tfpath):
+                       ASK.confirm('%s exists, overwrite?' % tfpath):
                     fill_templated_file(fpath, tfpath, context)
                     print '[generate] %s <-- %s' % (tfpath, fpath)
             elif exists(tfpath):
@@ -140,7 +140,7 @@
     chmod(filepath, 0600)
 
 def read_config(config_file):
-    """read the application configuration from a file and return it as a
+    """read the instance configuration from a file and return it as a
     dictionnary
 
     :type config_file: str
--- a/utils.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/utils.py	Fri Aug 07 12:20:50 2009 +0200
@@ -255,10 +255,10 @@
         # 1/ variable declaration if any
         if self.jsvars:
             from simplejson import dumps
-            w(u'<script type="text/javascript">\n')
+            w(u'<script type="text/javascript"><!--//--><![CDATA[//><!--\n')
             for var, value in self.jsvars:
                 w(u'%s = %s;\n' % (var, dumps(value)))
-            w(u'</script>\n')
+            w(u'//--><!]]></script>\n')
         # 2/ css files
         for cssfile, media in self.cssfiles:
             w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
@@ -321,23 +321,8 @@
 
 
 class AcceptMixIn(object):
-    """Mixin class for vobjects defining the 'accepts' attribute describing
+    """Mixin class for appobjects defining the 'accepts' attribute describing
     a set of supported entity type (Any by default).
     """
     # 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/view.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/view.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,13 +11,14 @@
 
 from cStringIO import StringIO
 
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 from logilab.mtconverter import xml_escape
+from rql import nodes
 
 from cubicweb import NotAnEntity
 from cubicweb.selectors import yes, non_final_entity, nonempty_rset, none_rset
 from cubicweb.selectors import require_group_compat, accepts_compat
-from cubicweb.appobject import AppRsetObject
+from cubicweb.appobject import AppObject
 from cubicweb.utils import UStringIO, HTMLStream
 from cubicweb.schema import display_name
 
@@ -72,7 +73,7 @@
 
 # base view object ############################################################
 
-class View(AppRsetObject):
+class View(AppObject):
     """abstract view class, used as base for every renderable object such
     as views, templates, some components...web
 
@@ -92,7 +93,7 @@
     time to a write function to use.
     """
     __registry__ = 'views'
-    registered = require_group_compat(AppRsetObject.registered)
+    registered = require_group_compat(AppObject.registered)
 
     templatable = True
     need_navigation = True
@@ -150,7 +151,7 @@
         if stream is not None:
             return self._stream.getvalue()
 
-    dispatch = obsolete('.dispatch is deprecated, use .render')(render)
+    dispatch = deprecated('.dispatch is deprecated, use .render')(render)
 
     # should default .call() method add a <div classs="section"> around each
     # rset item
@@ -195,10 +196,27 @@
         necessary for non linkable views, but a default implementation
         is provided anyway.
         """
-        try:
-            return self.build_url(vid=self.id, rql=self.req.form['rql'])
-        except KeyError:
-            return self.build_url(vid=self.id)
+        rset = self.rset
+        if rset is None:
+            return self.build_url('view', vid=self.id)
+        coltypes = rset.column_types(0)
+        if len(coltypes) == 1:
+            etype = iter(coltypes).next()
+            if not self.schema.eschema(etype).is_final():
+                if len(rset) == 1:
+                    entity = rset.get_entity(0, 0)
+                    return entity.absolute_url(vid=self.id)
+            # don't want to generate /<etype> url if there is some restriction
+            # on something else than the entity type
+            restr = rset.syntax_tree().children[0].where
+            # XXX norestriction is not correct here. For instance, in cases like
+            # "Any P,N WHERE P is Project, P name N" norestriction should equal
+            # True
+            norestriction = (isinstance(restr, nodes.Relation) and
+                             restr.is_types_restriction())
+            if norestriction:
+                return self.build_url(etype.lower(), vid=self.id)
+        return self.build_url('view', rql=rset.printable_rql(), vid=self.id)
 
     def set_request_content_type(self):
         """set the content type returned by this view"""
@@ -212,7 +230,7 @@
         self.view(__vid, rset, __fallback_vid, w=self.w, **kwargs)
 
     # XXX Template bw compat
-    template = obsolete('.template is deprecated, use .view')(wview)
+    template = deprecated('.template is deprecated, use .view')(wview)
 
     def whead(self, data):
         self.req.html_headers.write(data)
@@ -313,10 +331,6 @@
 
     category = 'startupview'
 
-    def url(self):
-        """return the url associated with this view. We can omit rql here"""
-        return self.build_url('view', vid=self.id)
-
     def html_headers(self):
         """return a list of html headers (eg something to be inserted between
         <head> and </head> of the returned page
@@ -334,7 +348,7 @@
 
     default_rql = None
 
-    def __init__(self, req, rset, **kwargs):
+    def __init__(self, req, rset=None, **kwargs):
         super(EntityStartupView, self).__init__(req, rset, **kwargs)
         if rset is None:
             # this instance is not in the "entityview" category
@@ -354,14 +368,6 @@
         for i in xrange(len(rset)):
             self.wview(self.id, rset, row=i, **kwargs)
 
-    def url(self):
-        """return the url associated with this view. We can omit rql if we are
-        on a result set on which we do not apply.
-        """
-        if self.rset is None:
-            return self.build_url(vid=self.id)
-        return super(EntityStartupView, self).url()
-
 
 class AnyRsetView(View):
     """base class for views applying on any non empty result sets"""
--- a/vregistry.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/vregistry.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,13 +5,13 @@
   according to a context
 
 * to interact with the vregistry, objects should inherit from the
-  VObject abstract class
+  AppObject abstract class
 
 * the selection procedure has been generalized by delegating to a
-  selector, which is responsible to score the vobject according to the
+  selector, which is responsible to score the appobject according to the
   current state (req, rset, row, col). At the end of the selection, if
-  a vobject class has been found, an instance of this class is
-  returned. The selector is instantiated at vobject registration
+  a appobject class has been found, an instance of this class is
+  returned. The selector is instantiated at appobject registration
 
 
 :organization: Logilab
@@ -25,11 +25,15 @@
 from os import listdir, stat
 from os.path import dirname, join, realpath, split, isdir, exists
 from logging import getLogger
-import types
+from warnings import warn
+
+from logilab.common.deprecation import deprecated, class_moved
+from logilab.common.logging_ext import set_log_methods
 
-from cubicweb import CW_SOFTWARE_ROOT, set_log_methods
-from cubicweb import RegistryNotFound, ObjectNotFound, NoSelectableObject
-
+from cubicweb import CW_SOFTWARE_ROOT
+from cubicweb import (RegistryNotFound, ObjectNotFound, NoSelectableObject,
+                      RegistryOutOfDate)
+from cubicweb.appobject import AppObject
 
 def _toload_info(path, extrapath, _toload=None):
     """return a dictionary of <modname>: <modpath> and an ordered list of
@@ -50,144 +54,228 @@
     return _toload
 
 
-class VObject(object):
-    """visual object, use to be handled somehow by the visual components
-    registry.
+class Registry(dict):
+
+    def __init__(self, config):
+        super(Registry, self).__init__()
+        self.config = config
 
-    The following attributes should be set on concret vobject subclasses:
+    def __getitem__(self, name):
+        """return the registry (dictionary of class objects) associated to
+        this name
+        """
+        try:
+            return super(Registry, self).__getitem__(name)
+        except KeyError:
+            raise ObjectNotFound(name), None, sys.exc_info()[-1]
 
-    :__registry__:
-      name of the registry for this object (string like 'views',
-      'templates'...)
-    :id:
-      object's identifier in the registry (string like 'main',
-      'primary', 'folder_box')
-    :__select__:
-      class'selector
+    def register(self, obj, oid=None, clear=False):
+        """base method to add an object in the registry"""
+        assert not '__abstract__' in obj.__dict__
+        oid = oid or obj.id
+        assert oid
+        if clear:
+            appobjects = self[oid] =  []
+        else:
+            appobjects = self.setdefault(oid, [])
+        # registered() is technically a classmethod but is not declared
+        # as such because we need to compose registered in some cases
+        appobject = obj.registered.im_func(obj, self)
+        assert not appobject in appobjects, \
+               'object %s is already registered' % appobject
+        assert callable(appobject.__select__), appobject
+        appobjects.append(appobject)
 
-    Moreover, the `__abstract__` attribute may be set to True to indicate
-    that a vobject is abstract and should not be registered
-    """
-    # necessary attributes to interact with the registry
-    id = None
-    __registry__ = None
-    __select__ = None
+    def register_and_replace(self, obj, replaced):
+        # XXXFIXME this is a duplication of unregister()
+        # remove register_and_replace in favor of unregister + register
+        # or simplify by calling unregister then register here
+        if hasattr(replaced, 'classid'):
+            replaced = replaced.classid()
+        registered_objs = self.get(obj.id, ())
+        for index, registered in enumerate(registered_objs):
+            if registered.classid() == replaced:
+                del registered_objs[index]
+                break
+        else:
+            self.warning('trying to replace an unregistered view %s by %s',
+                         replaced, obj)
+        self.register(obj)
 
-    @classmethod
-    def registered(cls, registry):
-        """called by the registry when the vobject has been registered.
+    def unregister(self, obj):
+        oid = obj.classid()
+        for registered in self.get(obj.id, ()):
+            # use classid() to compare classes because vreg will probably
+            # have its own version of the class, loaded through execfile
+            if registered.classid() == oid:
+                # XXX automatic reloading management
+                self[obj.id].remove(registered)
+                break
+        else:
+            self.warning('can\'t remove %s, no id %s in the registry',
+                         oid, obj.id)
 
-        It must return the  object that will be actually registered (this
-        may be the right hook to create an instance for example). By
-        default the vobject is returned without any transformation.
+    def all_objects(self):
+        """return a list containing all objects in this registry.
         """
-        cls.build___select__()
-        return cls
+        result = []
+        for objs in self.values():
+            result += objs
+        return result
 
-    @classmethod
-    def selected(cls, *args, **kwargs):
-        """called by the registry when the vobject has been selected.
+    # dynamic selection methods ################################################
+
+    def object_by_id(self, oid, *args, **kwargs):
+        """return object with the given oid. Only one object is expected to be
+        found.
+
+        raise `ObjectNotFound` if not object with id <oid> in <registry>
+        raise `AssertionError` if there is more than one object there
+        """
+        objects = self[oid]
+        assert len(objects) == 1, objects
+        return objects[0](*args, **kwargs)
 
-        It must return the  object that will be actually returned by the
-        .select method (this may be the right hook to create an
-        instance for example). By default the selected object is
-        returned without any transformation.
+    def select(self, oid, *args, **kwargs):
+        """return the most specific object among those with the given oid
+        according to the given context.
+
+        raise `ObjectNotFound` if not object with id <oid> in <registry>
+        raise `NoSelectableObject` if not object apply
         """
-        return cls
+        return self.select_best(self[oid], *args, **kwargs)
 
-    @classmethod
-    def classid(cls):
-        """returns a unique identifier for the vobject"""
-        return '%s.%s' % (cls.__module__, cls.__name__)
+    def select_object(self, oid, *args, **kwargs):
+        """return the most specific object among those with the given oid
+        according to the given context, or None if no object applies.
+        """
+        try:
+            return self.select(oid, *args, **kwargs)
+        except (NoSelectableObject, ObjectNotFound):
+            return None
 
-    # XXX bw compat code
-    @classmethod
-    def build___select__(cls):
-        for klass in cls.mro():
-            if klass.__name__ == 'AppRsetObject':
-                continue # the bw compat __selector__ is there
-            klassdict = klass.__dict__
-            if ('__select__' in klassdict and '__selectors__' in klassdict
-                and '__selgenerated__' not in klassdict):
-                raise TypeError("__select__ and __selectors__ can't be used together on class %s" % cls)
-            if '__selectors__' in klassdict and '__selgenerated__' not in klassdict:
-                cls.__selgenerated__ = True
-                # case where __selectors__ is defined locally (but __select__
-                # is in a parent class)
-                selectors = klassdict['__selectors__']
-                if len(selectors) == 1:
-                    # micro optimization: don't bother with AndSelector if there's
-                    # only one selector
-                    select = _instantiate_selector(selectors[0])
-                else:
-                    select = AndSelector(*selectors)
-                cls.__select__ = select
+    def possible_objects(self, *args, **kwargs):
+        """return an iterator on possible objects in this registry for the given
+        context
+        """
+        for appobjects in self.itervalues():
+            try:
+                yield self.select_best(appobjects, *args, **kwargs)
+            except NoSelectableObject:
+                continue
+
+    def select_best(self, appobjects, *args, **kwargs):
+        """return an instance of the most specific object according
+        to parameters
+
+        raise `NoSelectableObject` if not object apply
+        """
+        if len(args) > 1:
+            warn('only the request param can not be named when calling select',
+                 DeprecationWarning, stacklevel=3)
+        score, winners = 0, []
+        for appobject in appobjects:
+            appobjectscore = appobject.__select__(appobject, *args, **kwargs)
+            if appobjectscore > score:
+                score, winners = appobjectscore, [appobject]
+            elif appobjectscore > 0 and appobjectscore == score:
+                winners.append(appobject)
+        if not winners:
+            raise NoSelectableObject('args: %s\nkwargs: %s %s'
+                                     % (args, kwargs.keys(),
+                                        [repr(v) for v in appobjects]))
+        if len(winners) > 1:
+            if self.config.mode == 'installed':
+                self.error('select ambiguity, args: %s\nkwargs: %s %s',
+                           args, kwargs.keys(), [repr(v) for v in winners])
+            else:
+                raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
+                                % (args, kwargs.keys(),
+                                   [repr(v) for v in winners]))
+        # return the result of calling the appobject
+        return winners[0](*args, **kwargs)
 
 
-class VRegistry(object):
+class VRegistry(dict):
     """class responsible to register, propose and select the various
     elements used to build the web interface. Currently, we have templates,
     views, actions and components.
     """
 
-    def __init__(self, config):#, cache_size=1000):
+    def __init__(self, config):
+        super(VRegistry, self).__init__()
         self.config = config
-        # dictionnary of registry (themself dictionnary) by name
-        self._registries = {}
-        self._lastmodifs = {}
 
-    def reset(self):
-        self._registries = {}
+    def reset(self, force_reload=None):
+        self.clear()
         self._lastmodifs = {}
 
-    def __getitem__(self, key):
-        return self._registries[key]
-
-    def get(self, key, default=None):
-        return self._registries.get(key, default)
-
-    def items(self):
-        return self._registries.items()
-
-    def values(self):
-        return self._registries.values()
-
-    def __contains__(self, key):
-        return key in self._registries
-
-    def registry(self, name):
+    def __getitem__(self, name):
         """return the registry (dictionary of class objects) associated to
         this name
         """
         try:
-            return self._registries[name]
+            return super(VRegistry, self).__getitem__(name)
         except KeyError:
             raise RegistryNotFound(name), None, sys.exc_info()[-1]
 
-    def registry_objects(self, name, oid=None):
-        """returns objects registered with the given oid in the given registry.
-        If no oid is given, return all objects in this registry
+    # dynamic selection methods ################################################
+
+    @deprecated('use vreg[registry].object_by_id(oid, *args, **kwargs)')
+    def object_by_id(self, registry, oid, *args, **kwargs):
+        """return object in <registry>.<oid>
+
+        raise `ObjectNotFound` if not object with id <oid> in <registry>
+        raise `AssertionError` if there is more than one object there
         """
-        registry = self.registry(name)
-        if oid:
-            try:
-                return registry[oid]
-            except KeyError:
-                raise ObjectNotFound(oid), None, sys.exc_info()[-1]
-        else:
-            result = []
-            for objs in registry.values():
-                result += objs
-            return result
+        return self[registry].object_by_id(oid)
+
+    @deprecated('use vreg[registry].select(oid, *args, **kwargs)')
+    def select(self, registry, oid, *args, **kwargs):
+        """return the most specific object in <registry>.<oid> according to
+        the given context
+
+        raise `ObjectNotFound` if not object with id <oid> in <registry>
+        raise `NoSelectableObject` if not object apply
+        """
+        return self[registry].select(oid, *args, **kwargs)
 
-    def object_by_id(self, registry, cid, *args, **kwargs):
-        """return the most specific component according to the resultset"""
-        objects = self[registry][cid]
-        assert len(objects) == 1, objects
-        return objects[0].selected(*args, **kwargs)
+    @deprecated('use vreg[registry].select_object(oid, *args, **kwargs)')
+    def select_object(self, registry, oid, *args, **kwargs):
+        """return the most specific object in <registry>.<oid> according to
+        the given context, or None if no object apply
+        """
+        return self[registry].select_object(oid, *args, **kwargs)
+
+    @deprecated('use vreg[registry].possible_objects(*args, **kwargs)')
+    def possible_objects(self, registry, *args, **kwargs):
+        """return an iterator on possible objects in <registry> for the given
+        context
+        """
+        return self[registry].possible_objects(*args, **kwargs)
 
     # methods for explicit (un)registration ###################################
 
+    # default class, when no specific class set
+    REGISTRY_FACTORY = {None: Registry}
+
+    def registry_class(self, regid):
+        try:
+            return self.REGISTRY_FACTORY[regid]
+        except KeyError:
+            return self.REGISTRY_FACTORY[None]
+
+    def setdefault(self, regid):
+        try:
+            return self[regid]
+        except KeyError:
+            self[regid] = self.registry_class(regid)(self.config)
+            return self[regid]
+
+#     def clear(self, key):
+#         regname, oid = key.split('.')
+#         self[regname].pop(oid, None)
+
     def register_all(self, objects, modname, butclasses=()):
         for obj in objects:
             try:
@@ -203,113 +291,30 @@
         """base method to add an object in the registry"""
         assert not '__abstract__' in obj.__dict__
         registryname = registryname or obj.__registry__
-        oid = oid or obj.id
-        assert oid
-        registry = self._registries.setdefault(registryname, {})
-        if clear:
-            vobjects = registry[oid] =  []
-        else:
-            vobjects = registry.setdefault(oid, [])
-        # registered() is technically a classmethod but is not declared
-        # as such because we need to compose registered in some cases
-        vobject = obj.registered.im_func(obj, self)
-        assert not vobject in vobjects, \
-               'object %s is already registered' % vobject
-        assert callable(vobject.__select__), vobject
-        vobjects.append(vobject)
+        registry = self.setdefault(registryname)
+        registry.register(obj, oid=oid, clear=clear)
         try:
-            vname = vobject.__name__
+            vname = obj.__name__
         except AttributeError:
-            vname = vobject.__class__.__name__
-        self.debug('registered vobject %s in registry %s with id %s',
+            vname = obj.__class__.__name__
+        self.debug('registered appobject %s in registry %s with id %s',
                    vname, registryname, oid)
-        # automatic reloading management
         self._loadedmods[obj.__module__]['%s.%s' % (obj.__module__, oid)] = obj
 
     def unregister(self, obj, registryname=None):
-        registryname = registryname or obj.__registry__
-        registry = self.registry(registryname)
-        removed_id = obj.classid()
-        for registered in registry.get(obj.id, ()):
-            # use classid() to compare classes because vreg will probably
-            # have its own version of the class, loaded through execfile
-            if registered.classid() == removed_id:
-                # XXX automatic reloading management
-                registry[obj.id].remove(registered)
-                break
-        else:
-            self.warning('can\'t remove %s, no id %s in the %s registry',
-                         removed_id, obj.id, registryname)
+        self[registryname or obj.__registry__].unregister(obj)
 
     def register_and_replace(self, obj, replaced, registryname=None):
-        # XXXFIXME this is a duplication of unregister()
-        # remove register_and_replace in favor of unregister + register
-        # or simplify by calling unregister then register here
-        if hasattr(replaced, 'classid'):
-            replaced = replaced.classid()
-        registryname = registryname or obj.__registry__
-        registry = self.registry(registryname)
-        registered_objs = registry.get(obj.id, ())
-        for index, registered in enumerate(registered_objs):
-            if registered.classid() == replaced:
-                del registry[obj.id][index]
-                break
-        else:
-            self.warning('trying to replace an unregistered view %s by %s',
-                         replaced, obj)
-        self.register(obj, registryname=registryname)
-
-    # dynamic selection methods ###############################################
-
-    def select(self, vobjects, *args, **kwargs):
-        """return an instance of the most specific object according
-        to parameters
+        self[registryname or obj.__registry__].register_and_replace(obj, replaced)
 
-        raise NoSelectableObject if not object apply
-        """
-        score, winners = 0, []
-        for vobject in vobjects:
-            vobjectscore = vobject.__select__(vobject, *args, **kwargs)
-            if vobjectscore > score:
-                score, winners = vobjectscore, [vobject]
-            elif vobjectscore > 0 and vobjectscore == score:
-                winners.append(vobject)
-        if not winners:
-            raise NoSelectableObject('args: %s\nkwargs: %s %s'
-                                     % (args, kwargs.keys(),
-                                        [repr(v) for v in vobjects]))
-        if len(winners) > 1:
-            if self.config.mode == 'installed':
-                self.error('select ambiguity, args: %s\nkwargs: %s %s',
-                           args, kwargs.keys(), [repr(v) for v in winners])
-            else:
-                raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
-                                % (args, kwargs.keys(),
-                                   [repr(v) for v in winners]))
-        winner = winners[0]
-        # return the result of the .selected method of the vobject
-        return winner.selected(*args, **kwargs)
-
-    def possible_objects(self, registry, *args, **kwargs):
-        """return an iterator on possible objects in a registry for this result set
-
-        actions returned are classes, not instances
-        """
-        for vobjects in self.registry(registry).values():
-            try:
-                yield self.select(vobjects, *args, **kwargs)
-            except NoSelectableObject:
-                continue
-
-    def select_object(self, registry, cid, *args, **kwargs):
-        """return the most specific component according to the resultset"""
-        return self.select(self.registry_objects(registry, cid), *args, **kwargs)
-
-    # intialization methods ###################################################
+    # initialization methods ###################################################
 
     def init_registration(self, path, extrapath=None):
         # compute list of all modules that have to be loaded
         self._toloadmods, filemods = _toload_info(path, extrapath)
+        # XXX is _loadedmods still necessary ? It seems like it's useful
+        #     to avoid loading same module twice, especially with the
+        #     _load_ancestors_then_object logic but this needs to be checked
         self._loadedmods = {}
         return filemods
 
@@ -332,7 +337,7 @@
                 sys.path.remove(webdir)
         if CW_SOFTWARE_ROOT in sys.path:
             sys.path.remove(CW_SOFTWARE_ROOT)
-        # load views from each directory in the application's path
+        # load views from each directory in the instance's path
         filemods = self.init_registration(path, extrapath)
         change = False
         for filepath, modname in filemods:
@@ -341,7 +346,7 @@
         return change
 
     def load_file(self, filepath, modname, force_reload=False):
-        """load visual objects from a python file"""
+        """load app objects from a python file"""
         from logilab.common.modutils import load_module_from_name
         if modname in self._loadedmods:
             return
@@ -357,22 +362,12 @@
             # only load file if it was modified
             if modified_on <= self._lastmodifs[filepath]:
                 return
-            # if it was modified, unregister all exisiting objects
-            # from this module, and keep track of what was unregistered
-            unregistered = self.unregister_module_vobjects(modname)
-        else:
-            unregistered = None
+            # if it was modified, raise RegistryOutOfDate to reload everything
+            self.info('File %s changed since last visit', filepath)
+            raise RegistryOutOfDate()
         # load the module
         module = load_module_from_name(modname, use_sys=not force_reload)
         self.load_module(module)
-        # if something was unregistered, we need to update places where it was
-        # referenced
-        if unregistered:
-            # oldnew_mapping = {}
-            registered = self._loadedmods[modname]
-            oldnew_mapping = dict((unregistered[name], registered[name])
-                                  for name in unregistered if name in registered)
-            self.update_registered_subclasses(oldnew_mapping)
         self._lastmodifs[filepath] = modified_on
         return True
 
@@ -396,7 +391,7 @@
             return
         # skip non registerable object
         try:
-            if not issubclass(obj, VObject):
+            if not issubclass(obj, AppObject):
                 return
         except TypeError:
             return
@@ -410,20 +405,20 @@
 
     def load_object(self, obj):
         try:
-            self.register_vobject_class(obj)
+            self.register_appobject_class(obj)
         except Exception, ex:
             if self.config.mode in ('test', 'dev'):
                 raise
-            self.exception('vobject %s registration failed: %s', obj, ex)
+            self.exception('appobject %s registration failed: %s', obj, ex)
 
     # old automatic registration XXX deprecated ###############################
 
-    def register_vobject_class(self, cls):
-        """handle vobject class registration
+    def register_appobject_class(self, cls):
+        """handle appobject class registration
 
-        vobject class with __abstract__ == True in their local dictionnary or
+        appobject class with __abstract__ == True in their local dictionnary or
         with a name starting starting by an underscore are not registered.
-        Also a vobject class needs to have __registry__ and id attributes set
+        Also a appobject class needs to have __registry__ and id attributes set
         to a non empty string to be registered.
         """
         if (cls.__dict__.get('__abstract__') or cls.__name__[0] == '_'
@@ -434,232 +429,20 @@
             return
         self.register(cls)
 
-    def unregister_module_vobjects(self, modname):
-        """removes registered objects coming from a given module
-
-        returns a dictionnary classid/class of all classes that will need
-        to be updated after reload (i.e. vobjects referencing classes defined
-        in the <modname> module)
-        """
-        unregistered = {}
-        # browse each registered object
-        for registry, objdict in self.items():
-            for oid, objects in objdict.items():
-                for obj in objects[:]:
-                    objname = obj.classid()
-                    # if the vobject is defined in this module, remove it
-                    if objname.startswith(modname):
-                        unregistered[objname] = obj
-                        objects.remove(obj)
-                        self.debug('unregistering %s in %s registry',
-                                  objname, registry)
-                    # if not, check if the vobject can be found in baseclasses
-                    # (because we also want subclasses to be updated)
-                    else:
-                        if not isinstance(obj, type):
-                            obj = obj.__class__
-                        for baseclass in obj.__bases__:
-                            if hasattr(baseclass, 'classid'):
-                                baseclassid = baseclass.classid()
-                                if baseclassid.startswith(modname):
-                                    unregistered[baseclassid] = baseclass
-                # update oid entry
-                if objects:
-                    objdict[oid] = objects
-                else:
-                    del objdict[oid]
-        return unregistered
-
-    def update_registered_subclasses(self, oldnew_mapping):
-        """updates subclasses of re-registered vobjects
-
-        if baseviews.PrimaryView is changed, baseviews.py will be reloaded
-        automatically and the new version of PrimaryView will be registered.
-        But all existing subclasses must also be notified of this change, and
-        that's what this method does
-
-        :param oldnew_mapping: a dict mapping old version of a class to
-                               the new version
-        """
-        # browse each registered object
-        for objdict in self.values():
-            for objects in objdict.values():
-                for obj in objects:
-                    if not isinstance(obj, type):
-                        obj = obj.__class__
-                    # build new baseclasses tuple
-                    newbases = tuple(oldnew_mapping.get(baseclass, baseclass)
-                                     for baseclass in obj.__bases__)
-                    # update obj's baseclasses tuple (__bases__) if needed
-                    if newbases != obj.__bases__:
-                        self.debug('updating %s.%s base classes',
-                                  obj.__module__, obj.__name__)
-                        obj.__bases__ = newbases
-
 # init logging
-set_log_methods(VObject, getLogger('cubicweb'))
-set_log_methods(VRegistry, getLogger('cubicweb.registry'))
-
-
-# selector base classes and operations ########################################
-
-class Selector(object):
-    """base class for selector classes providing implementation
-    for operators ``&`` and ``|``
-
-    This class is only here to give access to binary operators, the
-    selector logic itself should be implemented in the __call__ method
-
-
-    a selector is called to help choosing the correct object for a
-    particular context by returning a score (`int`) telling how well
-    the class given as first argument apply to the given context.
-
-    0 score means that the class doesn't apply.
-    """
-
-    @property
-    def func_name(self):
-        # backward compatibility
-        return self.__class__.__name__
-
-    def search_selector(self, selector):
-        """search for the given selector or selector instance in the selectors
-        tree. Return it of None if not found
-        """
-        if self is selector:
-            return self
-        if isinstance(selector, type) and isinstance(self, selector):
-            return self
-        return None
-
-    def __str__(self):
-        return self.__class__.__name__
-
-    def __and__(self, other):
-        return AndSelector(self, other)
-    def __rand__(self, other):
-        return AndSelector(other, self)
-
-    def __or__(self, other):
-        return OrSelector(self, other)
-    def __ror__(self, other):
-        return OrSelector(other, self)
-
-    def __invert__(self):
-        return NotSelector(self)
-
-    # XXX (function | function) or (function & function) not managed yet
-
-    def __call__(self, cls, *args, **kwargs):
-        return NotImplementedError("selector %s must implement its logic "
-                                   "in its __call__ method" % self.__class__)
-
-class MultiSelector(Selector):
-    """base class for compound selector classes"""
-
-    def __init__(self, *selectors):
-        self.selectors = self.merge_selectors(selectors)
-
-    def __str__(self):
-        return '%s(%s)' % (self.__class__.__name__,
-                           ','.join(str(s) for s in self.selectors))
-
-    @classmethod
-    def merge_selectors(cls, selectors):
-        """deal with selector instanciation when necessary and merge
-        multi-selectors if possible:
-
-        AndSelector(AndSelector(sel1, sel2), AndSelector(sel3, sel4))
-        ==> AndSelector(sel1, sel2, sel3, sel4)
-        """
-        merged_selectors = []
-        for selector in selectors:
-            try:
-                selector = _instantiate_selector(selector)
-            except:
-                pass
-            #assert isinstance(selector, Selector), selector
-            if isinstance(selector, cls):
-                merged_selectors += selector.selectors
-            else:
-                merged_selectors.append(selector)
-        return merged_selectors
-
-    def search_selector(self, selector):
-        """search for the given selector or selector instance in the selectors
-        tree. Return it of None if not found
-        """
-        for childselector in self.selectors:
-            if childselector is selector:
-                return childselector
-            found = childselector.search_selector(selector)
-            if found is not None:
-                return found
-        return None
-
-
-def objectify_selector(selector_func):
-    """convenience decorator for simple selectors where a class definition
-    would be overkill::
-
-        @objectify_selector
-        def yes(cls, *args, **kwargs):
-            return 1
-
-    """
-    return type(selector_func.__name__, (Selector,),
-                {'__call__': lambda self, *args, **kwargs: selector_func(*args, **kwargs)})
-
-def _instantiate_selector(selector):
-    """ensures `selector` is a `Selector` instance
-
-    NOTE: This should only be used locally in build___select__()
-    XXX: then, why not do it ??
-    """
-    if isinstance(selector, types.FunctionType):
-        return objectify_selector(selector)()
-    if isinstance(selector, type) and issubclass(selector, Selector):
-        return selector()
-    return selector
-
-
-class AndSelector(MultiSelector):
-    """and-chained selectors (formerly known as chainall)"""
-    def __call__(self, cls, *args, **kwargs):
-        score = 0
-        for selector in self.selectors:
-            partscore = selector(cls, *args, **kwargs)
-            if not partscore:
-                return 0
-            score += partscore
-        return score
-
-
-class OrSelector(MultiSelector):
-    """or-chained selectors (formerly known as chainfirst)"""
-    def __call__(self, cls, *args, **kwargs):
-        for selector in self.selectors:
-            partscore = selector(cls, *args, **kwargs)
-            if partscore:
-                return partscore
-        return 0
-
-class NotSelector(Selector):
-    """negation selector"""
-    def __init__(self, selector):
-        self.selector = selector
-
-    def __call__(self, cls, *args, **kwargs):
-        score = self.selector(cls, *args, **kwargs)
-        return int(not score)
-
-    def __str__(self):
-        return 'NOT(%s)' % super(NotSelector, self).__str__()
+set_log_methods(VRegistry, getLogger('cubicweb.vreg'))
+set_log_methods(Registry, getLogger('cubicweb.registry'))
 
 
 # XXX bw compat functions #####################################################
 
+from cubicweb.appobject import objectify_selector, AndSelector, OrSelector, Selector
+
+objectify_selector = deprecated('objectify_selector has been moved to appobject module')(objectify_selector)
+
+Selector = class_moved(Selector)
+
+@deprecated('use & operator (binary and)')
 def chainall(*selectors, **kwargs):
     """return a selector chaining given selectors. If one of
     the selectors fail, selection will fail, else the returned score
@@ -672,6 +455,7 @@
         selector.__name__ = kwargs['name']
     return selector
 
+@deprecated('use | operator (binary or)')
 def chainfirst(*selectors, **kwargs):
     """return a selector chaining given selectors. If all
     the selectors fail, selection will fail, else the returned score
--- a/web/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 from datetime import datetime, date, timedelta
 from simplejson import dumps
 
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 
 from cubicweb.common.uilib import urlquote
 from cubicweb.web._exceptions import *
@@ -65,7 +65,7 @@
         return json_dumps(function(*args, **kwargs))
     return newfunc
 
-@obsolete('use req.build_ajax_replace_url() instead')
+@deprecated('use req.build_ajax_replace_url() instead')
 def ajax_replace_url(nodeid, rql, vid=None, swap=False, **extraparams):
     """builds a replacePageChunk-like url
     >>> ajax_replace_url('foo', 'Person P')
--- a/web/action.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/action.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,17 +6,16 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from cubicweb import target
 from cubicweb.selectors import (partial_relation_possible, match_search_state,
                                 one_line_rset, partial_may_add_relation, yes,
                                 accepts_compat, condition_compat, deprecate)
-from cubicweb.appobject import AppRsetObject
-
-_ = unicode
+from cubicweb.appobject import AppObject
 
 
-class Action(AppRsetObject):
+class Action(AppObject):
     """abstract action. Handle the .search_states attribute to match
     request search state.
     """
--- a/web/application.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/application.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,22 +10,24 @@
 import sys
 from time import clock, time
 
+from logilab.common.deprecation import deprecated
+
 from rql import BadRQLQuery
 
-from cubicweb import set_log_methods
-from cubicweb import (ValidationError, Unauthorized, AuthenticationError,
-                      NoSelectableObject, RepositoryError)
-from cubicweb.cwvreg import CubicWebRegistry
-from cubicweb.web import (LOGGER, StatusResponse, DirectResponse, Redirect,
-                          NotFound, RemoteCallFailed, ExplicitLogin,
-                          InvalidSession, RequestError)
-from cubicweb.web.component import Component
+from cubicweb import set_log_methods, cwvreg
+from cubicweb import (
+    ValidationError, Unauthorized, AuthenticationError, NoSelectableObject,
+    RepositoryError, CW_EVENT_MANAGER)
+from cubicweb.web import LOGGER, component
+from cubicweb.web import (
+    StatusResponse, DirectResponse, Redirect, NotFound,
+    RemoteCallFailed, ExplicitLogin, InvalidSession, RequestError)
 
 # make session manager available through a global variable so the debug view can
 # print information about web session
 SESSION_MANAGER = None
 
-class AbstractSessionManager(Component):
+class AbstractSessionManager(component.Component):
     """manage session data associated to a session identifier"""
     id = 'sessionmanager'
 
@@ -39,8 +41,11 @@
         if self.session_time:
             assert self.cleanup_session_time < self.session_time
             assert self.cleanup_anon_session_time < self.session_time
-        self.authmanager = self.vreg.select_component('authmanager')
-        assert self.authmanager, 'no authentication manager found'
+        self.set_authmanager()
+        CW_EVENT_MANAGER.bind('after-registry-reload', self.set_authmanager)
+
+    def set_authmanager(self):
+        self.authmanager = self.vreg['components'].select('authmanager')
 
     def clean_sessions(self):
         """cleanup sessions which has not been unused since a given amount of
@@ -88,7 +93,7 @@
         raise NotImplementedError()
 
 
-class AbstractAuthenticationManager(Component):
+class AbstractAuthenticationManager(component.Component):
     """authenticate user associated to a request and check session validity"""
     id = 'authmanager'
 
@@ -111,12 +116,20 @@
     SESSION_VAR = '__session'
 
     def __init__(self, appli):
-        self.session_manager = appli.vreg.select_component('sessionmanager')
-        assert self.session_manager, 'no session manager found'
+        self.vreg = appli.vreg
+        self.session_manager = self.vreg['components'].select('sessionmanager')
         global SESSION_MANAGER
         SESSION_MANAGER = self.session_manager
-        if not 'last_login_time' in appli.vreg.schema:
+        if not 'last_login_time' in self.vreg.schema:
             self._update_last_login_time = lambda x: None
+        CW_EVENT_MANAGER.bind('after-registry-reload', self.reset_session_manager)
+
+    def reset_session_manager(self):
+        data = self.session_manager.dump_data()
+        self.session_manager = self.vreg['components'].select('sessionmanager')
+        self.session_manager.restore_data(data)
+        global SESSION_MANAGER
+        SESSION_MANAGER = self.session_manager
 
     def clean_sessions(self):
         """cleanup sessions which has not been unused since a given amount of
@@ -201,7 +214,7 @@
         raise Redirect(req.build_url(path, **args))
 
     def logout(self, req):
-        """logout from the application by cleaning the session and raising
+        """logout from the instance by cleaning the session and raising
         `AuthenticationError`
         """
         self.session_manager.close_session(req.cnx)
@@ -210,31 +223,19 @@
 
 
 class CubicWebPublisher(object):
-    """Central registry for the web application. This is one of the central
-    object in the web application, coupling dynamically loaded objects with
-    the application's schema and the application's configuration objects.
-
-    It specializes the VRegistry by adding some convenience methods to
-    access to stored objects. Currently we have the following registries
-    of objects known by the web application (library may use some others
-    additional registries):
-    * controllers, which are directly plugged into the application
-      object to handle request publishing
-    * views
-    * templates
-    * components
-    * actions
+    """the publisher is a singleton hold by the web frontend, and is responsible
+    to publish HTTP request.
     """
 
     def __init__(self, config, debug=None,
                  session_handler_fact=CookieSessionHandler,
                  vreg=None):
         super(CubicWebPublisher, self).__init__()
-        # connect to the repository and get application's schema
+        # connect to the repository and get instance's schema
         if vreg is None:
-            vreg = CubicWebRegistry(config, debug=debug)
+            vreg = cwvreg.CubicWebVRegistry(config, debug=debug)
         self.vreg = vreg
-        self.info('starting web application from %s', config.apphome)
+        self.info('starting web instance from %s', config.apphome)
         self.repo = config.repository(vreg)
         if not vreg.initialized:
             self.config.init_cubes(self.repo.get_cubes())
@@ -251,7 +252,11 @@
             self.publish = self.main_publish
         # instantiate session and url resolving helpers
         self.session_handler = session_handler_fact(self)
-        self.url_resolver = vreg.select_component('urlpublisher')
+        self.set_urlresolver()
+        CW_EVENT_MANAGER.bind('after-registry-reload', self.set_urlresolver)
+
+    def set_urlresolver(self):
+        self.url_resolver = self.vreg['components'].select('urlpublisher')
 
     def connect(self, req):
         """return a connection for a logged user object according to existing
@@ -260,15 +265,6 @@
         """
         self.session_handler.set_session(req)
 
-    def select_controller(self, oid, req):
-        """return the most specific view according to the resultset"""
-        vreg = self.vreg
-        try:
-            return vreg.select(vreg.registry_objects('controllers', oid),
-                               req=req, appli=self)
-        except NoSelectableObject:
-            raise Unauthorized(req._('not authorized'))
-
     # publish methods #########################################################
 
     def log_publish(self, path, req):
@@ -293,6 +289,13 @@
             finally:
                 self._logfile_lock.release()
 
+    @deprecated("use vreg.select('controllers', ...)")
+    def select_controller(self, oid, req):
+        try:
+            return self.vreg['controllers'].select(oid, req=req, appli=self)
+        except NoSelectableObject:
+            raise Unauthorized(req._('not authorized'))
+
     def main_publish(self, path, req):
         """method called by the main publisher to process <path>
 
@@ -317,7 +320,11 @@
         try:
             try:
                 ctrlid, rset = self.url_resolver.process(req, path)
-                controller = self.select_controller(ctrlid, req)
+                try:
+                    controller = self.vreg['controllers'].select(ctrlid, req,
+                                                                 appli=self)
+                except NoSelectableObject:
+                    raise Unauthorized(req._('not authorized'))
                 req.update_search_state()
                 result = controller.publish(rset=rset)
                 if req.cnx is not None:
@@ -385,28 +392,28 @@
             if tb:
                 req.data['excinfo'] = excinfo
             req.form['vid'] = 'error'
-            errview = self.vreg.select_view('error', req, None)
+            errview = self.vreg['views'].select('error', req)
             template = self.main_template_id(req)
-            content = self.vreg.main_template(req, template, view=errview)
+            content = self.vreg['views'].main_template(req, template, view=errview)
         except:
-            content = self.vreg.main_template(req, 'error-template')
+            content = self.vreg['views'].main_template(req, 'error-template')
         raise StatusResponse(500, content)
 
     def need_login_content(self, req):
-        return self.vreg.main_template(req, 'login')
+        return self.vreg['views'].main_template(req, 'login')
 
     def loggedout_content(self, req):
-        return self.vreg.main_template(req, 'loggedout')
+        return self.vreg['views'].main_template(req, 'loggedout')
 
     def notfound_content(self, req):
         req.form['vid'] = '404'
-        view = self.vreg.select_view('404', req, None)
+        view = self.vreg['views'].select('404', req)
         template = self.main_template_id(req)
-        return self.vreg.main_template(req, template, view=view)
+        return self.vreg['views'].main_template(req, template, view=view)
 
     def main_template_id(self, req):
         template = req.form.get('__template', req.property_value('ui.main-template'))
-        if template not in self.vreg.registry('views'):
+        if template not in self.vreg['views']:
             template = 'main-template'
         return template
 
--- a/web/box.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/box.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,6 +11,7 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import Unauthorized, role as get_role, target as get_target
+from cubicweb.schema import display_name
 from cubicweb.selectors import (one_line_rset,  primary_view,
                                 match_context_prop, partial_has_related_entities,
                                 accepts_compat, has_relation_compat,
@@ -219,8 +220,8 @@
             return entity.unrelated(self.rtype, self.etype, get_role(self)).entities()
         # in other cases, use vocabulary functions
         entities = []
-        form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
-                                       row=self.row or 0)
+        form = self.vreg['forms'].select('edition', self.req, rset=self.rset,
+                                         row=self.row or 0)
         field = form.field_by_name(self.rtype, get_role(self), entity.e_schema)
         for _, eid in form.form_field_vocabulary(field):
             if eid is not None:
--- a/web/controller.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/controller.py	Fri Aug 07 12:20:50 2009 +0200
@@ -71,6 +71,7 @@
     registered = require_group_compat(AppObject.registered)
 
     def __init__(self, *args, **kwargs):
+        self.appli = kwargs.pop('appli', None)
         super(Controller, self).__init__(*args, **kwargs)
         # attributes use to control after edition redirection
         self._after_deletion_path = None
@@ -86,14 +87,16 @@
 
     def process_rql(self, rql):
         """execute rql if specified"""
+        # XXX assigning to self really necessary?
+        self.rset = None
         if rql:
             self.ensure_ro_rql(rql)
             if not isinstance(rql, unicode):
                 rql = unicode(rql, self.req.encoding)
-            pp = self.vreg.select_component('magicsearch', self.req)
-            self.rset = pp.process_query(rql, self.req)
-            return self.rset
-        return None
+            pp = self.vreg['components'].select_object('magicsearch', self.req)
+            if pp is not None:
+                self.rset = pp.process_query(rql, self.req)
+        return self.rset
 
     def check_expected_params(self, params):
         """check that the given list of parameters are specified in the form
@@ -121,7 +124,7 @@
         redirect_info = set()
         eidtypes = tuple(eidtypes)
         for eid, etype in eidtypes:
-            entity = self.req.eid_rset(eid, etype).get_entity(0, 0)
+            entity = self.req.entity_from_eid(eid, etype)
             path, params = entity.after_deletion_path()
             redirect_info.add( (path, tuple(params.iteritems())) )
             entity.delete()
Binary file web/data/accessories-text-editor.png has changed
--- a/web/data/cubicweb.edition.js	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/cubicweb.edition.js	Fri Aug 07 12:20:50 2009 +0200
@@ -477,7 +477,7 @@
     d.addCallback(function (result, req) {
         handleFormValidationResponse(divid+'-form', noop, noop, result);
 	if (reload) {
-	    document.location.href = result[1];
+	    document.location.href = result[1].split('?')[0];
 	} else {
 	    var fieldview = getNode('value-' + divid);
 	    // XXX using innerHTML is very fragile and won't work if
--- a/web/data/cubicweb.flot.js	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/cubicweb.flot.js	Fri Aug 07 12:20:50 2009 +0200
@@ -1,32 +1,34 @@
 function showTooltip(x, y, contents) {
     $('<div id="tooltip">' + contents + '</div>').css( {
             position: 'absolute',
-	    display: 'none',
-	    top: y + 5,
+        display: 'none',
+        top: y + 5,
             left: x + 5,
             border: '1px solid #fdd',
             padding: '2px',
             'background-color': '#fee',
             opacity: 0.80
-		}).appendTo("body").fadeIn(200);
+        }).appendTo("body").fadeIn(200);
 }
 
 var previousPoint = null;
 function onPlotHover(event, pos, item) {
     if (item) {
         if (previousPoint != item.datapoint) {
-    	previousPoint = item.datapoint;
-    	
-    	$("#tooltip").remove();
-    	var x = item.datapoint[0].toFixed(2),
-    	    y = item.datapoint[1].toFixed(2);
-	if (item.datapoint.length == 3) {
-	    var x = new Date(item.datapoint[2]);
-	    x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
-	}
-    	showTooltip(item.pageX, item.pageY,
-    		    item.series.label + ': (' + x + ' ; ' + y + ')');
+            previousPoint = item.datapoint;
+            $("#tooltip").remove();
+            var x = item.datapoint[0].toFixed(2),
+                y = item.datapoint[1].toFixed(2);
+            if (item.datapoint.length == 3) {
+                x = new Date(item.datapoint[2]);
+                x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
+            } else if (item.datapoint.length == 4) {
+               x = new Date(item.datapoint[2]);
+               x = x.strftime(item.datapoint[3]);
             }
+            showTooltip(item.pageX, item.pageY,
+            item.series.label + ': (' + x + ' ; ' + y + ')');
+        }
     } else {
         $("#tooltip").remove();
         previousPoint = null;
--- a/web/data/cubicweb.htmlhelpers.js	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/cubicweb.htmlhelpers.js	Fri Aug 07 12:20:50 2009 +0200
@@ -16,78 +16,6 @@
     return '';
 }
 
-// XXX this is used exactly ONCE in web/views/massmailing.py
-function insertText(text, areaId) {
-    var textarea = jQuery('#' + areaId);
-    if (document.selection) { // IE
-        var selLength;
-        textarea.focus();
-        sel = document.selection.createRange();
-        selLength = sel.text.length;
-        sel.text = text;
-        sel.moveStart('character', selLength-text.length);
-        sel.select();
-    } else if (textarea.selectionStart || textarea.selectionStart == '0') { // mozilla
-        var startPos = textarea.selectionStart;
-        var endPos = textarea.selectionEnd;
-	// insert text so that it replaces the [startPos, endPos] part
-        textarea.value = textarea.value.substring(0,startPos) + text + textarea.value.substring(endPos,textarea.value.length);
-	// set cursor pos at the end of the inserted text
-        textarea.selectionStart = textarea.selectionEnd = startPos+text.length;
-        textarea.focus();
-    } else { // safety belt for other browsers
-        textarea.value += text;
-    }
-}
-
-/* taken from dojo toolkit */
-// XXX this looks unused
-function setCaretPos(element, start, end){
-    if(!end){ end = element.value.length; }  // NOTE: Strange - should be able to put caret at start of text?
-    // Mozilla
-    // parts borrowed from http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
-    if(element.setSelectionRange){
-        element.focus();
-        element.setSelectionRange(start, end);
-    } else if(element.createTextRange){ // IE
-        var range = element.createTextRange();
-        with(range){
-            collapse(true);
-            moveEnd('character', end);
-            moveStart('character', start);
-            select();
-        }
-    } else { //otherwise try the event-creation hack (our own invention)
-        // do we need these?
-        element.value = element.value;
-        element.blur();
-        element.focus();
-        // figure out how far back to go
-        var dist = parseInt(element.value.length)-end;
-        var tchar = String.fromCharCode(37);
-        var tcc = tchar.charCodeAt(0);
-        for(var x = 0; x < dist; x++){
-            var te = document.createEvent("KeyEvents");
-            te.initKeyEvent("keypress", true, true, null, false, false, false, false, tcc, tcc);
-            element.dispatchEvent(te);
-        }
-    }
-}
-
-
-// XXX this looks unused
-function setProgressMessage(label) {
-    var body = document.getElementsByTagName('body')[0];
-    body.appendChild(DIV({id: 'progress'}, label));
-    jQuery('#progress').show();
-}
-
-// XXX this looks unused
-function resetProgressMessage() {
-    var body = document.getElementsByTagName('body')[0];
-    jQuery('#progress').hide();
-}
-
 
 /* set body's cursor to 'progress' */
 function setProgressCursor() {
@@ -151,7 +79,7 @@
 
 
 /* toggles visibility of login popup div */
-// XXX used exactly ONCE
+// XXX used exactly ONCE in basecomponents
 function popupLoginBox() {
     toggleVisibility('popupLoginBox');
     jQuery('#__login:visible').focus();
@@ -193,14 +121,6 @@
     forEach(filter(filterfunc, elements), function(cb) {cb.checked=checked;});
 }
 
-/* centers an HTML element on the screen */
-// XXX looks unused
-function centerElement(obj){
-    var vpDim = getViewportDimensions();
-    var elemDim = getElementDimensions(obj);
-    setElementPosition(obj, {'x':((vpDim.w - elemDim.w)/2),
-			     'y':((vpDim.h - elemDim.h)/2)});
-}
 
 /* this function is a hack to build a dom node from html source */
 function html2dom(source) {
@@ -223,12 +143,6 @@
 function isTextNode(domNode) { return domNode.nodeType == 3; }
 function isElementNode(domNode) { return domNode.nodeType == 1; }
 
-// XXX this looks unused
-function changeLinkText(link, newText) {
-    jQuery(link).text(newText);
-}
-
-
 function autogrow(area) {
     if (area.scrollHeight > area.clientHeight && !window.opera) {
 	if (area.rows < 20) {
@@ -236,13 +150,6 @@
 	}
     }
 }
-
-// XXX this looks unused
-function limitTextAreaSize(textarea, size) {
-    var $area = jQuery(textarea);
-    $area.val($area.val().slice(0, size));
-}
-
 //============= page loading events ==========================================//
 
 CubicWeb.rounded = [
@@ -250,8 +157,6 @@
 		    ['div.boxTitle, div.boxPrefTitle, div.sideBoxTitle, th.month', 'top 6px']
 		    ];
 
-
-
 function roundedCorners(node) {
     node = jQuery(node);
     for(var r=0; r < CubicWeb.rounded.length; r++) {
@@ -259,7 +164,8 @@
     }
 }
 
-jQuery(document).ready(function () {roundedCorners(this.body)});
+jQuery(document).ready(function () {roundedCorners(this.body);});
+
+CubicWeb.provide('corners.js');
 
 CubicWeb.provide('htmlhelpers.js');
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/data/cubicweb.massmailing.js	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,23 @@
+
+function insertText(text, areaId) {
+    var textarea = jQuery('#' + areaId);
+    if (document.selection) { // IE
+        var selLength;
+        textarea.focus();
+        sel = document.selection.createRange();
+        selLength = sel.text.length;
+        sel.text = text;
+        sel.moveStart('character', selLength-text.length);
+        sel.select();
+    } else if (textarea.selectionStart || textarea.selectionStart == '0') { // mozilla
+        var startPos = textarea.selectionStart;
+        var endPos = textarea.selectionEnd;
+	// insert text so that it replaces the [startPos, endPos] part
+        textarea.value = textarea.value.substring(0,startPos) + text + textarea.value.substring(endPos,textarea.value.length);
+	// set cursor pos at the end of the inserted text
+        textarea.selectionStart = textarea.selectionEnd = startPos+text.length;
+        textarea.focus();
+    } else { // safety belt for other browsers
+        textarea.value += text;
+    }
+}
--- a/web/data/cubicweb.python.js	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/cubicweb.python.js	Fri Aug 07 12:20:50 2009 +0200
@@ -157,7 +157,7 @@
 // ========== ARRAY EXTENSIONS ========== ///
 Array.prototype.contains = function(element) {
     return findValue(this, element) != -1;
-}
+};
 
 // ========== END OF ARRAY EXTENSIONS ========== ///
 
@@ -201,7 +201,7 @@
  * [0,2,4,6,8]
  */
 function list(iterable) {
-    iterator = iter(iterable);
+    var iterator = iter(iterable);
     var result = [];
     while (true) {
 	/* iterates until StopIteration occurs */
@@ -267,14 +267,6 @@
 function min() { return listMin(arguments); }
 function max() { return listMax(arguments); }
 
-// tricky multiple assign
-// function assign(lst, varnames) {
-//     var length = min(lst.length, varnames.length);
-//     for(var i=0; i<length; i++) {
-// 	window[varnames[i]] = lst[i];
-//     }
-// }
-
 /*
  * >>> d = dict(["x", "y", "z"], [0, 1, 2])
  * >>> d['y']
@@ -335,7 +327,7 @@
 function makeConstructor(userctor) {
     return function() {
 	// this is a proxy to user's __init__
-	if(userctor) {
+	if (userctor) {
 	    userctor.apply(this, arguments);
 	}
     };
@@ -369,7 +361,7 @@
 	}
     }
     var userctor = basemeths['__init__'];
-    constructor = makeConstructor(userctor);
+    var constructor = makeConstructor(userctor);
 
     // python-like interface
     constructor.__name__ = name;
--- a/web/data/cubicweb.widgets.js	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/cubicweb.widgets.js	Fri Aug 07 12:20:50 2009 +0200
@@ -184,8 +184,7 @@
 Widgets.TreeView = defclass("TreeView", null, {
     __init__: function(wdgnode) {
 	jQuery(wdgnode).treeview({toggle: toggleTree,
-				  prerendered: true
-				 });
+				  prerendered: true});
     }
 });
 
--- a/web/data/external_resources	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/data/external_resources	Fri Aug 07 12:20:50 2009 +0200
@@ -18,7 +18,7 @@
 #IE_STYLESHEETS = DATADIR/cubicweb.ie.css
 
 # Javascripts files to include in HTML headers
-#JAVASCRIPTS = DATADIR/jqyery.js, DATADIR/cubicweb.python.js, DATADIR/jquery.json.js, DATADIR/cubicweb.compat.js, DATADIR/cubicweb.htmlhelpers.js
+#JAVASCRIPTS = DATADIR/jquery.js, DATADIR/cubicweb.python.js, DATADIR/jquery.json.js, DATADIR/cubicweb.compat.js, DATADIR/cubicweb.htmlhelpers.js
 
 # path to favicon (relative to the application main script, seen as a
 # directory, hence .. when you are not using an absolute path)
--- a/web/facet.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/facet.py	Fri Aug 07 12:20:50 2009 +0200
@@ -24,7 +24,7 @@
 from cubicweb.schema import display_name
 from cubicweb.utils import datetime2ticks, make_uid, ustrftime
 from cubicweb.selectors import match_context_prop, partial_relation_possible
-from cubicweb.appobject import AppRsetObject
+from cubicweb.appobject import AppObject
 from cubicweb.web.htmlwidgets import HTMLWidget
 
 ## rqlst manipulation functions used by facets ################################
@@ -64,8 +64,8 @@
 
 
 def get_facet(req, facetid, rqlst, mainvar):
-    return req.vreg.object_by_id('facets', facetid, req, rqlst=rqlst,
-                                 filtered_variable=mainvar)
+    return req.vreg['facets'].object_by_id(facetid, req, rqlst=rqlst,
+                                           filtered_variable=mainvar)
 
 
 def filter_hiddens(w, **kwargs):
@@ -241,7 +241,7 @@
 
 
 ## base facet classes #########################################################
-class AbstractFacet(AppRsetObject):
+class AbstractFacet(AppObject):
     __abstract__ = True
     __registry__ = 'facets'
     property_defs = {
@@ -259,22 +259,18 @@
     needs_update = False
     start_unfolded = True
 
-    @classmethod
-    def selected(cls, req, rset=None, rqlst=None, context=None,
-                 filtered_variable=None):
+    def __init__(self, req, rset=None, rqlst=None, filtered_variable=None,
+                 **kwargs):
+        super(AbstractFacet, self).__init__(req, rset, **kwargs)
         assert rset is not None or rqlst is not None
         assert filtered_variable
-        instance = super(AbstractFacet, cls).selected(req, rset)
-        #instance = AppRsetObject.selected(req, rset)
-        #instance.__class__ = cls
         # facet retreived using `object_by_id` from an ajax call
         if rset is None:
-            instance.init_from_form(rqlst=rqlst)
+            self.init_from_form(rqlst=rqlst)
         # facet retreived from `select` using the result set to filter
         else:
-            instance.init_from_rset()
-        instance.filtered_variable = filtered_variable
-        return instance
+            self.init_from_rset()
+        self.filtered_variable = filtered_variable
 
     def init_from_rset(self):
         self.rqlst = self.rset.syntax_tree().children[0]
--- a/web/form.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/form.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,7 +7,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from cubicweb.appobject import AppRsetObject
+from cubicweb.appobject import AppObject
 from cubicweb.view import NOINDEX, NOFOLLOW
 from cubicweb.common import tags
 from cubicweb.web import stdmsgs, httpcache, formfields
@@ -202,6 +202,6 @@
     found
     """
 
-class Form(FormMixIn, AppRsetObject):
+class Form(FormMixIn, AppObject):
     __metaclass__ = metafieldsform
     __registry__ = 'forms'
--- a/web/formfields.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/formfields.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,10 +11,10 @@
 from datetime import datetime
 
 from logilab.mtconverter import xml_escape
-from yams.constraints import SizeConstraint, StaticVocabularyConstraint
+from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
+                              FormatConstraint)
 
-from cubicweb.schema import 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 (
@@ -63,6 +63,8 @@
     :role:
        when the field is linked to an entity attribute or relation, tells the
        role of the entity in the relation (eg 'subject' or 'object')
+    :fieldset:
+       optional fieldset to which this field belongs to
 
     """
     # default widget associated to this class of fields. May be overriden per
@@ -76,7 +78,7 @@
     def __init__(self, name=None, id=None, label=None, help=None,
                  widget=None, required=False, initial=None,
                  choices=None, sort=True, internationalizable=False,
-                 eidparam=False, role='subject'):
+                 eidparam=False, role='subject', fieldset=None):
         self.name = name
         self.id = id or name
         self.label = label or name
@@ -88,6 +90,7 @@
         self.internationalizable = internationalizable
         self.eidparam = eidparam
         self.role = role
+        self.fieldset = fieldset
         self.init_widget(widget)
         # ordering number for this field instance
         self.creation_rank = Field.__creation_rank
@@ -158,7 +161,13 @@
         """render this field, which is part of form, using the given form
         renderer
         """
-        return self.get_widget(form).render(form, self)
+        widget = self.get_widget(form)
+        try:
+            return widget.render(form, self, renderer)
+        except TypeError:
+            warn('widget.render now take the renderer as third argument, please update %s implementation'
+                 % widget.__class__.__name__, DeprecationWarning)
+            return widget.render(form, self)
 
     def vocabulary(self, form):
         """return vocabulary for this field. This method will be called by
@@ -288,7 +297,7 @@
             result = format_field.render(form, renderer)
         else:
             result = u''
-        return result + self.get_widget(form).render(form, self)
+        return result + self.get_widget(form).render(form, self, renderer)
 
 
 class FileField(StringField):
@@ -308,7 +317,7 @@
             yield self.encoding_field
 
     def render(self, form, renderer):
-        wdgs = [self.get_widget(form).render(form, self)]
+        wdgs = [self.get_widget(form).render(form, self, renderer)]
         if self.format_field or self.encoding_field:
             divid = '%s-advanced' % form.context[self]['name']
             wdgs.append(u'<a href="%s" title="%s"><img src="%s" alt="%s"/></a>' %
@@ -362,7 +371,7 @@
                             'You can either submit a new file using the browse button above'
                             ', or edit file content online with the widget below.')
                     wdgs.append(u'<p><b>%s</b></p>' % msg)
-                    wdgs.append(TextArea(setdomid=False).render(form, self))
+                    wdgs.append(TextArea(setdomid=False).render(form, self, renderer))
                     # XXX restore form context?
         return '\n'.join(wdgs)
 
@@ -444,7 +453,7 @@
         # first see if its specified by __linkto form parameters
         linkedto = entity.linked_to(self.name, self.role)
         if linkedto:
-            entities = (req.eid_rset(eid).get_entity(0, 0) for eid in linkedto)
+            entities = (req.entity_from_eid(eid) for eid in linkedto)
             return [(entity.view('combobox'), entity.eid) for entity in entities]
         # it isn't, check if the entity provides a method to get correct values
         res = []
@@ -465,14 +474,26 @@
         return value
 
 
+class CompoundField(Field):
+    def __init__(self, fields, *args, **kwargs):
+        super(CompoundField, self).__init__(*args, **kwargs)
+        self.fields = fields
+
+    def subfields(self, form):
+        return self.fields
+
+    def actual_fields(self, form):
+        return [self] + list(self.fields)
+
+
 def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs):
     """return the most adapated widget to edit the relation
     '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'):
@@ -482,7 +503,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/formwidgets.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/formwidgets.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,7 +10,7 @@
 from datetime import date
 from warnings import warn
 
-from cubicweb.common import tags
+from cubicweb.common import tags, uilib
 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE
 
 
@@ -43,7 +43,7 @@
         if self.needs_css:
             form.req.add_css(self.needs_css)
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         """render the widget for the given `field` of `form`.
         To override in concrete class
         """
@@ -68,7 +68,7 @@
     """abstract widget class for <input> tag based widgets"""
     type = None
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         """render the widget for the given `field` of `form`.
 
         Generate one <input> tag for each field's value
@@ -96,7 +96,7 @@
     """
     type = 'password'
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         self.add_media(form)
         name, values, attrs = self._render_attrs(form, field)
         assert len(values) == 1
@@ -105,9 +105,11 @@
             confirmname = '%s-confirm:%s' % tuple(name.rsplit(':', 1))
         except TypeError:
             confirmname = '%s-confirm' % name
-        inputs = [tags.input(name=name, value=values[0], type=self.type, id=id, **attrs),
+        inputs = [tags.input(name=name, value=values[0], type=self.type, id=id,
+                             **attrs),
                   '<br/>',
-                  tags.input(name=confirmname, value=values[0], type=self.type, **attrs),
+                  tags.input(name=confirmname, value=values[0], type=self.type,
+                             **attrs),
                   '&nbsp;', tags.span(form.req._('confirm password'),
                                       **{'class': 'emphasis'})]
         return u'\n'.join(inputs)
@@ -147,7 +149,7 @@
 class TextArea(FieldWidget):
     """<textarea>"""
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         name, values, attrs = self._render_attrs(form, field)
         attrs.setdefault('onkeyup', 'autogrow(this)')
         if not values:
@@ -171,9 +173,9 @@
         super(FCKEditor, self).__init__(*args, **kwargs)
         self.attrs['cubicweb:type'] = 'wysiwyg'
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         form.req.fckeditor_config()
-        return super(FCKEditor, self).render(form, field)
+        return super(FCKEditor, self).render(form, field, renderer)
 
 
 class Select(FieldWidget):
@@ -184,23 +186,30 @@
         super(Select, self).__init__(attrs)
         self._multiple = multiple
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         name, curvalues, attrs = self._render_attrs(form, field)
         if not 'size' in attrs:
             attrs['size'] = self._multiple and '5' or '1'
         options = []
         optgroup_opened = False
-        for label, value in field.vocabulary(form):
+        for option in field.vocabulary(form):
+            try:
+                label, value, oattrs = option
+            except ValueError:
+                label, value = option
+                oattrs = {}
             if value is None:
                 # handle separator
                 if optgroup_opened:
                     options.append(u'</optgroup>')
-                options.append(u'<optgroup label="%s">' % (label or ''))
+                oattrs.setdefault('label', label or '')
+                options.append(u'<optgroup %s>' % uilib.sgml_attributes(oattrs))
                 optgroup_opened = True
             elif value in curvalues:
-                options.append(tags.option(label, value=value, selected='selected'))
+                options.append(tags.option(label, value=value,
+                                           selected='selected', **oattrs))
             else:
-                options.append(tags.option(label, value=value))
+                options.append(tags.option(label, value=value, **oattrs))
         if optgroup_opened:
             options.append(u'</optgroup>')
         return tags.select(name=name, multiple=self._multiple,
@@ -214,20 +223,26 @@
     type = 'checkbox'
     vocabulary_widget = True
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         name, curvalues, attrs = self._render_attrs(form, field)
         domid = attrs.pop('id', None)
-        sep = attrs.pop('separator', u'<br/>')
+        sep = attrs.pop('separator', u'<br/>\n')
         options = []
-        for i, (label, value) in enumerate(field.vocabulary(form)):
+        for i, option in enumerate(field.vocabulary(form)):
+            try:
+                label, value, oattrs = option
+            except ValueError:
+                label, value = option
+                oattrs = {}
             iattrs = attrs.copy()
+            iattrs.update(oattrs)
             if i == 0 and domid is not None:
-                iattrs['id'] = domid
+                iattrs.setdefault('id', domid)
             if value in curvalues:
                 iattrs['checked'] = u'checked'
             tag = tags.input(name=name, type=self.type, value=value, **iattrs)
-            options.append(tag + label + sep)
-        return '\n'.join(options)
+            options.append(tag + label)
+        return sep.join(options)
 
 
 class Radio(CheckBox):
@@ -237,6 +252,51 @@
     type = 'radio'
 
 
+# compound widgets #############################################################
+
+class IntervalWidget(FieldWidget):
+    """custom widget to display an interval composed by 2 fields. This widget
+    is expected to be used with a CompoundField containing the two actual
+    fields.
+
+    Exemple usage::
+
+from uicfg import autoform_field, autoform_section
+autoform_field.tag_attribute(('Concert', 'minprice'),
+                              CompoundField(fields=(IntField(name='minprice'),
+                                                    IntField(name='maxprice')),
+                                            label=_('price'),
+                                            widget=IntervalWidget()
+                                            ))
+# we've to hide the other field manually for now
+autoform_section.tag_attribute(('Concert', 'maxprice'), 'generated')
+    """
+    def render(self, form, field, renderer):
+        actual_fields = field.fields
+        assert len(actual_fields) == 2
+        return u'<div>%s %s %s %s</div>' % (
+            form.req._('from_interval_start'),
+            actual_fields[0].render(form, renderer),
+            form.req._('to_interval_end'),
+            actual_fields[1].render(form, renderer),
+            )
+
+
+class HorizontalLayoutWidget(FieldWidget):
+    """custom widget to display a set of fields grouped together horizontally
+    in a form. See `IntervalWidget` for example usage.
+    """
+    def render(self, form, field, renderer):
+        if self.attrs.get('display_label', True):
+            subst = self.attrs.get('label_input_substitution', '%(label)s %(input)s')
+            fields = [subst % {'label': renderer.render_label(form, f),
+                              'input': f.render(form, renderer)}
+                      for f in field.subfields(form)]
+        else:
+            fields = [f.render(form, renderer) for f in field.subfields(form)]
+        return u'<div>%s</div>' % ' '.join(fields)
+
+
 # javascript widgets ###########################################################
 
 class DateTimePicker(TextInput):
@@ -262,8 +322,8 @@
         req.html_headers.define_var('MONTHNAMES', monthnames)
         req.html_headers.define_var('DAYNAMES', daynames)
 
-    def render(self, form, field):
-        txtwidget = super(DateTimePicker, self).render(form, field)
+    def render(self, form, field, renderer):
+        txtwidget = super(DateTimePicker, self).render(form, field, renderer)
         self.add_localized_infos(form.req)
         cal_button = self._render_calendar_popup(form, field)
         return txtwidget + cal_button
@@ -302,7 +362,7 @@
         if inputid is not None:
             self.attrs['cubicweb:inputid'] = inputid
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         self.add_media(form)
         attrs = self._render_attrs(form, field)[-1]
         return tags.div(**attrs)
@@ -373,8 +433,8 @@
         etype_from = entity.e_schema.subject_relation(self.name).objects(entity.e_schema)[0]
         attrs['cubicweb:etype_from'] = etype_from
 
-    def render(self, form, field):
-        return super(AddComboBoxWidget, self).render(form, field) + u'''
+    def render(self, form, field, renderer):
+        return super(AddComboBoxWidget, self).render(form, field, renderer) + u'''
 <div id="newvalue">
   <input type="text" id="newopt" />
   <a href="javascript:noop()" id="add_newopt">&nbsp;</a></div>
@@ -400,7 +460,7 @@
         self.cwaction = cwaction
         self.attrs.setdefault('klass', 'validateButton')
 
-    def render(self, form, field=None):
+    def render(self, form, field=None, renderer=None):
         label = form.req._(self.label)
         attrs = self.attrs.copy()
         if self.cwaction:
@@ -443,7 +503,7 @@
         self.imgressource = imgressource
         self.label = label
 
-    def render(self, form, field=None):
+    def render(self, form, field=None, renderer=None):
         label = form.req._(self.label)
         imgsrc = form.req.external_resource(self.imgressource)
         return '<a id="%(domid)s" href="%(href)s">'\
--- a/web/request.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/request.py	Fri Aug 07 12:20:50 2009 +0200
@@ -18,7 +18,7 @@
 from rql.utils import rqlvar_maker
 
 from logilab.common.decorators import cached
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 
 from logilab.mtconverter import xml_escape
 
@@ -26,6 +26,7 @@
 from cubicweb.common.mail import header
 from cubicweb.common.uilib import remove_html_tags
 from cubicweb.utils import SizeConstrainedList, HTMLHead
+from cubicweb.view import STRICT_DOCTYPE
 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
                           RequestError, StatusResponse)
 
@@ -80,7 +81,7 @@
         # to create a relation with another)
         self.search_state = ('normal',)
         # tabindex generator
-        self.tabindexgen = count()
+        self.tabindexgen = count(1)
         self.next_tabindex = self.tabindexgen.next
         # page id, set by htmlheader template
         self.pageid = None
@@ -515,7 +516,7 @@
         return self.base_url() + self.relative_path(includeparams)
 
     def _datadir_url(self):
-        """return url of the application's data directory"""
+        """return url of the instance's data directory"""
         return self.base_url() + 'data%s/' % self.vreg.config.instance_md5_version()
 
     def selected(self, url):
@@ -538,8 +539,7 @@
     def from_controller(self):
         """return the id (string) of the controller issuing the request"""
         controller = self.relative_path(False).split('/', 1)[0]
-        registered_controllers = (ctrl.id for ctrl in
-                                  self.vreg.registry_objects('controllers'))
+        registered_controllers = self.vreg['controllers'].keys()
         if controller in registered_controllers:
             return controller
         return 'view'
@@ -587,7 +587,7 @@
 
     def relative_path(self, includeparams=True):
         """return the normalized path of the request (ie at least relative
-        to the application's root, but some other normalization may be needed
+        to the instance's root, but some other normalization may be needed
         so that the returned path may be used to compare to generated urls
 
         :param includeparams:
@@ -629,7 +629,7 @@
                            auth, ex.__class__.__name__, ex)
         return None, None
 
-    @obsolete("use parse_accept_header('Accept-Language')")
+    @deprecated("use parse_accept_header('Accept-Language')")
     def header_accept_language(self):
         """returns an ordered list of preferred languages"""
         return [value.split('-')[0] for value in
@@ -699,6 +699,14 @@
         return useragent and 'MSIE' in useragent
 
     def xhtml_browser(self):
+        """return True if the browser is considered as xhtml compatible.
+
+        If the instance is configured to always return text/html and not
+        application/xhtml+xml, this method will always return False, even though
+        this is semantically different
+        """
+        if self.vreg.config['force-html-content-type']:
+            return False
         useragent = self.useragent()
         # * MSIE/Konqueror does not support xml content-type
         # * Opera supports xhtml and handles namespaces properly but it breaks
@@ -713,5 +721,11 @@
             return 'application/xhtml+xml'
         return 'text/html'
 
+    def document_surrounding_div(self):
+        if self.xhtml_browser():
+            return (u'<?xml version="1.0"?>\n' + STRICT_DOCTYPE +
+                    u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">')
+        return u'<div>'
+
 from cubicweb import set_log_methods
 set_log_methods(CubicWebRequestBase, LOGGER)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/test/data/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,62 @@
+"""
+
+:organization: Logilab
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+
+from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+                            SubjectRelation, ObjectRelation,
+                            String, Int, Datetime, Boolean, Float)
+from yams.constraints import IntervalBoundConstraint
+
+class Salesterm(EntityType):
+    described_by_test = SubjectRelation('File', cardinality='1*', composite='subject')
+    amount = Int(constraints=[IntervalBoundConstraint(0, 100)])
+    reason = String(maxsize=20, vocabulary=[u'canceled', u'sold'])
+
+class tags(RelationDefinition):
+    subject = 'Tag'
+    object = ('BlogEntry', 'CWUser')
+
+class checked_by(RelationType):
+    subject = 'BlogEntry'
+    object = 'CWUser'
+    cardinality = '?*'
+    permissions = {
+        'add': ('managers',),
+        'read': ('managers', 'users'),
+        'delete': ('managers',),
+        }
+
+class Personne(EntityType):
+    nom    = String(fulltextindexed=True, required=True, maxsize=64)
+    prenom = String(fulltextindexed=True, maxsize=64)
+    sexe   = String(maxsize=1, default='M')
+    promo  = String(vocabulary=('bon','pasbon'))
+    titre  = String(fulltextindexed=True, maxsize=128)
+    ass    = String(maxsize=128)
+    web    = String(maxsize=128)
+    tel    = Int()
+    fax    = Int()
+    datenaiss = Datetime()
+    test   = Boolean()
+    description = String()
+    salary = Float()
+    travaille = SubjectRelation('Societe')
+    connait = ObjectRelation('CWUser')
+
+class Societe(EntityType):
+    nom  = String(maxsize=64, fulltextindexed=True)
+    web  = String(maxsize=128)
+    type  = String(maxsize=128) # attribute in common with Note
+    tel  = Int()
+    fax  = Int()
+    rncs = String(maxsize=128)
+    ad1  = String(maxsize=128)
+    ad2  = String(maxsize=128)
+    ad3  = String(maxsize=128)
+    cp   = String(maxsize=12)
+    ville= String(maxsize=32)
+
--- a/web/test/data/schema/Personne.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-nom    ivarchar(64) NOT NULL
-prenom ivarchar(64)
-sexe   char(1) DEFAULT 'M' 
-promo  choice('bon','pasbon')
-titre  ivarchar(128)
-ass    varchar(128)
-web    varchar(128)
-tel    integer
-fax    integer
-datenaiss datetime
-test   boolean 
-description text
-salary float
--- a/web/test/data/schema/Societe.sql	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-nom  ivarchar(64)
-web varchar(128)
-tel  integer
-fax  integer
-rncs varchar(32)
-ad1  varchar(128)
-ad2  varchar(128)
-ad3  varchar(128)
-cp   varchar(12)
-ville varchar(32)
--- a/web/test/data/schema/relations.rel	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-Personne travaille Societe
-CWUser connait Personne
--- a/web/test/data/schema/testschema.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-class Salesterm(EntityType):
-    described_by_test = SubjectRelation('File', cardinality='1*', composite='subject')
-    amount = Int(constraints=[IntervalBoundConstraint(0, 100)])
-    reason = String(maxsize=20, vocabulary=[u'canceled', u'sold'])
-
-class tags(RelationDefinition):
-    subject = 'Tag'
-    object = ('BlogEntry', 'CWUser')
-
-class checked_by(RelationType):
-    subject = 'BlogEntry'
-    object = 'CWUser'
-    cardinality = '?*'
-    permissions = {
-        'add': ('managers',),
-        'read': ('managers', 'users'),
-        'delete': ('managers',),
-        }
--- a/web/test/test_views.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/test_views.py	Fri Aug 07 12:20:50 2009 +0200
@@ -52,7 +52,7 @@
 
     def test_js_added_only_once(self):
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(SomeView)
+        self.vreg.register_appobject_class(SomeView)
         rset = self.execute('CWUser X')
         source = self.view('someview', rset).source
         self.assertEquals(source.count('spam.js'), 1)
--- a/web/test/unittest_application.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_application.py	Fri Aug 07 12:20:50 2009 +0200
@@ -7,16 +7,17 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 
-from logilab.common.testlib import TestCase, unittest_main
 import base64, Cookie
-
 import sys
 from urllib import unquote
+
+from logilab.common.testlib import TestCase, unittest_main
 from logilab.common.decorators import clear_cache
 
+from cubicweb.devtools.apptest import EnvBasedTC
+from cubicweb.devtools.fake import FakeRequest
 from cubicweb.web import Redirect, AuthenticationError, ExplicitLogin, INTERNAL_FIELD_VALUE
 from cubicweb.web.views.basecontrollers import ViewController
-from cubicweb.devtools._apptest import FakeRequest
 
 class FakeMapping:
     """emulates a mapping module"""
@@ -133,9 +134,6 @@
                            for i in (12, 13, 14)])
 
 
-from cubicweb.devtools.apptest import EnvBasedTC
-
-
 class ApplicationTC(EnvBasedTC):
 
     def publish(self, req, path='view'):
--- a/web/test/unittest_form.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_form.py	Fri Aug 07 12:20:50 2009 +0200
@@ -91,7 +91,7 @@
         e.req = self.req
         geid = self.execute('CWGroup X WHERE X name "users"')[0][0]
         self.req.form['__linkto'] = 'in_group:%s:subject' % geid
-        form = self.vreg.select_object('forms', 'edition', self.req, None, entity=e)
+        form = self.vreg['forms'].select('edition', self.req, entity=e)
         form.content_type = 'text/html'
         pageinfo = self._check_html(form.form_render(), form, template=None)
         inputs = pageinfo.find_tag('select', False)
@@ -101,8 +101,8 @@
 
     def test_reledit_composite_field(self):
         rset = self.execute('INSERT BlogEntry X: X title "cubicweb.org", X content "hop"')
-        form = self.vreg.select_object('views', 'reledit', self.request(),
-                                       rset=rset, row=0, rtype='content')
+        form = self.vreg['views'].select('reledit', self.request(),
+                                         rset=rset, row=0, rtype='content')
         data = form.render(row=0, rtype='content')
         self.failUnless('edits-content' in data)
         self.failUnless('edits-content_format' in data)
@@ -151,17 +151,17 @@
 
     def test_richtextfield_1(self):
         self.req.use_fckeditor = lambda: False
-        self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="0">
+        self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="1">
 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
 <option value="text/html">text/html</option>
 <option value="text/plain">text/plain</option>
 <option selected="selected" value="text/rest">text/rest</option>
-</select><textarea cols="80" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>''')
+</select><textarea cols="80" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="2"></textarea>''')
 
 
     def test_richtextfield_2(self):
         self.req.use_fckeditor = lambda: True
-        self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest"></input><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="0"></textarea>')
+        self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest" /><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>')
 
 
     def test_filefield(self):
@@ -172,14 +172,14 @@
                                data=Binary('new widgets system'))
         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""></input>
+                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
 <div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain"></input><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8"></input><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
 </div>
 <br/>
-<input name="data:%(eid)s__detach" type="checkbox"></input>
+<input name="data:%(eid)s__detach" type="checkbox" />
 detach attached file
 ''' % {'eid': file.eid})
 
@@ -196,17 +196,17 @@
                                data=Binary('new widgets system'))
         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""></input>
+                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
 <div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain"></input><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8"></input><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
 </div>
 <br/>
-<input name="data:%(eid)s__detach" type="checkbox"></input>
+<input name="data:%(eid)s__detach" type="checkbox" />
 detach attached file
 <p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
-<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
+<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="4">new widgets system</textarea>''' % {'eid': file.eid})
 
 
     def test_passwordfield(self):
@@ -214,9 +214,9 @@
             upassword = StringField(widget=PasswordInput)
         form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
         self.assertTextEquals(self._render_entity_field('upassword', form),
-                              '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"></input>
+                              '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
 <br/>
-<input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"></input>
+<input name="upassword-confirm:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
 &nbsp;
 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
 
--- a/web/test/unittest_magicsearch.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_magicsearch.py	Fri Aug 07 12:20:50 2009 +0200
@@ -44,7 +44,7 @@
         super(QueryTranslatorTC, self).setUp()
         self.req = self.env.create_request()
         self.vreg.config.translations = {'en': _translate}
-        proc = self.vreg.select_component('magicsearch', self.req)
+        proc = self.vreg['components'].select('magicsearch', self.req)
         self.proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0]
 
     def test_basic_translations(self):
@@ -69,7 +69,7 @@
         super(QSPreProcessorTC, self).setUp()
         self.vreg.config.translations = {'en': _translate}
         self.req = self.request()
-        proc = self.vreg.select_component('magicsearch', self.req)
+        proc = self.vreg['components'].select('magicsearch', self.req)
         self.proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0]
         self.proc.req = self.req
 
@@ -147,11 +147,6 @@
                           ('CWUser C WHERE C use_email C1, C1 alias LIKE %(text)s', {'text': '%Logilab'}))
         self.assertRaises(BadRQLQuery, transform, 'word1', 'word2', 'word3')
 
-    def test_multiple_words_query(self):
-        """tests multiple_words_query()"""
-        self.assertEquals(self.proc._multiple_words_query(['a', 'b', 'c', 'd', 'e']),
-                          ('a b c d e',))
-
     def test_quoted_queries(self):
         """tests how quoted queries are handled"""
         queries = [
@@ -174,10 +169,11 @@
             (u'Utilisateur P', (u"CWUser P",)),
             (u'Utilisateur cubicweb', (u'CWUser C WHERE C has_text %(text)s', {'text': u'cubicweb'})),
             (u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)),
-            (u'Any X WHERE X is Something', (u"Any X WHERE X is Something",)),
             ]
         for query, expected in queries:
             self.assertEquals(self.proc.preprocess_query(query, self.req), expected)
+        self.assertRaises(BadRQLQuery,
+                          self.proc.preprocess_query, 'Any X WHERE X is Something', self.req)
 
 
 
@@ -191,7 +187,7 @@
         super(ProcessorChainTC, self).setUp()
         self.vreg.config.translations = {'en': _translate}
         self.req = self.request()
-        self.proc = self.vreg.select_component('magicsearch', self.req)
+        self.proc = self.vreg['components'].select('magicsearch', self.req)
 
     def test_main_preprocessor_chain(self):
         """tests QUERY_PROCESSOR"""
--- a/web/test/unittest_urlrewrite.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_urlrewrite.py	Fri Aug 07 12:20:50 2009 +0200
@@ -29,12 +29,14 @@
         self.assertListEquals(rules, [
             ('foo' , dict(rql='Foo F')),
             ('/index' , dict(vid='index2')),
-            ('/schema', {'vid': 'schema'}),
+            ('/schema', dict(vid='schema')),
             ('/myprefs', dict(vid='propertiesform')),
             ('/siteconfig', dict(vid='systempropertiesform')),
+            ('/siteinfo', dict(vid='info')),
             ('/manage', dict(vid='manage')),
-            ('/notfound', {'vid': '404'}),
-            ('/error', {'vid': 'error'}),
+            ('/notfound', dict(vid='404')),
+            ('/error', dict(vid='error')),
+            ('/sparql', dict(vid='sparql')),
             ('/schema/([^/]+?)/?$', {'rql': r'Any X WHERE X is CWEType, X name "\1"', 'vid': 'eschema'}),
             ('/add/([^/]+?)/?$' , dict(vid='creation', etype=r'\1')),
             ('/doc/images/(.+?)/?$', dict(fid='\\1', vid='wdocimages')),
--- a/web/test/unittest_views_actions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_actions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,19 +13,19 @@
     def test_view_action(self):
         req = self.request(__message='bla bla bla', vid='rss', rql='CWUser X')
         rset = self.execute('CWUser X')
-        vaction = [action for action in self.vreg.possible_vobjects('actions', req, rset)
+        vaction = [action for action in self.vreg['actions'].possible_vobjects(req, rset=rset)
                    if action.id == 'view'][0]
         self.assertEquals(vaction.url(), 'http://testing.fr/cubicweb/view?rql=CWUser%20X')
 
     def test_sendmail_action(self):
         req = self.request()
         rset = self.execute('Any X WHERE X login "admin"', req=req)
-        self.failUnless([action for action in self.vreg.possible_vobjects('actions', req, rset)
+        self.failUnless([action for action in self.vreg['actions'].possible_vobjects(req, rset=rset)
                          if action.id == 'sendemail'])
         self.login('anon')
         req = self.request()
         rset = self.execute('Any X WHERE X login "anon"', req=req)
-        self.failIf([action for action in self.vreg.possible_vobjects('actions', req, rset)
+        self.failIf([action for action in self.vreg['actions'].possible_vobjects(req, rset=rset)
                      if action.id == 'sendemail'])
 
 if __name__ == '__main__':
--- a/web/test/unittest_views_basecontrollers.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_basecontrollers.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,16 +8,13 @@
 import simplejson
 
 from logilab.common.testlib import unittest_main, mock_object
-
-from cubicweb import Binary, Unauthorized
-from cubicweb.devtools._apptest import TestEnvironment
 from cubicweb.devtools.apptest import EnvBasedTC, ControllerTC
 
-from cubicweb.common import ValidationError
+from cubicweb import Binary, NoSelectableObject, ValidationError
+from cubicweb.view import STRICT_DOCTYPE
 from cubicweb.common.uilib import rql_for_eid
 
 from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError
-from cubicweb.web.views.basecontrollers import xhtml_wrap
 
 from cubicweb.entities.authobjs import CWUser
 
@@ -499,7 +496,7 @@
         # updated (which is what happened before this test)
         req = self.request()
         req.form['url'] = 'http://intranet.logilab.fr/'
-        controller = self.env.app.select_controller('embed', req)
+        controller = self.vreg['controllers'].select('embed', req)
         result = controller.publish(rset=None)
 
 
@@ -507,7 +504,7 @@
 
     def test_usable_by_guets(self):
         req = self.request()
-        self.env.app.select_controller('reportbug', req)
+        self.vreg['controllers'].select('reportbug', req)
 
 
 class SendMailControllerTC(EnvBasedTC):
@@ -515,7 +512,7 @@
     def test_not_usable_by_guets(self):
         self.login('anon')
         req = self.request()
-        self.assertRaises(Unauthorized, self.env.app.select_controller, 'sendmail', req)
+        self.assertRaises(NoSelectableObject, self.env.vreg['controllers'].select, 'sendmail', req)
 
 
 
@@ -523,7 +520,7 @@
 
     def ctrl(self, req=None):
         req = req or self.request(url='http://whatever.fr/')
-        return self.env.app.select_controller('json', req)
+        return self.vreg['controllers'].select('json', req)
 
     def setup_database(self):
         self.pytag = self.add_entity('Tag', name=u'python')
@@ -538,8 +535,13 @@
         ctrl = self.ctrl(req)
         rset = self.john.as_rset()
         rset.req = req
-        self.assertTextEquals(ctrl.publish(),
-                              xhtml_wrap(mock_object(req=req), ctrl.view('primary', rset)))
+        source = ctrl.publish()
+        self.failUnless(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE +
+                                          u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">')
+                        )
+        req.xhtml_browser = lambda: False
+        source = ctrl.publish()
+        self.failUnless(source.startswith('<div>'))
 
 #     def test_json_exec(self):
 #         rql = 'Any T,N WHERE T is Tag, T name N'
--- a/web/test/unittest_views_baseforms.py	Fri Aug 07 12:20:37 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-"""cubicweb.web.views.baseforms unit tests
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-from StringIO import StringIO
-from datetime import date
-import re
-
-
-from logilab.common.testlib import unittest_main
-from logilab.common.decorators import clear_cache
-from cubicweb.devtools.apptest import EnvBasedTC
-from cubicweb.entities import AnyEntity
-from cubicweb.web import widgets
-
-orig_now = widgets.datetime.now
-
-def setup_module(options):
-    def _today():
-        return date(0000, 1, 1)
-    widgets.datetime.now = _today
-
-def teardown_module(options, results):
-    widgets.datetime.now = orig_now
-
-
-def cleanup_text(text):
-    return re.sub('\d\d:\d\d', 'hh:mm', re.sub('\d+/\d\d/\d\d', 'YYYY/MM/DD', '\n'.join(l.strip() for l in text.splitlines() if l.strip())))
-
-
-
-class EditionFormTC(EnvBasedTC):
-
-    def setup_database(self):
-        self.create_user('joe')
-
-    def _build_creation_form(self, etype):
-        req = self.request()
-        req.next_tabindex()
-        req.next_tabindex()
-        req.del_page_data()
-        req.form['etype'] = etype
-        view = self.vreg.select_view('creation', req, None)
-        entity = self.vreg.etype_class(etype)(req, None, None)
-        buffer = StringIO()
-        view.w = buffer.write
-        view.edit_form(entity, {})
-        return buffer.getvalue()
-
-    def _test_view_for(self, etype, expected):
-        self.assertTextEquals(expected, cleanup_text(self._build_creation_form(etype)))
-
-    def test_base(self):
-        self._test_view_for('CWGroup', '''\
-<form id="entityForm" class="entityForm" cubicweb:target="eformframe"
-method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
-<div class="formTitle"><span>egroup (creation)</span></div>
-<div id="progress">validating...</div>
-<div class="iformTitle"><span>main informations</span></div>
-<div class="formBody"><fieldset>
-<input type="hidden" name="eid" value="A" />
-<input type="hidden" name="__type:A" value="CWGroup" />
-<input type="hidden" name="__maineid" value="A" />
-<input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
-<input type="hidden" name="__form_id" value="edition" />
-<input type="hidden" name="__message" value="element created" />
-<table id="entityFormA" class="attributeForm" style="width:100%;">
-<tr>
-<th class="labelCol"><label class="required" for="name:A">name</label></th>
-<td style="width:100%;">
-<input type="hidden" name="edits-name:A" value="__cubicweb_internal_field__"/>
-<input type="text" name="name:A" value="" accesskey="n" id="name:A" maxlength="64" size="40" tabindex="2"/>
-<br/>
-</td>
-</tr>
-</table>
-</fieldset>
-</div>
-<table width="100%">
-<tbody>
-<tr><td align="center">
-<input class="validateButton" type="submit" name="defaultsubmit" value="Button_ok" tabindex="3"/>
-</td><td style="align: right; width: 50%;">
-<input class="validateButton" type="button" onclick="postForm('__action_apply', 'Button_apply', 'entityForm')" value="Button_apply" tabindex="4"/>
-<input class="validateButton" type="button" onclick="postForm('__action_cancel', 'Button_cancel', 'entityForm')" value="Button_cancel" tabindex="5"/>
-</td></tr>
-</tbody>
-</table>
-</form>''')
-
-    def test_with_inline_view(self):
-        activated = self.execute('Any X WHERE X is State, X name "activated"')[0][0]
-        self._test_view_for('CWUser', '''<form id="entityForm" class="entityForm" cubicweb:target="eformframe"
-method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
-<div class="formTitle"><span>euser (creation)</span></div>
-<div id="progress">validating...</div>
-<div class="iformTitle"><span>main informations</span></div>
-<div class="formBody"><fieldset>
-<input type="hidden" name="eid" value="A" />
-<input type="hidden" name="__type:A" value="CWUser" />
-<input type="hidden" name="__maineid" value="A" />
-<input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
-<input type="hidden" name="__form_id" value="edition" />
-<input type="hidden" name="__message" value="element created" />
-<table id="entityFormA" class="attributeForm" style="width:100%%;">
-<tr>
-<th class="labelCol"><label class="required" for="login:A">login</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-login:A" value="__cubicweb_internal_field__"/>
-<input type="text" name="login:A" value="" accesskey="l" id="login:A" maxlength="64" size="40" tabindex="2"/>
-<br/>&nbsp;<span class="helper">unique identifier used to connect to the application</span>
-</td>
-</tr>
-<tr>
-<th class="labelCol"><label class="required" for="upassword:A">upassword</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-upassword:A" value="__cubicweb_internal_field__"/>
-<input type="password" name="upassword:A" value="" accesskey="u" id="upassword:A" tabindex="3"/><br/>
-<input type="password" name="upassword-confirm:A" id="upassword-confirm:A" tabindex="4"/>&nbsp;<span class="emphasis">(confirm password)</span>
-<br/>
-</td>
-</tr>
-<tr>
-<th class="labelCol"><label for="firstname:A">firstname</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-firstname:A" value="__cubicweb_internal_field__"/>
-<input type="text" name="firstname:A" value="" accesskey="f" id="firstname:A" maxlength="64" size="40" tabindex="5"/>
-<br/>
-</td>
-</tr>
-<tr>
-<th class="labelCol"><label for="surname:A">surname</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-surname:A" value="__cubicweb_internal_field__"/>
-<input type="text" name="surname:A" value="" accesskey="s" id="surname:A" maxlength="64" size="40" tabindex="6"/>
-<br/>
-</td>
-</tr>
-<tr>
-<th class="labelCol"><label class="required" for="in_group:A">in_group</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-in_group:A" value="__cubicweb_internal_field__"/>
-<select name="in_group:A" id="in_group:A" multiple="multiple" size="5" tabindex="7">
-<option value="3" >guests</option>
-<option value="1" >managers</option>
-<option value="2" >users</option>
-</select>
-<br/>&nbsp;<span class="helper">groups grant permissions to the user</span>
-</td>
-</tr>
-<tr>
-<th class="labelCol"><label class="required" for="in_state:A">in_state</label></th>
-<td style="width:100%%;">
-<input type="hidden" name="edits-in_state:A" value="__cubicweb_internal_field__"/>
-<select name="in_state:A" id="in_state:A" tabindex="8">
-<option value="%(activated)s" >activated</option>
-</select>
-<br/>&nbsp;<span class="helper">account state</span>
-</td>
-</tr>
-</table>
-<div id="inlineuse_emailslot">
-<div class="inlinedform" id="addNewEmailAddressuse_emailsubject:A" cubicweb:limit="true">
-<a class="addEntity" id="adduse_email:Alink" href="javascript: addInlineCreationForm('A', 'CWUser', 'EmailAddress', 'use_email', 'subject')" >+ add a EmailAddress.</a>
-</div>
-<div class="trame_grise">&nbsp;</div>
-</div>
-</fieldset>
-</div>
-<table width="100%%">
-<tbody>
-<tr><td align="center">
-<input class="validateButton" type="submit" name="defaultsubmit" value="Button_ok" tabindex="9"/>
-</td><td style="align: right; width: 50%%;">
-<input class="validateButton" type="button" onclick="postForm('__action_apply', 'Button_apply', 'entityForm')" value="Button_apply" tabindex="10"/>
-<input class="validateButton" type="button" onclick="postForm('__action_cancel', 'Button_cancel', 'entityForm')" value="Button_cancel" tabindex="11"/>
-</td></tr>
-</tbody>
-</table>
-</form>''' % {'activated' : activated})
-
-    def test_redirection_after_creation(self):
-        req = self.request()
-        req.form['etype'] = 'CWUser'
-        view = self.vreg.select_view('creation', req, None)
-        self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/euser')
-        req.form['__redirectrql'] = 'Any X WHERE X eid 3012'
-        req.form['__redirectvid'] = 'avid'
-        self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/view?rql=Any%20X%20WHERE%20X%20eid%203012&vid=avid')
-
-
-    def test_need_multipart(self):
-        req = self.request()
-        class Salesterm(AnyEntity):
-            id = 'Salesterm'
-            __rtags__ = {'described_by_test' : 'inlineview'}
-        vreg = self.vreg
-        vreg.register_vobject_class(Salesterm)
-        req.form['etype'] = 'Salesterm'
-        entity = vreg.etype_class('Salesterm')(req, None, None)
-        view = vreg.select_view('creation', req, None)
-        self.failUnless(view.need_multipart(entity))
-
-
-
-    def test_nonregr_check_add_permission_on_relation(self):
-        from cubes.blog.entities import BlogEntry
-        class BlogEntryPlus(BlogEntry):
-            __rtags__ = {'checked_by': 'primary'}
-        self.vreg.register_vobject_class(BlogEntryPlus)
-        clear_cache(self.vreg, 'etype_class')
-        # an admin should be able to edit the checked_by relation
-        html = self._build_creation_form('BlogEntry')
-        self.failUnless('name="edits-checked_by:A"' in html)
-        # a regular user should not be able to see the relation
-        self.login('joe')
-        html = self._build_creation_form('BlogEntry')
-        self.failIf('name="edits-checked_by:A"' in html)
-
-from cubicweb.devtools.testlib import WebTest
-from cubicweb.devtools.htmlparser import DTDValidator
-
-class CopyWebTest(WebTest):
-
-    def setup_database(self):
-        p = self.create_user("Doe")
-        # do not try to skip 'primary_email' for this test
-        e = self.add_entity('EmailAddress', address=u'doe@doe.com')
-        self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
-                     {'p' : p.eid, 'e' : e.eid})
-
-
-    def test_cloned_elements_in_copy_form(self):
-        rset = self.execute('CWUser P WHERE P login "Doe"')
-        output = self.view('copy', rset)
-        clones = [attrs for _, attrs in output.input_tags
-                  if attrs.get('name', '').startswith('__cloned_eid')]
-        # the only cloned entity should be the original person
-        self.assertEquals(len(clones), 1)
-        attrs = clones[0]
-        self.assertEquals(attrs['name'], '__cloned_eid:A')
-        self.assertEquals(int(attrs['value']), rset[0][0])
-
-
-if __name__ == '__main__':
-    unittest_main()
--- a/web/test/unittest_views_basetemplates.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_basetemplates.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,7 +13,7 @@
 
     def _login_labels(self):
         valid = self.content_type_validators.get('text/html', DTDValidator)()
-        page = valid.parse_string(self.vreg.main_template(self.request(), 'login'))
+        page = valid.parse_string(self.vreg['views'].main_template(self.request(), 'login'))
         return page.find_tag('label')
 
     def test_label(self):
--- a/web/test/unittest_views_baseviews.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_baseviews.py	Fri Aug 07 12:20:50 2009 +0200
@@ -44,11 +44,16 @@
         rset = self.execute('Any X WHERE X eid 1')
         self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary')
 
-    def test_more_than_one_entity(self):
+    def test_more_than_one_entity_same_type(self):
         req = self.request()
         rset = self.execute('Any X WHERE X is CWUser')
-        self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
+        self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist')
         rset = self.execute('Any X, L WHERE X login L')
+        self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist')
+
+    def test_more_than_one_entity_diff_type(self):
+        req = self.request()
+        rset = self.execute('Any X WHERE X is IN (CWUser, CWGroup)')
         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
 
     def test_more_than_one_entity_by_row(self):
@@ -86,7 +91,7 @@
         rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s',
                             {'x': e.eid}, 'x')
         req = self.request()
-        view = self.vreg.select_view('table', req, rset)
+        view = self.vreg['views'].select('table', req, rset=rset)
         return e, rset, view
 
     def test_headers(self):
@@ -102,9 +107,8 @@
         # self.assertAlmostEquals(value, rset.rows[0][3].seconds)
 
     def test_sortvalue_with_display_col(self):
-        self.skip('XXX there is no column_labels on rset')
         e, rset, view = self._prepare_entity()
-        labels = rset.column_labels()
+        labels = view.columns_labels()
         table = TableWidget(view)
         table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0)
         expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')]
--- a/web/test/unittest_views_editforms.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_editforms.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,20 +17,20 @@
 
     def test_custom_widget(self):
         AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'),
-                                          {'widget':AutoCompletionWidget})
-        form = self.vreg.select_object('forms', 'edition', self.request(), None,
-                                       entity=self.user())
+                                          {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')})
+        form = self.vreg['forms'].select('edition', self.request(),
+                                         entity=self.user())
         field = form.field_by_name('login')
         self.assertIsInstance(field.widget, AutoCompletionWidget)
         AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject')
 
 
-    def test_euser_relations_by_category(self):
+    def test_cwuser_relations_by_category(self):
         #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
         #    if rtype == 'tags':
         #        print rtype, role, stype, otype, ':', tag
         e = self.etype_instance('CWUser')
-        # see custom configuration in views.euser
+        # see custom configuration in views.cwuser
         self.assertEquals(rbc(e, 'primary'),
                           [('login', 'subject'),
                            ('upassword', 'subject'),
@@ -46,6 +46,7 @@
                               [('last_login_time', 'subject'),
                                ('created_by', 'subject'),
                                ('creation_date', 'subject'),
+                               ('cwuri', 'subject'),
                                ('modification_date', 'subject'),
                                ('owned_by', 'subject'),
                                ('bookmarked_by', 'object'),
@@ -97,6 +98,7 @@
         self.assertListEquals(rbc(e, 'metadata'),
                               [('created_by', 'subject'),
                                ('creation_date', 'subject'),
+                               ('cwuri', 'subject'),
                                ('modification_date', 'subject'),
                                ('owned_by', 'subject'),
                                ])
@@ -114,11 +116,11 @@
 
     def test_edition_form(self):
         rset = self.execute('CWUser X LIMIT 1')
-        form = self.vreg.select_object('forms', 'edition', rset.req, rset,
-                                       row=0, col=0)
+        form = self.vreg['forms'].select('edition', rset.req, rset=rset,
+                                row=0, col=0)
         # should be also selectable by specifying entity
-        self.vreg.select_object('forms', 'edition', self.request(), None,
-                                entity=rset.get_entity(0, 0))
+        self.vreg['forms'].select('edition', rset.req,
+                         entity=rset.get_entity(0, 0))
         self.failIf(any(f for f in form.fields if f is None))
 
 
@@ -158,3 +160,4 @@
 
 if __name__ == '__main__':
     unittest_main()
+
--- a/web/test/unittest_views_navigation.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_navigation.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,57 +16,82 @@
 
 class NavigationTC(EnvBasedTC):
 
-    def test_navigation_selection(self):
+    def test_navigation_selection_whatever(self):
+        req = self.request()
         rset = self.execute('Any X,N WHERE X name N')
-        req = self.request()
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, PageNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, PageNavigation)
         req.set_search_state('normal')
+
+    def test_navigation_selection_ordered(self):
+        req = self.request()
         rset = self.execute('Any X,N ORDERBY N WHERE X name N')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('normal')
+        html = navcomp.render()
+
+    def test_navigation_selection_not_enough(self):
+        req = self.request()
         rset = self.execute('Any X,N LIMIT 10 WHERE X name N')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('normal')
+
+    def test_navigation_selection_not_enough(self):
+        req = self.request()
         rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
 
-
-    def test_sorted_navigation(self):
-        rset = self.execute('Any X,N ORDERBY N WHERE X name N')
+    def test_navigation_selection_wrong_boundary(self):
+        req = self.request()
+        rset = self.execute('Any X,N WHERE X name N')
         req = self.request()
-        req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_component('navigation', rset.req, rset)
+        req.form['__start'] = 1000000
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
+
+    def test_sorted_navigation_1(self):
+        req = self.request()
         rset = self.execute('Any RDEF ORDERBY RT WHERE RDEF relation_type RT')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
+
+    def test_sorted_navigation_2(self):
+        req = self.request()
         rset = self.execute('Any RDEF ORDERBY RDEF WHERE RDEF relation_type RT')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
+
+    def test_sorted_navigation_3(self):
+        req = self.request()
         rset = self.execute('CWAttribute RDEF ORDERBY RDEF')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
+
+    def test_sorted_navigation_4(self):
+        req = self.request()
         rset = self.execute('Any RDEF ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select_component('navigation', req, rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
+
+    def test_sorted_navigation_5(self):
+        req = self.request()
         rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select_component('navigation', rset.req, rset)
+        navcomp = self.vreg['components'].select('navigation', rset.req, rset=rset)
         html = navcomp.render()
 
 
@@ -77,13 +102,13 @@
         view = mock_object(is_primary=lambda x: True)
         rset = self.execute('CWUser X LIMIT 1')
         req = self.request()
-        objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
-                                           view=view, context='navtop')
+        objs = self.vreg['contentnavigation'].possible_vobjects(
+            req, rset=rset, view=view, context='navtop')
         # breadcrumbs should be in headers by default
         clsids = set(obj.id for obj in objs)
         self.failUnless('breadcrumbs' in clsids)
-        objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
-                                          view=view, context='navbottom')
+        objs = self.vreg['contentnavigation'].possible_vobjects(
+            req, rset=rset, view=view, context='navbottom')
         # breadcrumbs should _NOT_ be in footers by default
         clsids = set(obj.id for obj in objs)
         self.failIf('breadcrumbs' in clsids)
@@ -91,13 +116,13 @@
                      'P value "navbottom"')
         # breadcrumbs should now be in footers
         req.cnx.commit()
-        objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
-                                          view=view, context='navbottom')
+        objs = self.vreg['contentnavigation'].possible_vobjects(
+            req, rset=rset, view=view, context='navbottom')
 
         clsids = [obj.id for obj in objs]
         self.failUnless('breadcrumbs' in clsids)
-        objs = self.vreg.possible_vobjects('contentnavigation', req, rset,
-                                          view=view, context='navtop')
+        objs = self.vreg['contentnavigation'].possible_vobjects(
+            req, rset=rset, view=view, context='navtop')
 
         clsids = [obj.id for obj in objs]
         self.failIf('breadcrumbs' in clsids)
--- a/web/test/unittest_views_pyviews.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_views_pyviews.py	Fri Aug 07 12:20:50 2009 +0200
@@ -4,9 +4,9 @@
 class PyViewsTC(EnvBasedTC):
 
     def test_pyvaltable(self):
-        content = self.vreg.view('pyvaltable', self.request(),
-                                 pyvalue=[[1, 'a'], [2, 'b']],
-                                 headers=['num', 'char'])
+        content = self.vreg['views'].render('pyvaltable', self.request(),
+                                            pyvalue=[[1, 'a'], [2, 'b']],
+                                            headers=['num', 'char'])
         self.assertEquals(content.strip(), '''<table class="listing">
 <tr><th>num</th><th>char</th></tr>
 <tr><td>1</td><td>a</td></tr>
@@ -14,8 +14,8 @@
 </table>''')
 
     def test_pyvallist(self):
-        content = self.vreg.view('pyvallist', self.request(),
-                                 pyvalue=[1, 'a'])
+        content = self.vreg['views'].render('pyvallist', self.request(),
+                                            pyvalue=[1, 'a'])
         self.assertEquals(content.strip(), '''<ul>
 <li>1</li>
 <li>a</li>
--- a/web/test/unittest_viewselector.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_viewselector.py	Fri Aug 07 12:20:50 2009 +0200
@@ -22,8 +22,9 @@
                ('logout', actions.LogoutAction)]
 SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction),
                ('manage', actions.ManageAction),
-               ('schema', schema.ViewSchemaAction)]
-
+               ('schema', schema.ViewSchemaAction),
+               ('siteinfo', actions.SiteInfoAction),
+               ]
 
 class ViewSelectorTC(EnvBasedTC):
 
@@ -34,7 +35,7 @@
         self.add_entity('Tag', name=u'x')
 
     def pactions(self, req, rset):
-        resdict = self.vreg.possible_actions(req, rset)
+        resdict = self.vreg['actions'].possible_actions(req, rset)
         for cat, actions in resdict.items():
             resdict[cat] = [(a.id, a.__class__) for a in actions]
         return resdict
@@ -73,7 +74,7 @@
                               ('manage', startup.ManageView),
                               ('owl', owl.OWLView),
                               ('propertiesform', cwproperties.CWPropertiesForm),
-                              ('schema', startup.SchemaView),
+                              ('schema', schema.SchemaView),
                               ('systempropertiesform', cwproperties.SystemCWPropertiesForm)])
 
     def test_possible_views_noresult(self):
@@ -84,7 +85,8 @@
     def test_possible_views_one_egroup(self):
         rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"')
         self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
+                             [('adaptedlist', baseviews.AdaptedListView),
+                              ('csvexport', csvexport.CSVRsetView),
                               ('ecsvexport', csvexport.CSVEntityView),
                               ('editable-table', tableview.EditableTableView),
                               ('filetree', treeview.FileTreeView),
@@ -106,7 +108,8 @@
     def test_possible_views_multiple_egroups(self):
         rset, req = self.env.get_rset_and_req('CWGroup X')
         self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
+                             [('adaptedlist', baseviews.AdaptedListView),
+                              ('csvexport', csvexport.CSVRsetView),
                               ('ecsvexport', csvexport.CSVEntityView),
                               ('editable-table', tableview.EditableTableView),
                               ('filetree', treeview.FileTreeView),
@@ -129,26 +132,26 @@
         assert self.vreg['views']['propertiesform']
         rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
         rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
-        self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
-        self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=rset1))
-        self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+        self.failUnless(self.vreg['views'].select('propertiesform', req1, rset=None))
+        self.failUnless(self.vreg['views'].select('propertiesform', req1, rset=rset1))
+        self.failUnless(self.vreg['views'].select('propertiesform', req2, rset=rset2))
 
     def test_propertiesform_anon(self):
         self.login('anon')
         rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
         rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
-        self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=None)
-        self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
-        self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset2)
+        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=None)
+        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset1)
+        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset2)
 
     def test_propertiesform_jdoe(self):
         self.create_user('jdoe')
         self.login('jdoe')
         rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
         rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "jdoe"')
-        self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
-        self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
-        self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+        self.failUnless(self.vreg['views'].select('propertiesform', req1, rset=None))
+        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset1)
+        self.failUnless(self.vreg['views'].select('propertiesform', req2, rset=rset2))
 
     def test_possible_views_multiple_different_types(self):
         rset, req = self.env.get_rset_and_req('Any X')
@@ -184,7 +187,8 @@
     def test_possible_views_multiple_eusers(self):
         rset, req = self.env.get_rset_and_req('CWUser X')
         self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
+                             [('adaptedlist', baseviews.AdaptedListView),
+                              ('csvexport', csvexport.CSVRsetView),
                               ('ecsvexport', csvexport.CSVEntityView),
                               ('editable-table', tableview.EditableTableView),
                               ('filetree', treeview.FileTreeView),
@@ -201,6 +205,7 @@
                               ('text', baseviews.TextView),
                               ('treeview', treeview.TreeView),
                               ('vcard', vcard.VCardCWUserView),
+                              ('wfhistory', workflow.WFHistoryView),
                               ('xbel', xbel.XbelView),
                               ('xml', xmlrss.XMLView),
                               ])
@@ -262,103 +267,103 @@
         req = self.request()
         # creation form
         req.form['etype'] = 'CWGroup'
-        self.assertIsInstance(self.vreg.select_view('creation', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
                               editforms.CreationFormView)
         del req.form['etype']
         # custom creation form
         class CWUserCreationForm(editforms.CreationFormView):
             __select__ = specified_etype_implements('CWUser')
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(CWUserCreationForm)
+        self.vreg.register_appobject_class(CWUserCreationForm)
         req.form['etype'] = 'CWUser'
-        self.assertIsInstance(self.vreg.select_view('creation', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
                               CWUserCreationForm)
 
     def test_select_view(self):
         # no entity
         rset = None
         req = self.request()
-        self.assertIsInstance(self.vreg.select_view('index', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('index', req, rset=rset),
                              startup.IndexView)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'primary', req, rset)
+                             self.vreg['views'].select, 'primary', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'table', req, rset)
+                             self.vreg['views'].select, 'table', req, rset=rset)
 
         # no entity
         rset, req = self.env.get_rset_and_req('Any X WHERE X eid 999999')
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'index', req, rset)
+                              self.vreg['views'].select, 'index', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'creation', req, rset)
+                              self.vreg['views'].select, 'creation', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'primary', req, rset)
+                              self.vreg['views'].select, 'primary', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'table', req, rset)
+                             self.vreg['views'].select, 'table', req, rset=rset)
         # one entity
         rset, req = self.env.get_rset_and_req('CWGroup X WHERE X name "managers"')
-        self.assertIsInstance(self.vreg.select_view('primary', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
                              primary.PrimaryView)
-        self.assertIsInstance(self.vreg.select_view('list', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
                              baseviews.ListView)
-        self.assertIsInstance(self.vreg.select_view('edition', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('edition', req, rset=rset),
                              editforms.EditionFormView)
-        self.assertIsInstance(self.vreg.select_view('table', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                              tableview.TableView)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'creation', req, rset)
+                              self.vreg['views'].select, 'creation', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'index', req, rset)
+                              self.vreg['views'].select, 'index', req, rset=rset)
         # list of entities of the same type
         rset, req = self.env.get_rset_and_req('CWGroup X')
-        self.assertIsInstance(self.vreg.select_view('primary', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
                              primary.PrimaryView)
-        self.assertIsInstance(self.vreg.select_view('list', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
                              baseviews.ListView)
-        self.assertIsInstance(self.vreg.select_view('table', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                              tableview.TableView)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'creation', req, rset)
+                              self.vreg['views'].select, 'creation', req, rset=rset)
         # list of entities of different types
         rset, req = self.env.get_rset_and_req('Any X')
-        self.assertIsInstance(self.vreg.select_view('primary', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
                                   primary.PrimaryView)
-        self.assertIsInstance(self.vreg.select_view('list', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
                                   baseviews.ListView)
-        self.assertIsInstance(self.vreg.select_view('table', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                                   tableview.TableView)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'creation', req, rset)
+                             self.vreg['views'].select, 'creation', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'index', req, rset)
+                              self.vreg['views'].select, 'index', req, rset=rset)
         # whatever
         rset, req = self.env.get_rset_and_req('Any N, X WHERE X in_group Y, Y name N')
-        self.assertIsInstance(self.vreg.select_view('table', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                                   tableview.TableView)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'index', req, rset)
+                              self.vreg['views'].select, 'index', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'creation', req, rset)
+                              self.vreg['views'].select, 'creation', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'primary', req, rset)
+                             self.vreg['views'].select, 'primary', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'list', req, rset)
+                             self.vreg['views'].select, 'list', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                             self.vreg.select_view, 'edition', req, rset)
+                             self.vreg['views'].select, 'edition', req, rset=rset)
         # mixed query
         rset, req = self.env.get_rset_and_req('Any U,G WHERE U is CWUser, G is CWGroup')
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'edition', req, rset)
+                              self.vreg['views'].select, 'edition', req, rset=rset)
         self.failUnlessRaises(NoSelectableObject,
-                              self.vreg.select_view, 'creation', req, rset)
-        self.assertIsInstance(self.vreg.select_view('table', req, rset),
+                              self.vreg['views'].select, 'creation', req, rset=rset)
+        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                               tableview.TableView)
 
     def test_interface_selector(self):
         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
         # image primary view priority
         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
-        self.assertIsInstance(self.vreg.select_view('primary', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
                               idownloadable.IDownloadablePrimaryView)
 
 
@@ -366,12 +371,12 @@
         image = self.add_entity('Image', name=u'bim.png', data=Binary('bim'))
         # image primary view priority
         rset, req = self.env.get_rset_and_req('Image X WHERE X name "bim.png"')
-        self.assertIsInstance(self.vreg.select_view('image', req, rset),
+        self.assertIsInstance(self.vreg['views'].select('image', req, rset=rset),
                               idownloadable.ImageView)
         fileobj = self.add_entity('File', name=u'bim.txt', data=Binary('bim'))
         # image primary view priority
         rset, req = self.env.get_rset_and_req('File X WHERE X name "bim.txt"')
-        self.assertRaises(NoSelectableObject, self.vreg.select_view, 'image', req, rset)
+        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
 
 
 
@@ -382,7 +387,7 @@
         else:
             rset, req = self.env.get_rset_and_req(rql)
         try:
-            self.vreg.render('views', vid, req, rset=rset, **args)
+            self.vreg['views'].render(vid, req, rset=rset, **args)
         except:
             print vid, rset, args
             raise
@@ -426,11 +431,11 @@
     def setUp(self):
         super(RQLActionTC, self).setUp()
         self.vreg._loadedmods[__name__] = {}
-        self.vreg.register_vobject_class(CWETypeRQLAction)
+        self.vreg.register_appobject_class(CWETypeRQLAction)
 
     def tearDown(self):
         super(RQLActionTC, self).tearDown()
-        del self.vreg._registries['actions']['testaction']
+        del self.vreg['actions']['testaction']
 
     def test(self):
         rset, req = self.env.get_rset_and_req('CWEType X WHERE X name "CWEType"')
--- a/web/test/unittest_web.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/test/unittest_web.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,19 +6,17 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 from logilab.common.testlib import TestCase, unittest_main
-from cubicweb.web import ajax_replace_url as  arurl
+from cubicweb.devtools.fake import FakeRequest
 class AjaxReplaceUrlTC(TestCase):
 
     def test_ajax_replace_url(self):
+        req = FakeRequest()
+        arurl = req.build_ajax_replace_url
         # NOTE: for the simplest use cases, we could use doctest
-        self.assertEquals(arurl('foo', 'Person P'),
-                          "javascript: replacePageChunk('foo', 'Person%20P');")
-        self.assertEquals(arurl('foo', 'Person P', 'oneline'),
-                          "javascript: replacePageChunk('foo', 'Person%20P', 'oneline');")
+        self.assertEquals(arurl('foo', 'Person P', 'list'),
+                          "javascript: loadxhtml('foo', 'http://testing.fr/cubicweb/view?rql=Person%20P&amp;__notemplate=1&amp;vid=list', 'replace')")
         self.assertEquals(arurl('foo', 'Person P', 'oneline', name='bar', age=12),
-                          'javascript: replacePageChunk(\'foo\', \'Person%20P\', \'oneline\', {"age": 12, "name": "bar"});')
-        self.assertEquals(arurl('foo', 'Person P', name='bar', age=12),
-                          'javascript: replacePageChunk(\'foo\', \'Person%20P\', \'null\', {"age": 12, "name": "bar"});')
+                          '''javascript: loadxhtml('foo', 'http://testing.fr/cubicweb/view?age=12&amp;rql=Person%20P&amp;__notemplate=1&amp;vid=oneline&amp;name=bar', 'replace')''')
 
 
 if __name__ == '__main__':
--- a/web/uicfg.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/uicfg.py	Fri Aug 07 12:20:50 2009 +0200
@@ -67,7 +67,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from cubicweb import neg_role
+from cubicweb import neg_role, onevent
 from cubicweb.rtags import (RelationTags, RelationTagsBool,
                             RelationTagsSet, RelationTagsDict)
 from cubicweb.web import formwidgets
@@ -86,7 +86,8 @@
         card = card_from_role(rschema.rproperty(sschema, oschema, 'cardinality'), role)
         composed = rschema.rproperty(sschema, oschema, 'composite') == neg_role(role)
         if rschema.is_final():
-            if rschema.meta or oschema.type in ('Password', 'Bytes'):
+            if rschema.meta or sschema.is_metadata(rschema) \
+                    or oschema.type in ('Password', 'Bytes'):
                 section = 'hidden'
             else:
                 section = 'attributes'
@@ -102,21 +103,6 @@
                                    init_primaryview_section,
                                    frozenset(('attributes', 'relations',
                                                'sideboxes', 'hidden')))
-for rtype in ('eid', 'creation_date', 'modification_date',
-              'is', 'is_instance_of', 'identity',
-              'owned_by', 'created_by',
-              'in_state', 'wf_info_for', 'require_permission',
-              'from_entity', 'to_entity',
-              'see_also'):
-    primaryview_section.tag_subject_of(('*', rtype, '*'), 'hidden')
-    primaryview_section.tag_object_of(('*', rtype, '*'), 'hidden')
-primaryview_section.tag_subject_of(('*', 'use_email', '*'), 'attributes')
-primaryview_section.tag_subject_of(('*', 'primary_email', '*'), 'hidden')
-
-for attr in ('name', 'meta', 'final'):
-    primaryview_section.tag_attribute(('CWEType', attr), 'hidden')
-for attr in ('name', 'meta', 'final', 'symetric', 'inlined'):
-    primaryview_section.tag_attribute(('CWRType', attr), 'hidden')
 
 
 class DisplayCtrlRelationTags(RelationTagsDict):
@@ -158,7 +144,6 @@
 primaryview_display_ctrl = DisplayCtrlRelationTags('primaryview_display_ctrl',
                                                    init_primaryview_display_ctrl)
 
-
 # index view configuration ####################################################
 # entity type section in the index/manage page. May be one of
 # * 'application'
@@ -166,7 +151,11 @@
 # * 'schema'
 # * 'subobject' (not displayed by default)
 
-indexview_etype_section = {'EmailAddress': 'subobject'}
+indexview_etype_section = {'EmailAddress': 'subobject',
+                           'CWUser': 'system',
+                           'CWGroup': 'system',
+                           'CWPermission': 'system',
+                           }
 
 
 # autoform.AutomaticEntityForm configuration ##################################
@@ -182,7 +171,7 @@
             card = rschema.rproperty(sschema, oschema, 'cardinality')[1]
             composed = rschema.rproperty(sschema, oschema, 'composite') == 'subject'
         if sschema.is_metadata(rschema):
-            section = 'generated'
+            section = 'metadata'
         elif card in '1+':
             if not rschema.is_final() and composed:
                 section = 'generated'
@@ -197,61 +186,17 @@
 autoform_section = RelationTags('autoform_section', init_autoform_section,
                                 set(('primary', 'secondary', 'generic',
                                      'metadata', 'generated')))
-# use primary and not generated for eid since it has to be an hidden
-autoform_section.tag_attribute(('*', 'eid'), 'primary')
-autoform_section.tag_attribute(('*', 'description'), 'secondary')
-autoform_section.tag_attribute(('*', 'creation_date'), 'metadata')
-autoform_section.tag_attribute(('*', 'modification_date'), 'metadata')
-autoform_section.tag_attribute(('*', 'has_text'), 'generated')
-autoform_section.tag_subject_of(('*', 'in_state', '*'), 'primary')
-autoform_section.tag_subject_of(('*', 'owned_by', '*'), 'metadata')
-autoform_section.tag_subject_of(('*', 'created_by', '*'), 'metadata')
-autoform_section.tag_subject_of(('*', 'is', '*'), 'generated')
-autoform_section.tag_object_of(('*', 'is', '*'), 'generated')
-autoform_section.tag_subject_of(('*', 'is_instance_of', '*'), 'generated')
-autoform_section.tag_object_of(('*', 'is_instance_of', '*'), 'generated')
-autoform_section.tag_subject_of(('*', 'identity', '*'), 'generated')
-autoform_section.tag_object_of(('*', 'identity', '*'), 'generated')
-autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated')
-autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'generated')
-autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated')
-autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated')
-autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated')
-autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary')
-autoform_section.tag_attribute(('CWEType', 'final'), 'generated')
-autoform_section.tag_attribute(('CWRType', 'final'), 'generated')
-autoform_section.tag_attribute(('CWUser', 'firstname'), 'secondary')
-autoform_section.tag_attribute(('CWUser', 'surname'), 'secondary')
-autoform_section.tag_attribute(('CWUser', 'last_login_time'), 'metadata')
-autoform_section.tag_subject_of(('CWUser', 'in_group', '*'), 'primary')
-autoform_section.tag_object_of(('*', 'owned_by', 'CWUser'), 'generated')
-autoform_section.tag_object_of(('*', 'created_by', 'CWUser'), 'generated')
-autoform_section.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'metadata')
-autoform_section.tag_attribute(('Bookmark', 'path'), 'primary')
-autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually
-autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic')
-
 
 # relations'field class
 autoform_field = RelationTags('autoform_field')
 
 # relations'field explicit kwargs (given to field's __init__)
 autoform_field_kwargs = RelationTagsDict()
-autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
-                                    {'widget': formwidgets.TextInput})
-autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
-                                    {'widget': formwidgets.TextInput})
-
-
 
 # inlined view flag for non final relations: when True for an entry, the
 # entity(ies) at the other end of the relation will be editable from the
 # form of the edited entity
 autoform_is_inlined = RelationTagsBool('autoform_is_inlined')
-autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True)
-autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True)
-autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True)
-autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True)
 
 
 # set of tags of the form <action>_on_new on relations. <action> is a
@@ -259,7 +204,6 @@
 # permissions checking is by-passed and supposed to be ok
 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides')
 
-
 # boxes.EditBox configuration #################################################
 
 # 'link' / 'create' relation tags, used to control the "add entity" submenu
@@ -272,28 +216,14 @@
 
 actionbox_appearsin_addmenu = RelationTagsBool('actionbox_appearsin_addmenu',
                                                init_actionbox_appearsin_addmenu)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'is', '*'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'is', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'is_instance_of', '*'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'is_instance_of', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'identity', '*'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'identity', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'owned_by', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'created_by', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'require_permission', '*'), False)
-actionbox_appearsin_addmenu.tag_subject_of(('*', 'wf_info_for', '*'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'wf_info_for', '*'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'state_of', 'CWEType'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'transition_of', 'CWEType'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'relation_type', 'CWRType'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'from_entity', 'CWEType'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'to_entity', 'CWEType'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'in_group', 'CWGroup'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'owned_by', 'CWUser'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'created_by', 'CWUser'), False)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'bookmarked_by', 'CWUser'), True)
-actionbox_appearsin_addmenu.tag_subject_of(('Transition', 'destination_state', '*'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'allowed_transition', 'Transition'), True)
-actionbox_appearsin_addmenu.tag_object_of(('*', 'destination_state', 'State'), True)
-actionbox_appearsin_addmenu.tag_subject_of(('State', 'allowed_transition', '*'), True)
 
+@onevent('before-registry-reload')
+def clear_rtag_objects():
+    primaryview_section.clear()
+    primaryview_display_ctrl.clear()
+    autoform_section.clear()
+    autoform_field.clear()
+    autoform_field_kwargs.clear()
+    autoform_is_inlined.clear()
+    autoform_permissions_overrides.clear()
+    actionbox_appearsin_addmenu.clear()
--- a/web/views/__init__.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/__init__.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,7 +8,7 @@
 __docformat__ = "restructuredtext en"
 
 import os
-from tempfile import mktemp
+import tempfile
 
 from rql import nodes
 
@@ -81,6 +81,8 @@
             if req.search_state[0] == 'normal':
                 return 'primary'
             return 'outofcontext-search'
+        if len(rset.column_types(0)) == 1:
+            return 'adaptedlist'
         return 'list'
     return 'table'
 
@@ -109,7 +111,7 @@
 
     def cell_call(self, row=0, col=0):
         self.row, self.col = row, col # in case one need it
-        tmpfile = mktemp('.png')
+        _, tmpfile = tempfile.mkstemp('.png')
         try:
             self._generate(tmpfile)
             self.w(open(tmpfile).read())
--- a/web/views/actions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/actions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -8,7 +8,7 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
-from cubicweb.vregistry import objectify_selector
+from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import (EntitySelector,
     one_line_rset, two_lines_rset, one_etype_rset, relation_possible,
     nonempty_rset, non_final_entity,
@@ -67,7 +67,7 @@
                 return 1
     return 0
 
-# generic primary actions #####################################################
+# generic 'main' actions #######################################################
 
 class SelectAction(Action):
     """base class for link search actions. By default apply on
@@ -147,7 +147,7 @@
         return self.build_url('view', rql=self.rset.rql, vid='muledit')
 
 
-# generic secondary actions ###################################################
+# generic "more" actions #######################################################
 
 class ManagePermissionsAction(Action):
     id = 'managepermission'
@@ -287,8 +287,41 @@
     title = _('manage')
     order = 20
 
+class SiteInfoAction(ManagersAction):
+    id = 'siteinfo'
+    title = _('info')
+    order = 30
+    __select__ = match_user_groups('users','managers')
+
 
 from logilab.common.deprecation import class_moved
 from cubicweb.web.views.bookmark import FollowAction
 FollowAction = class_moved(FollowAction)
 
+## default actions ui configuration ###########################################
+
+addmenu = uicfg.actionbox_appearsin_addmenu
+addmenu.tag_subject_of(('*', 'is', '*'), False)
+addmenu.tag_object_of(('*', 'is', '*'), False)
+addmenu.tag_subject_of(('*', 'is_instance_of', '*'), False)
+addmenu.tag_object_of(('*', 'is_instance_of', '*'), False)
+addmenu.tag_subject_of(('*', 'identity', '*'), False)
+addmenu.tag_object_of(('*', 'identity', '*'), False)
+addmenu.tag_subject_of(('*', 'owned_by', '*'), False)
+addmenu.tag_subject_of(('*', 'created_by', '*'), False)
+addmenu.tag_subject_of(('*', 'require_permission', '*'), False)
+addmenu.tag_subject_of(('*', 'wf_info_for', '*'), False)
+addmenu.tag_object_of(('*', 'wf_info_for', '*'), False)
+addmenu.tag_object_of(('*', 'state_of', 'CWEType'), True)
+addmenu.tag_object_of(('*', 'transition_of', 'CWEType'), True)
+addmenu.tag_object_of(('*', 'relation_type', 'CWRType'), True)
+addmenu.tag_object_of(('*', 'from_entity', 'CWEType'), False)
+addmenu.tag_object_of(('*', 'to_entity', 'CWEType'), False)
+addmenu.tag_object_of(('*', 'in_group', 'CWGroup'), True)
+addmenu.tag_object_of(('*', 'owned_by', 'CWUser'), False)
+addmenu.tag_object_of(('*', 'created_by', 'CWUser'), False)
+addmenu.tag_object_of(('*', 'bookmarked_by', 'CWUser'), True)
+addmenu.tag_subject_of(('Transition', 'destination_state', '*'), True)
+addmenu.tag_object_of(('*', 'allowed_transition', 'Transition'), True)
+addmenu.tag_object_of(('*', 'destination_state', 'State'), True)
+addmenu.tag_subject_of(('State', 'allowed_transition', '*'), True)
--- a/web/views/autoform.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/autoform.py	Fri Aug 07 12:20:50 2009 +0200
@@ -14,7 +14,7 @@
 from cubicweb.web import stdmsgs, uicfg
 from cubicweb.web.form import FieldNotFound
 from cubicweb.web.formfields import guess_field
-from cubicweb.web.formwidgets import Button, SubmitButton
+from cubicweb.web import formwidgets
 from cubicweb.web.views import forms, editforms
 
 
@@ -33,9 +33,9 @@
     cwtarget = 'eformframe'
     cssclass = 'entityForm'
     copy_nav_params = True
-    form_buttons = [SubmitButton(),
-                    Button(stdmsgs.BUTTON_APPLY, cwaction='apply'),
-                    Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
+    form_buttons = [formwidgets.SubmitButton(),
+                    formwidgets.Button(stdmsgs.BUTTON_APPLY, cwaction='apply'),
+                    formwidgets.Button(stdmsgs.BUTTON_CANCEL, cwaction='cancel')]
     attrcategories = ('primary', 'secondary')
     # class attributes below are actually stored in the uicfg module since we
     # don't want them to be reloaded
@@ -307,3 +307,51 @@
 def etype_relation_field(etype, rtype, role='subject'):
     eschema = AutomaticEntityForm.schema.eschema(etype)
     return AutomaticEntityForm.field_by_name(rtype, role, eschema)
+
+
+## default form ui configuration ##############################################
+
+# use primary and not generated for eid since it has to be an hidden
+uicfg.autoform_section.tag_attribute(('*', 'eid'), 'primary')
+uicfg.autoform_section.tag_attribute(('*', 'description'), 'secondary')
+uicfg.autoform_section.tag_attribute(('*', 'creation_date'), 'metadata')
+uicfg.autoform_section.tag_attribute(('*', 'modification_date'), 'metadata')
+uicfg.autoform_section.tag_attribute(('*', 'cwuri'), 'metadata')
+uicfg.autoform_section.tag_attribute(('*', 'has_text'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'in_state', '*'), 'primary')
+uicfg.autoform_section.tag_subject_of(('*', 'owned_by', '*'), 'metadata')
+uicfg.autoform_section.tag_subject_of(('*', 'created_by', '*'), 'metadata')
+uicfg.autoform_section.tag_subject_of(('*', 'is', '*'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'is', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'is_instance_of', '*'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'is_instance_of', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'identity', '*'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'identity', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'require_permission', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'wf_info_for', '*'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'wf_info_for', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('*', 'for_user', '*'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'for_user', '*'), 'generated')
+uicfg.autoform_section.tag_subject_of(('CWPermission', 'require_group', '*'), 'primary')
+uicfg.autoform_section.tag_attribute(('CWEType', 'final'), 'generated')
+uicfg.autoform_section.tag_attribute(('CWRType', 'final'), 'generated')
+uicfg.autoform_section.tag_attribute(('CWUser', 'firstname'), 'secondary')
+uicfg.autoform_section.tag_attribute(('CWUser', 'surname'), 'secondary')
+uicfg.autoform_section.tag_attribute(('CWUser', 'last_login_time'), 'metadata')
+uicfg.autoform_section.tag_subject_of(('CWUser', 'in_group', '*'), 'primary')
+uicfg.autoform_section.tag_object_of(('*', 'owned_by', 'CWUser'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'created_by', 'CWUser'), 'generated')
+uicfg.autoform_section.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'metadata')
+uicfg.autoform_section.tag_attribute(('Bookmark', 'path'), 'primary')
+uicfg.autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually
+uicfg.autoform_section.tag_subject_of(('*', 'primary_email', '*'), 'generic')
+
+uicfg.autoform_field_kwargs.tag_attribute(('RQLExpression', 'expression'),
+                                          {'widget': formwidgets.TextInput})
+uicfg.autoform_field_kwargs.tag_attribute(('Bookmark', 'path'),
+                                          {'widget': formwidgets.TextInput})
+
+uicfg.autoform_is_inlined.tag_subject_of(('*', 'use_email', '*'), True)
+uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'relation_type', '*'), True)
+uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'from_entity', '*'), True)
+uicfg.autoform_is_inlined.tag_subject_of(('CWRelation', 'to_entity', '*'), True)
--- a/web/views/basecomponents.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/basecomponents.py	Fri Aug 07 12:20:50 2009 +0200
@@ -57,7 +57,7 @@
 
 
 class ApplLogo(component.Component):
-    """build the application logo, usually displayed in the header"""
+    """build the instance logo, usually displayed in the header"""
     id = 'logo'
     property_defs = VISIBLE_PROP_DEF
     # don't want user to hide this component using an cwproperty
@@ -90,7 +90,7 @@
     def call(self):
         if not self.req.cnx.anonymous_connection:
             # display useractions and siteactions
-            actions = self.vreg.possible_actions(self.req, self.rset)
+            actions = self.vreg['actions'].possible_actions(self.req, rset=self.rset)
             box = MenuWidget('', 'userActionsBox', _class='', islist=False)
             menu = PopupBoxMenu(self.req.user.login, isitem=False)
             box.append(menu)
@@ -118,8 +118,8 @@
 
 
 class ApplicationMessage(component.Component):
-    """display application's messages given using the __message parameter
-    into a special div section
+    """display messages given using the __message parameter into a special div
+    section
     """
     __select__ = yes()
     id = 'applmessages'
@@ -138,7 +138,7 @@
 
 
 class ApplicationName(component.Component):
-    """display the application name"""
+    """display the instance name"""
     id = 'appliname'
     property_defs = VISIBLE_PROP_DEF
     # don't want user to hide this component using an cwproperty
--- a/web/views/basecontrollers.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/basecontrollers.py	Fri Aug 07 12:20:50 2009 +0200
@@ -15,7 +15,6 @@
 import simplejson
 
 from logilab.common.decorators import cached
-from logilab.mtconverter import xml_escape
 
 from cubicweb import NoSelectableObject, ValidationError, ObjectNotFound, typed_eid
 from cubicweb.utils import strptime
@@ -33,16 +32,6 @@
 except ImportError: # gae
     HAS_SEARCH_RESTRICTION = False
 
-
-def xhtml_wrap(self, source):
-    # XXX factor out, watch view.py ~ Maintemplate.doctype
-    if self.req.xhtml_browser():
-        dt = STRICT_DOCTYPE
-    else:
-        dt = STRICT_DOCTYPE_NOEXT
-    head = u'<?xml version="1.0"?>\n' + dt
-    return head + u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">%s</div>' % source.strip()
-
 def jsonize(func):
     """decorator to sets correct content_type and calls `simplejson.dumps` on
     results
@@ -58,7 +47,8 @@
     def wrapper(self, *args, **kwargs):
         self.req.set_content_type(self.req.html_content_type())
         result = func(self, *args, **kwargs)
-        return xhtml_wrap(self, result)
+        return ''.join((self.req.document_surrounding_div(), result.strip(),
+                        u'</div>'))
     wrapper.__name__ = func.__name__
     return wrapper
 
@@ -78,7 +68,7 @@
     id = 'login'
 
     def publish(self, rset=None):
-        """log in the application"""
+        """log in the instance"""
         if self.config['auth-mode'] == 'http':
             # HTTP authentication
             raise ExplicitLogin()
@@ -91,7 +81,7 @@
     id = 'logout'
 
     def publish(self, rset=None):
-        """logout from the application"""
+        """logout from the instance"""
         return self.appli.session_handler.logout(self.req)
 
 
@@ -109,7 +99,8 @@
         self.add_to_breadcrumbs(view)
         self.validate_cache(view)
         template = self.appli.main_template_id(self.req)
-        return self.vreg.main_template(self.req, template, rset=rset, view=view)
+        return self.vreg['views'].main_template(self.req, template,
+                                                rset=rset, view=view)
 
     def _select_view_and_rset(self, rset):
         req = self.req
@@ -128,12 +119,12 @@
                 req.set_message(req._("error while handling __method: %s") % req._(ex))
         vid = req.form.get('vid') or vid_from_rset(req, rset, self.schema)
         try:
-            view = self.vreg.select_view(vid, req, rset)
+            view = self.vreg['views'].select(vid, req, rset=rset)
         except ObjectNotFound:
             self.warning("the view %s could not be found", vid)
             req.set_message(req._("The view %s could not be found") % vid)
             vid = vid_from_rset(req, rset, self.schema)
-            view = self.vreg.select_view(vid, req, rset)
+            view = self.vreg['views'].select(vid, req, rset=rset)
         except NoSelectableObject:
             if rset:
                 req.set_message(req._("The view %s can not be applied to this query") % vid)
@@ -141,7 +132,7 @@
                 req.set_message(req._("You have no access to this view or it's not applyable to current data"))
             self.warning("the view %s can not be applied to this query", vid)
             vid = vid_from_rset(req, rset, self.schema)
-            view = self.vreg.select_view(vid, req, rset)
+            view = self.vreg['views'].select(vid, req, rset=rset)
         return view, rset
 
     def add_to_breadcrumbs(self, view):
@@ -179,6 +170,7 @@
 
 
 def _validation_error(req, ex):
+    req.cnx.rollback()
     forminfo = req.get_session_data(req.form.get('__errorurl'), pop=True)
     foreid = ex.entity
     eidmap = req.data.get('eidmap', {})
@@ -191,20 +183,17 @@
 def _validate_form(req, vreg):
     # XXX should use the `RemoteCallFailed` mechanism
     try:
-        ctrl = vreg.select(vreg.registry_objects('controllers', 'edit'),
-                           req=req)
+        ctrl = vreg['controllers'].select('edit', req=req)
     except NoSelectableObject:
         return (False, {None: req._('not authorized')})
     try:
         ctrl.publish(None)
     except ValidationError, ex:
-        req.cnx.rollback()
         return (False, _validation_error(req, ex))
     except Redirect, ex:
         try:
             req.cnx.commit() # ValidationError may be raise on commit
         except ValidationError, ex:
-            req.cnx.rollback()
             return (False, _validation_error(req, ex))
         else:
             return (True, ex.location)
@@ -218,18 +207,21 @@
 class FormValidatorController(Controller):
     id = 'validateform'
 
+    def response(self, domid, status, args):
+        self.req.set_content_type('text/html')
+        jsargs = simplejson.dumps( (status, args) )
+        return """<script type="text/javascript">
+ window.parent.handleFormValidationResponse('%s', null, null, %s);
+</script>""" %  (domid, jsargs)
+
     def publish(self, rset=None):
         self.req.json_request = True
         # XXX unclear why we have a separated controller here vs
         # js_validate_form on the json controller
         status, args = _validate_form(self.req, self.vreg)
-        self.req.set_content_type('text/html')
-        jsarg = simplejson.dumps( (status, args) )
         domid = self.req.form.get('__domid', 'entityForm').encode(
             self.req.encoding)
-        return """<script type="text/javascript">
- window.parent.handleFormValidationResponse('%s', null, null, %s);
-</script>""" %  (domid, simplejson.dumps( (status, args) ))
+        return self.response(domid, status, args)
 
 
 class JSonController(Controller):
@@ -263,6 +255,8 @@
         except RemoteCallFailed:
             raise
         except Exception, ex:
+            import traceback
+            traceback.print_exc()
             self.exception('an exception occured while calling js_%s(%s): %s',
                            fname, args, ex)
             raise RemoteCallFailed(repr(ex))
@@ -315,10 +309,10 @@
             rset = None
         vid = req.form.get('vid') or vid_from_rset(req, rset, self.schema)
         try:
-            view = self.vreg.select_view(vid, req, rset)
+            view = self.vreg['views'].select(vid, req, rset=rset)
         except NoSelectableObject:
             vid = req.form.get('fallbackvid', 'noresult')
-            view = self.vreg.select_view(vid, req, rset)
+            view = self.vreg['views'].select(vid, req, rset=rset)
         divid = req.form.get('divid', 'pageContent')
         # we need to call pagination before with the stream set
         stream = view.set_stream()
@@ -345,11 +339,10 @@
     @xhtmlize
     def js_prop_widget(self, propkey, varname, tabindex=None):
         """specific method for CWProperty handling"""
-        entity = self.vreg.etype_class('CWProperty')(self.req, None, None)
+        entity = self.vreg['etypes'].etype_class('CWProperty')(self.req)
         entity.eid = varname
         entity['pkey'] = propkey
-        form = self.vreg.select_object('forms', 'edition', self.req, None,
-                                       entity=entity)
+        form = self.vreg['forms'].select('edition', self.req, entity=entity)
         form.form_build_context()
         vfield = form.field_by_name('value')
         renderer = FormRenderer(self.req)
@@ -362,7 +355,7 @@
             rset = self._exec(rql)
         else:
             rset = None
-        comp = self.vreg.select_object(registry, compid, self.req, rset)
+        comp = self.vreg[registry].select(compid, self.req, rset=rset)
         if extraargs is None:
             extraargs = {}
         else: # we receive unicode keys which is not supported by the **syntax
@@ -374,9 +367,9 @@
     @check_pageid
     @xhtmlize
     def js_inline_creation_form(self, peid, ttype, rtype, role):
-        view = self.vreg.select_view('inline-creation', self.req, None,
-                                     etype=ttype, peid=peid, rtype=rtype,
-                                     role=role)
+        view = self.vreg['views'].select('inline-creation', self.req,
+                                         etype=ttype, peid=peid, rtype=rtype,
+                                         role=role)
         return view.render(etype=ttype, peid=peid, rtype=rtype, role=role)
 
     @jsonize
@@ -404,7 +397,7 @@
     @jsonize
     def js_reledit_form(self, eid, rtype, role, default, lzone):
         """XXX we should get rid of this and use loadxhtml"""
-        entity = self.req.eid_rset(eid).get_entity(0, 0)
+        entity = self.req.entity_from_eid(eid)
         return entity.view('reledit', rtype=rtype, role=role,
                            default=default, landing_zone=lzone)
 
@@ -570,7 +563,8 @@
         self.smtp.sendmail(helo_addr, [recipient], msg.as_string())
 
     def publish(self, rset=None):
-        # XXX this allow anybody with access to an cubicweb application to use it as a mail relay
+        # XXX this allows users with access to an cubicweb instance to use it as
+        # a mail relay
         body = self.req.form['mailbody']
         subject = self.req.form['subject']
         for recipient in self.recipients():
--- a/web/views/basetemplates.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/basetemplates.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,11 +10,12 @@
 
 from logilab.mtconverter import xml_escape
 
-from cubicweb.vregistry import objectify_selector
+from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import match_kwargs
 from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
 from cubicweb.utils import make_uid, UStringIO
 
+
 # main templates ##############################################################
 
 class LogInOutTemplate(MainTemplate):
@@ -83,15 +84,15 @@
     def call(self, view):
         view.set_request_content_type()
         view.set_stream()
-        xhtml_wrap = (self.req.form.has_key('__notemplate') and view.templatable
-                      and view.content_type == self.req.html_content_type())
-        if xhtml_wrap:
-            view.w(u'<?xml version="1.0"?>\n' + self.doctype)
-            view.w(u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">')
-        # have to replace our unicode stream using view's binary stream
-        view.render()
-        if xhtml_wrap:
+        if (self.req.form.has_key('__notemplate') and view.templatable
+            and view.content_type == self.req.html_content_type()):
+            view.w(self.req.document_surrounding_div())
+            view.render()
             view.w(u'</div>')
+        else:
+            view.render()
+        # have to replace our stream by view's stream (which may be a binary
+        # stream)
         self._stream = view._stream
 
 
@@ -112,9 +113,9 @@
         if vtitle:
             w(u'<h1 class="vtitle">%s</h1>\n' % xml_escape(vtitle))
         # display entity type restriction component
-        etypefilter = self.vreg.select_component('etypenavigation',
-                                                 self.req, self.rset)
-        if etypefilter and etypefilter.propval('visible'):
+        etypefilter = self.vreg['components'].select_vobject(
+            'etypenavigation', self.req, rset=self.rset)
+        if etypefilter:
             etypefilter.render(w=w)
         self.nav_html = UStringIO()
         if view and view.need_navigation:
@@ -137,7 +138,8 @@
         w = self.whead
         lang = self.req.lang
         self.write_doctype()
-        w(u'<base href="%s" />' % xml_escape(self.req.base_url()))
+        # explictly close the <base> tag to avoid IE 6 bugs while browsing DOM
+        w(u'<base href="%s"></base>' % xml_escape(self.req.base_url()))
         w(u'<meta http-equiv="content-type" content="%s; charset=%s"/>\n'
           % (content_type, self.req.encoding))
         w(u'\n'.join(additional_headers) + u'\n')
@@ -152,10 +154,12 @@
         w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n')
         self.nav_column(view, 'left')
         w(u'<td id="contentcol">\n')
-        rqlcomp = self.vreg.select_component('rqlinput', self.req, self.rset)
+        rqlcomp = self.vreg['components'].select_object('rqlinput', self.req,
+                                                        rset=self.rset)
         if rqlcomp:
             rqlcomp.render(w=self.w, view=view)
-        msgcomp = self.vreg.select_component('applmessages', self.req, self.rset)
+        msgcomp = self.vreg['components'].select_object('applmessages',
+                                                        self.req, rset=self.rset)
         if msgcomp:
             msgcomp.render(w=self.w)
         self.content_header(view)
@@ -169,8 +173,8 @@
         self.w(u'</body>')
 
     def nav_column(self, view, context):
-        boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
-                                                 view=view, context=context))
+        boxes = list(self.vreg['boxes'].possible_vobjects(
+            self.req, rset=self.rset, view=view, context=context))
         if boxes:
             self.w(u'<td class="navcol"><div class="navboxes">\n')
             for box in boxes:
@@ -196,7 +200,7 @@
         """display an unexpected error"""
         self.set_request_content_type()
         self.req.reset_headers()
-        view = self.vreg.select_view('error', self.req, self.rset)
+        view = self.vreg['views'].select('error', self.req, rset=self.rset)
         self.template_header(self.content_type, view, self.req._('an error occured'),
                              [NOINDEX, NOFOLLOW])
         view.render(w=self.w)
@@ -238,8 +242,8 @@
         w(u'<table width="100%" height="100%" border="0"><tr>\n')
         w(u'<td class="navcol">\n')
         self.topleft_header()
-        boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
-                                                 view=view, context='left'))
+        boxes = list(self.vreg['boxes'].possible_vobjects(
+            self.req, rset=self.rset, view=view, context='left'))
         if boxes:
             w(u'<div class="navboxes">\n')
             for box in boxes:
@@ -253,11 +257,14 @@
             w(u'<h1 class="vtitle">%s</h1>' % xml_escape(vtitle))
 
     def topleft_header(self):
-        self.w(u'<table id="header"><tr>\n')
-        self.w(u'<td>')
-        self.vreg.select_component('logo', self.req, self.rset).render(w=self.w)
-        self.w(u'</td>\n')
-        self.w(u'</tr></table>\n')
+        logo = self.vreg['components'].select_vobject('logo', self.req,
+                                                      rset=self.rset)
+        if logo:
+            self.w(u'<table id="header"><tr>\n')
+            self.w(u'<td>')
+            logo.render(w=self.w)
+            self.w(u'</td>\n')
+            self.w(u'</tr></table>\n')
 
 # page parts templates ########################################################
 
@@ -292,11 +299,11 @@
             self.req.add_js(jscript, localfile=False)
 
     def alternates(self):
-        urlgetter = self.vreg.select_component('rss_feed_url', self.req, self.rset)
+        urlgetter = self.vreg['components'].select_object('rss_feed_url',
+                                            self.req, rset=self.rset)
         if urlgetter is not None:
-            url = urlgetter.feed_url()
             self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n'
-                       %  xml_escape(url))
+                       %  xml_escape(urlgetter.feed_url()))
 
     def pageid(self):
         req = self.req
@@ -322,24 +329,29 @@
         """build the top menu with authentification info and the rql box"""
         self.w(u'<table id="header"><tr>\n')
         self.w(u'<td id="firstcolumn">')
-        self.vreg.select_component('logo', self.req, self.rset).render(w=self.w)
+        logo = self.vreg['components'].select_vobject(
+            'logo', self.req, rset=self.rset)
+        if logo:
+            logo.render(w=self.w)
         self.w(u'</td>\n')
         # appliname and breadcrumbs
         self.w(u'<td id="headtext">')
-        comp = self.vreg.select_component('appliname', self.req, self.rset)
-        if comp and comp.propval('visible'):
-            comp.render(w=self.w)
-        comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view)
-        if comp and comp.propval('visible'):
-            comp.render(w=self.w, view=view)
+        for cid in ('appliname', 'breadcrumbs'):
+            comp = self.vreg['components'].select_vobject(
+                cid, self.req, rset=self.rset)
+            if comp:
+                comp.render(w=self.w)
         self.w(u'</td>')
         # logged user and help
         self.w(u'<td>\n')
-        comp = self.vreg.select_component('loggeduserlink', self.req, self.rset)
-        comp.render(w=self.w)
+        comp = self.vreg['components'].select_vobject(
+            'loggeduserlink', self.req, rset=self.rset)
+        if comp:
+            comp.render(w=self.w)
         self.w(u'</td><td>')
-        helpcomp = self.vreg.select_component('help', self.req, self.rset)
-        if helpcomp: # may not be available if Card is not defined in the schema
+        helpcomp = self.vreg['components'].select_vobject(
+            'help', self.req, rset=self.rset)
+        if helpcomp:
             helpcomp.render(w=self.w)
         self.w(u'</td>')
         # lastcolumn
@@ -393,9 +405,8 @@
 
     def call(self, view, **kwargs):
         """by default, display informal messages in content header"""
-        components = self.vreg.possible_vobjects('contentnavigation',
-                                                 self.req, self.rset,
-                                                 view=view, context='navtop')
+        components = self.vreg['contentnavigation'].possible_vobjects(
+            self.req, rset=self.rset, view=view, context='navtop')
         if components:
             self.w(u'<div id="contentheader">')
             for comp in components:
@@ -410,9 +421,8 @@
     id = 'contentfooter'
 
     def call(self, view, **kwargs):
-        components = self.vreg.possible_vobjects('contentnavigation',
-                                                 self.req, self.rset,
-                                                 view=view, context='navbottom')
+        components = self.vreg['contentnavigation'].possible_vobjects(
+            self.req, rset=self.rset, view=view, context='navbottom')
         if components:
             self.w(u'<div id="contentfooter">')
             for comp in components:
--- a/web/views/baseviews.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/baseviews.py	Fri Aug 07 12:20:50 2009 +0200
@@ -2,7 +2,7 @@
 
 * noresult, final
 * primary, sidebox
-* secondary, oneline, incontext, outofcontext, text
+* oneline, incontext, outofcontext, text
 * list
 
 
@@ -20,7 +20,8 @@
 from logilab.mtconverter import TransformError, xml_escape, xml_escape
 
 from cubicweb import NoSelectableObject
-from cubicweb.selectors import yes, empty_rset
+from cubicweb.selectors import yes, empty_rset, one_etype_rset
+from cubicweb.schema import display_name
 from cubicweb.view import EntityView, AnyRsetView, View
 from cubicweb.common.uilib import cut, printable_value
 
@@ -100,6 +101,7 @@
         self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime))
 
 
+# XXX deprecated
 class SecondaryView(EntityView):
     id = 'secondary'
     title = _('secondary')
@@ -179,9 +181,6 @@
         self.w(u'</div>')
 
 
-# new default views for finner control in general views , to use instead of
-# oneline / secondary
-
 class InContextTextView(TextView):
     id = 'textincontext'
     title = None # not listed as a possible view
@@ -236,6 +235,7 @@
 
         :param listid: the DOM id to use for the root element
         """
+        # XXX much of the behaviour here should probably be outside this view
         if subvid is None and 'subvid' in self.req.form:
             subvid = self.req.form.pop('subvid') # consume it
         if listid:
@@ -258,28 +258,6 @@
         self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs)
         self.w(u'</li>\n')
 
-    def url(self):
-        """overrides url method so that by default, the view list is called
-        with sorted entities
-        """
-        coltypes = self.rset.column_types(0)
-        # don't want to generate the rql if there is some restriction on
-        # something else than the entity type
-        if len(coltypes) == 1:
-            # XXX norestriction is not correct here. For instance, in cases like
-            # Any P,N WHERE P is Project, P name N
-            # norestriction should equal True
-            restr = self.rset.syntax_tree().children[0].where
-            norestriction = (isinstance(restr, nodes.Relation) and
-                             restr.is_types_restriction())
-            if norestriction:
-                etype = iter(coltypes).next()
-                return self.build_url(etype.lower(), vid=self.id)
-        if len(self.rset) == 1:
-            entity = self.rset.get_entity(0, 0)
-            return self.build_url(entity.rest_path(), vid=self.id)
-        return self.build_url(rql=self.rset.printable_rql(), vid=self.id)
-
 
 class ListItemView(EntityView):
     id = 'listitem'
@@ -307,6 +285,31 @@
     redirect_vid = 'incontext'
 
 
+class AdaptedListView(EntityView):
+    """list of entities of the same type"""
+    id = 'adaptedlist'
+    __select__ = EntityView.__select__ & one_etype_rset()
+    item_vid = 'adaptedlistitem'
+
+    @property
+    def title(self):
+        etype = iter(self.rset.column_types(0)).next()
+        return display_name(self.req, etype, form='plural')
+
+    def call(self, **kwargs):
+        """display a list of entities by calling their <item_vid> view"""
+        if not 'vtitle' in self.req.form:
+            self.w(u'<h1>%s</h1>' % self.title)
+        super(AdaptedListView, self).call(**kwargs)
+
+    def cell_call(self, row, col=0, vid=None, **kwargs):
+        self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs)
+
+
+class AdaptedListItemView(ListItemView):
+    id = 'adaptedlistitem'
+
+
 class CSVView(SimpleListView):
     id = 'csv'
     redirect_vid = 'incontext'
--- a/web/views/bookmark.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/bookmark.py	Fri Aug 07 12:20:50 2009 +0200
@@ -85,7 +85,7 @@
         if eschema.has_perm(req, 'add') and rschema.has_perm(req, 'add', toeid=ueid):
             boxmenu = BoxMenu(req._('manage bookmarks'))
             linkto = 'bookmarked_by:%s:subject' % ueid
-            # use a relative path so that we can move the application without
+            # use a relative path so that we can move the instance without
             # loosing bookmarks
             path = req.relative_path()
             url = self.create_url(self.etype, __linkto=linkto, path=path)
--- a/web/views/boxes.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/boxes.py	Fri Aug 07 12:20:50 2009 +0200
@@ -51,7 +51,8 @@
                 title = u'%s - %s' % (title, etypelabel.lower())
         box = BoxWidget(title, self.id, _class="greyBoxFrame")
         # build list of actions
-        actions = self.vreg.possible_actions(self.req, self.rset, view=view)
+        actions = self.vreg['actions'].possible_actions(self.req, self.rset,
+                                                        view=view)
         add_menu = BoxMenu(_('add')) # 'addrelated' category
         other_menu = BoxMenu(_('more actions')) # 'moreactions' category
         searchstate = self.req.search_state[0]
@@ -144,20 +145,16 @@
         if 'in_state' in entity.e_schema.subject_relations() and entity.in_state:
             _ = self.req._
             state = entity.in_state[0]
-            transitions = list(state.transitions(entity))
-            if transitions:
-                menu_title = u'%s: %s' % (_('state'), state.view('text'))
-                menu_items = []
-                for tr in transitions:
-                    url = entity.absolute_url(vid='statuschange', treid=tr.eid)
-                    menu_items.append(self.mk_action(_(tr.name), url))
-                box.append(BoxMenu(menu_title, menu_items))
-            # when there are no possible transition, put state if the menu if
-            # there are some other actions
-            elif not box.is_empty():
-                menu_title = u'<a title="%s">%s: <i>%s</i></a>' % (
-                    _('no possible transition'), _('state'), state.view('text'))
-                box.append(RawBoxItem(menu_title, 'boxMainactions'))
+            menu_title = u'%s: %s' % (_('state'), state.view('text'))
+            menu_items = []
+            for tr in state.transitions(entity):
+                url = entity.absolute_url(vid='statuschange', treid=tr.eid)
+                menu_items.append(self.mk_action(_(tr.name), url))
+            wfurl = self.build_url('cwetype/%s'%entity.e_schema, vid='workflow')
+            menu_items.append(self.mk_action(_('view workflow'), wfurl))
+            wfurl = entity.absolute_url(vid='wfhistory')
+            menu_items.append(self.mk_action(_('view history'), wfurl))
+            box.append(BoxMenu(menu_title, menu_items))
         return None
 
     def linkto_url(self, entity, rtype, etype, target):
@@ -211,7 +208,8 @@
 
     def call(self, **kwargs):
         box = BoxWidget(self.req._(self.title), self.id)
-        views = [v for v in self.vreg.possible_views(self.req, self.rset)
+        views = [v for v in self.vreg['views'].possible_views(self.req,
+                                                              rset=self.rset)
                  if v.category != 'startupview']
         for category, views in self.sort_actions(views):
             menu = BoxMenu(category)
@@ -231,7 +229,7 @@
 
     def call(self, **kwargs):
         box = BoxWidget(self.req._(self.title), self.id)
-        for view in self.vreg.possible_views(self.req, None):
+        for view in self.vreg['views'].possible_views(self.req, None):
             if view.category == 'startupview':
                 box.append(self.box_action(view))
 
--- a/web/views/cwproperties.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/cwproperties.py	Fri Aug 07 12:20:50 2009 +0200
@@ -64,6 +64,7 @@
 
 
 class SystemCWPropertiesForm(FormViewMixIn, StartupView):
+    """site-wide properties edition form"""
     id = 'systempropertiesform'
     __select__ = none_rset() & match_user_groups('managers')
 
@@ -94,7 +95,6 @@
         return status
 
     def call(self, **kwargs):
-        """The default view representing the application's index"""
         self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js', 'cubicweb.ajax.js'))
         self.req.add_css('cubicweb.preferences.css')
         vreg = self.vreg
@@ -180,7 +180,7 @@
         if key in values:
             entity = self.cwprops_rset.get_entity(values[key], 0)
         else:
-            entity = self.vreg.etype_class('CWProperty')(self.req, None, None)
+            entity = self.vreg['etypes'].etype_class('CWProperty')(self.req)
             entity.eid = self.req.varmaker.next()
             entity['pkey'] = key
             entity['value'] = self.vreg.property_value(key)
@@ -188,11 +188,11 @@
 
     def form(self, formid, keys, splitlabel=False):
         buttons = [SubmitButton()]
-        form = self.vreg.select_object('forms', 'composite', self.req,
-                                  domid=formid, action=self.build_url(),
-                                  form_buttons=buttons,
-                                  onsubmit="return validatePrefsForm('%s')" % formid,
-                                  submitmsg=self.req._('changes applied'))
+        form = self.vreg['forms'].select(
+            'composite', self.req, domid=formid, action=self.build_url(),
+            form_buttons=buttons,
+            onsubmit="return validatePrefsForm('%s')" % formid,
+            submitmsg=self.req._('changes applied'))
         path = self.req.relative_path()
         if '?' in path:
             path, params = path.split('?', 1)
@@ -200,8 +200,8 @@
         form.form_add_hidden('__redirectpath', path)
         for key in keys:
             self.form_row(form, key, splitlabel)
-        renderer = self.vreg.select_object('formrenderers', 'cwproperties', self.req,
-                                           display_progress_div=False)
+        renderer = self.vreg['formrenderers'].select('cwproperties', self.req,
+                                                     display_progress_div=False)
         return form.form_render(renderer=renderer)
 
     def form_row(self, form, key, splitlabel):
@@ -210,8 +210,8 @@
             label = key.split('.')[-1]
         else:
             label = key
-        subform = self.vreg.select_object('forms', 'base', self.req, entity=entity,
-                                     mainform=False)
+        subform = self.vreg['forms'].select('base', self.req, entity=entity,
+                                            mainform=False)
         subform.append_field(PropertyValueField(name='value', label=label,
                                                 eidparam=True))
         subform.vreg = self.vreg
@@ -226,6 +226,7 @@
 
 
 class CWPropertiesForm(SystemCWPropertiesForm):
+    """user's preferences properties edition form"""
     id = 'propertiesform'
     __select__ = (
         (none_rset() & match_user_groups('users','managers'))
@@ -259,7 +260,7 @@
 
 class PlaceHolderWidget(object):
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         domid = form.context[field]['id']
         # empty span as well else html validation fail (label is refering to
         # this id)
@@ -272,7 +273,7 @@
         self.value = value
         self.msg = msg
 
-    def render(self, form, field):
+    def render(self, form, field, renderer):
         domid = form.context[field]['id']
         value = '<span class="value" id="%s">%s</span>' % (domid, self.value)
         if self.msg:
@@ -291,7 +292,7 @@
         wdg.attrs['tabindex'] = form.req.next_tabindex()
         wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % (
             form.edited_entity.eid, form.req.next_tabindex())
-        return wdg.render(form, self)
+        return wdg.render(form, self, renderer)
 
     def vocabulary(self, form):
         entity = form.edited_entity
@@ -312,7 +313,7 @@
         wdg = self.get_widget(form)
         if tabindex is not None:
             wdg.attrs['tabindex'] = tabindex
-        return wdg.render(form, self)
+        return wdg.render(form, self, renderer)
 
     def form_init(self, form):
         entity = form.edited_entity
--- a/web/views/editcontroller.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/editcontroller.py	Fri Aug 07 12:20:50 2009 +0200
@@ -53,7 +53,7 @@
             for eid in req.edited_eids():
                 formparams = req.extract_entity_params(eid)
                 if methodname is not None:
-                    entity = req.eid_rset(eid).get_entity(0, 0)
+                    entity = req.entity_from_eid(eid)
                     method = getattr(entity, methodname)
                     method(formparams)
                 eid = self.edit_entity(formparams)
@@ -81,7 +81,7 @@
     def edit_entity(self, formparams, multiple=False):
         """edit / create / copy an entity and return its eid"""
         etype = formparams['__type']
-        entity = self.vreg.etype_class(etype)(self.req, None, None)
+        entity = self.vreg['etypes'].etype_class(etype)(self.req)
         entity.eid = eid = self._get_eid(formparams['eid'])
         edited = self.req.form.get('__maineid') == formparams['eid']
         # let a chance to do some entity specific stuff.
--- a/web/views/editforms.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/editforms.py	Fri Aug 07 12:20:50 2009 +0200
@@ -17,11 +17,11 @@
 
 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
-from cubicweb.web.form import FormViewMixIn
+from cubicweb.web.form import FormViewMixIn, FieldNotFound
 from cubicweb.web.formfields import guess_field
 from cubicweb.web.formwidgets import Button, SubmitButton, ResetButton
 from cubicweb.web.views import forms
@@ -43,7 +43,31 @@
         js, nodeid, label)
 
 
-class DeleteConfForm(FormViewMixIn, EntityView):
+class DeleteConfForm(forms.CompositeForm):
+    id = 'deleteconf'
+    __select__ = non_final_entity()
+
+    domid = 'deleteconf'
+    copy_nav_params = True
+    form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
+                    Button(stdmsgs.NO, cwaction='cancel')]
+    @property
+    def action(self):
+        return self.build_url('edit')
+
+    def __init__(self, *args, **kwargs):
+        super(DeleteConfForm, self).__init__(*args, **kwargs)
+        done = set()
+        for entity in self.rset.entities():
+            if entity.eid in done:
+                continue
+            done.add(entity.eid)
+            subform = self.vreg['forms'].select('base', self.req, entity=entity,
+                                                mainform=False)
+            self.form_add_subform(subform)
+
+
+class DeleteConfFormView(FormViewMixIn, EntityView):
     """form used to confirm deletion of some entities"""
     id = 'deleteconf'
     title = _('delete')
@@ -59,20 +83,10 @@
           % _('this action is not reversible!'))
         # XXX above message should have style of a warning
         w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
-        form = self.vreg.select_object('forms', 'composite', req, domid='deleteconf',
-                                       copy_nav_params=True,
-                                       action=self.build_url('edit'), onsubmit=onsubmit,
-                                       form_buttons=[Button(stdmsgs.YES, cwaction='delete'),
-                                                     Button(stdmsgs.NO, cwaction='cancel')])
-        done = set()
+        form = self.vreg['forms'].select(self.id, req, rset=self.rset,
+                                         onsubmit=onsubmit)
         w(u'<ul>\n')
         for entity in self.rset.entities():
-            if entity.eid in done:
-                continue
-            done.add(entity.eid)
-            subform = self.vreg.select_object('forms', 'base', req, entity=entity,
-                                              mainform=False)
-            form.form_add_subform(subform)
             # don't use outofcontext view or any other that may contain inline edition form
             w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
                                       href=entity.absolute_url()))
@@ -81,25 +95,30 @@
 
 
 class ClickAndEditFormView(FormViewMixIn, EntityView):
-    """form used to permit ajax edition of an attribute of an entity in a view
+    """form used to permit ajax edition of a relation or attribute of an entity
+    in a view, if logged user have the permission to edit it.
 
-    (double-click on the field to see an appropriate edition widget)
+    (double-click on the field to see an appropriate edition widget).
     """
-    id = 'reledit'
+    id = 'doreledit'
     __select__ = non_final_entity() & match_kwargs('rtype')
     # FIXME editableField class could be toggleable from userprefs
 
+    # add metadata to allow edition of metadata attributes (not considered by
+    # edition form by default)
+    attrcategories = ('primary', 'secondary', 'metadata')
+
     _onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
-    _defaultlandingzone = u'<img title="%(msg)s" src="data/file.gif" alt="%(msg)s"/>'
+    _defaultlandingzone = (u'<img title="%(msg)s" '
+                           'src="data/accessories-text-editor.png" '
+                           'alt="%(msg)s"/>')
     _landingzonemsg = _('click to edit this field')
     # default relation vids according to cardinality
     _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
 
@@ -107,16 +126,33 @@
         return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
 
     def _build_renderer(self, entity, rtype, role):
-        return self.vreg.select_object('formrenderers', 'base', self.req,
-                                       entity=entity,
-                                       display_label=False, display_help=False,
-                                       display_fields=[(rtype, role)],
-                                       table_class='', button_bar_class='buttonbar',
-                                       display_progress_div=False)
+        return self.vreg['formrenderers'].select(
+            'base', self.req, entity=entity, display_label=False,
+            display_help=False, display_fields=[(rtype, role)], table_class='',
+            button_bar_class='buttonbar', display_progress_div=False)
+
+    def _build_form(self, entity, rtype, role, formid, default, onsubmit, reload,
+                  extradata=None, **formargs):
+        divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
+        event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype,
+                      'reload' : dumps(reload), 'default' : default}
+        if extradata:
+            event_data.update(extradata)
+        onsubmit %= event_data
+        cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (entity.eid, rtype,
+                                                            divid)
+        form = self.vreg['forms'].select(
+            formid, self.req, entity=entity, domid='%s-form' % divid,
+            cssstyle='display: none', onsubmit=onsubmit, action='#',
+            form_buttons=[SubmitButton(), Button(stdmsgs.BUTTON_CANCEL,
+                                                 onclick=cancelclick)],
+            **formargs)
+        form.event_data = event_data
+        return form
 
     def cell_call(self, row, col, rtype=None, role='subject',
                   reload=False,      # controls reloading the whole page after change
-                  rvid=None,         # vid to be applied to other side of rtype
+                  rvid=None,         # vid to be applied to other side of rtype (non final relations only)
                   default=None,      # default value
                   landing_zone=None  # prepend value with a separate html element to click onto
                                      # (esp. needed when values are links)
@@ -131,73 +167,61 @@
         lzone = self._build_landing_zone(landing_zone)
         # compute value, checking perms, build form
         if rschema.is_final():
+            onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
+                        "%(reload)s, '%(default)s');")
+            form = self._build_form(
+                entity, rtype, role, 'edition', default, onsubmit, reload,
+                attrcategories=self.attrcategories)
+            if not self.should_edit_attribute(entity, rschema, role, form):
+                return
             value = entity.printable_value(rtype) or default
-            if not entity.has_perm('update'):
-                self.w(value)
-                return
-            self._attribute_form(entity, value, rtype, role, reload,
-                                 row, col, default, lzone)
+            self.attribute_form(lzone, value, form,
+                                 self._build_renderer(entity, rtype, role))
         else:
-            dispctrl = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema,
-                                                                rtype, role)
-            vid = dispctrl.get('vid', 'reledit')
-            if vid != 'reledit': # reledit explicitly disabled
-                self.wview(vid, entity.related(rtype, role))
+            if rvid is None:
+                rvid = self._compute_best_vid(entity.e_schema, rschema, role)
+            if not self.should_edit_relation(entity, rschema, role, rvid):
                 return
-            if rvid is None:
-                rvid = self._compute_best_vid(entity, rtype, role)
             rset = entity.related(rtype, role)
-            candidate = self.view(rvid, rset, 'null')
-            value = candidate or default
-            if role == 'subject' and not rschema.has_perm(self.req, 'add',
-                                                          fromeid=entity.eid):
-                return self.w(value)
-            elif role == 'object' and not rschema.has_perm(self.req, 'add',
-                                                           toeid=entity.eid):
-                return self.w(value)
-            elif get_schema_property(entity.e_schema, rschema,
-                                     role, 'composite') == role:
-                self.warning('reledit cannot be applied : (... %s %s [composite])'
-                             % (rtype, entity.e_schema))
-                return self.w(value)
-            self._relation_form(entity, value, rtype, role, reload, rvid,
-                                default, lzone)
-
+            if rset:
+                value = self.view(rvid, rset)
+            else:
+                value = default
+            onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
+                        "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');")
+            form = self._build_form(
+                entity, rtype, role, 'base', default, onsubmit, reload,
+                dict(vid=rvid, role=role, lzone=lzone))
+            field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
+            form.append_field(field)
+            self.relation_form(lzone, value, form,
+                               self._build_renderer(entity, rtype, role))
 
-    def _relation_form(self, entity, value, rtype, role, reload, rvid, default, lzone):
-        """xxx-reledit div (class=field)
-              +-xxx div (class="editableField")
-              |   +-landing zone
-              +-value
-              +-form-xxx div
-        """
-        divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
-        event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid,
-                      'reload' : dumps(reload), 'default' : default, 'role' : role,
-                      'lzone' : lzone}
-        onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
-                    "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
-                    % event_data)
-        cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
-            entity.eid, rtype, divid)
-        form = self.vreg.select_object('forms', 'base', self.req, entity=entity,
-                                       domid='%s-form' % divid, cssstyle='display: none',
-                                       onsubmit=onsubmit, action='#',
-                                       form_buttons=[SubmitButton(),
-                                                     Button(stdmsgs.BUTTON_CANCEL,
-                                                            onclick=cancelclick)])
-        field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
-        form.append_field(field)
-        w = self.w
-        w(u'<div id="%s-reledit" class="field">' % divid)
-        w(tags.div(lzone, klass='editableField', id=divid,
-                   onclick=self._onclick % event_data))
-        w(value)
-        renderer = self._build_renderer(entity, rtype, role)
-        w(form.form_render(renderer=renderer))
-        w(u'</div>')
+    def should_edit_attribute(self, entity, rschema, role, form):
+        rtype = str(rschema)
+        ttype = rschema.targets(entity.id, role)[0]
+        afs = uicfg.autoform_section.etype_get(entity.id, rtype, role, ttype)
+        if not (afs in self.attrcategories and entity.has_perm('update')):
+            self.w(entity.printable_value(rtype))
+            return False
+        try:
+            field = form.field_by_name(rtype, role)
+        except FieldNotFound:
+            self.w(entity.printable_value(rtype))
+            return False
+        return True
 
-    def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
+    def should_edit_relation(self, entity, rschema, role, rvid):
+        if ((role == 'subject' and not rschema.has_perm(self.req, 'add',
+                                                        fromeid=entity.eid))
+            or
+            (role == 'object' and not rschema.has_perm(self.req, 'add',
+                                                       toeid=entity.eid))):
+            self.wview(rvid, entity.related(str(rschema), role), 'null')
+            return False
+        return True
+
+    def attribute_form(self, lzone, value, form, renderer):
         """div (class=field)
               +-xxx div
               |  +-xxx div (class=editableField)
@@ -206,34 +230,55 @@
               |     +-value
               +-form-xxx div
         """
-        eid = entity.eid
-        divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
-        event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
-                      'reload' : dumps(reload), 'default' : default}
-        onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
-                    "%(reload)s, '%(default)s');")
-        buttons = [SubmitButton(stdmsgs.BUTTON_OK),
-                   Button(stdmsgs.BUTTON_CANCEL,
-                          onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
-                              eid, rtype, divid))]
-        form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
-                                       row=row, col=col, form_buttons=buttons,
-                                       domid='%s-form' % divid, action='#',
-                                       cssstyle='display: none',
-                                       onsubmit=onsubmit % event_data)
         w = self.w
         w(u'<div class="field">')
-        w(u'<div id="%s" style="display: inline">' % divid)
+        w(u'<div id="%s" style="display: inline">' % form.event_data['divid'])
         w(tags.div(lzone, klass='editableField',
-                   onclick=self._onclick % event_data))
+                   onclick=self._onclick % form.event_data))
         w(u'<div id="value-%s" style="display: inline">%s</div>' %
-               (divid, value))
+               (form.event_data['divid'], value))
+        w(u'</div>')
+        w(form.form_render(renderer=renderer))
         w(u'</div>')
-        renderer = self._build_renderer(entity, rtype, role)
+
+    def relation_form(self, lzone, value, form, renderer):
+        """xxx-reledit div (class=field)
+              +-xxx div (class="editableField")
+              |   +-landing zone
+              +-value
+              +-form-xxx div
+        """
+        w = self.w
+        w(u'<div id="%s-reledit" class="field">' % form.event_data['divid'])
+        w(tags.div(lzone, klass='editableField', id=form.event_data['divid'],
+                   onclick=self._onclick % form.event_data))
+        w(value)
         w(form.form_render(renderer=renderer))
         w(u'</div>')
 
 
+class AutoClickAndEditFormView(ClickAndEditFormView):
+    """same as ClickAndEditFormView but checking if the view *should* be applied
+    by checking uicfg configuration and composite relation property.
+    """
+    id = 'reledit'
+
+    def should_edit_relation(self, entity, rschema, role, rvid):
+        eschema = entity.e_schema
+        rtype = str(rschema)
+        # XXX check autoform_section. what if 'generic'?
+        dispctrl = uicfg.primaryview_display_ctrl.etype_get(eschema, rtype, role)
+        vid = dispctrl.get('vid', 'reledit')
+        if vid != 'reledit': # reledit explicitly disabled
+            self.wview(vid, entity.related(rtype, role), 'null')
+            return False
+        if eschema.role_rproperty(role, rschema, 'composite') == role:
+            self.wview(rvid, entity.related(rtype, role), 'null')
+            return False
+        return super(AutoClickAndEditFormView, self).should_edit_relation(
+            entity, rschema, role, rvid)
+
+
 class EditionFormView(FormViewMixIn, EntityView):
     """display primary entity edition form"""
     id = 'edition'
@@ -250,9 +295,9 @@
     def render_form(self, entity):
         """fetch and render the form"""
         self.form_title(entity)
-        form = self.vreg.select_object('forms', 'edition', self.req, entity.rset,
-                                       row=entity.row, col=entity.col, entity=entity,
-                                       submitmsg=self.submited_message())
+        form = self.vreg['forms'].select('edition', self.req, rset=entity.rset,
+                                         row=entity.row, col=entity.col, entity=entity,
+                                         submitmsg=self.submited_message())
         self.init_form(form, entity)
         self.w(form.form_render(formvid=u'edition'))
 
@@ -282,7 +327,7 @@
         """creation view for an entity"""
         etype = kwargs.pop('etype', self.req.form.get('etype'))
         try:
-            entity = self.vreg.etype_class(etype)(self.req)
+            entity = self.vreg['etypes'].etype_class(etype)(self.req)
         except:
             self.w(self.req._('no such entity type %s') % etype)
         else:
@@ -369,9 +414,10 @@
         kwargs.setdefault('__redirectrql', rset.printable_rql())
         super(TableEditForm, self).__init__(req, rset, **kwargs)
         for row in xrange(len(self.rset)):
-            form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
-                                           row=row, attrcategories=('primary',),
-                                           mainform=False)
+            form = self.vreg['forms'].select('edition', self.req,
+                                             rset=self.rset, row=row,
+                                             attrcategories=('primary',),
+                                             mainform=False)
             # XXX rely on the EntityCompositeFormRenderer to put the eid input
             form.remove_field(form.field_by_name('eid'))
             self.form_add_subform(form)
@@ -387,7 +433,7 @@
         should be the eid
         """
         #self.form_title(entity)
-        form = self.vreg.select_object('forms', self.id, self.req, self.rset)
+        form = self.vreg['forms'].select(self.id, self.req, rset=self.rset)
         self.w(form.form_render())
 
 
@@ -418,9 +464,9 @@
 
     def render_form(self, entity, peid, rtype, role, **kwargs):
         """fetch and render the form"""
-        form = self.vreg.select_object('forms', 'edition', self.req, None,
-                                       entity=entity, form_renderer_id='inline',
-                                       mainform=False, copy_nav_params=False)
+        form = self.vreg['forms'].select('edition', self.req, entity=entity,
+                                         form_renderer_id='inline',
+                                         mainform=False, copy_nav_params=False)
         self.add_hiddens(form, entity, peid, rtype, role)
         divid = '%s-%s-%s' % (peid, rtype, entity.eid)
         title = self.schema.rschema(rtype).display_name(self.req, role)
@@ -470,7 +516,7 @@
         :param role: the role played by the `peid` in the relation
         """
         try:
-            entity = self.vreg.etype_class(etype)(self.req, None, None)
+            entity = self.vreg['etypes'].etype_class(etype)(self.req, None, None)
         except:
             self.w(self.req._('no such entity type %s') % etype)
             return
--- a/web/views/editviews.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/editviews.py	Fri Aug 07 12:20:50 2009 +0200
@@ -120,8 +120,7 @@
         eid = entity.eid
         pending_inserts = self.req.get_pending_inserts(eid)
         rtype = rschema.type
-        form = self.vreg.select_object('forms', 'edition', self.req,
-                                       self.rset, entity=entity)
+        form = self.vreg['forms'].select('edition', self.req, entity=entity)
         field = form.field_by_name(rschema, target, entity.e_schema)
         limit = self.req.property_value('navigation.combobox-limit')
         for eview, reid in form.form_field_vocabulary(field, limit):
--- a/web/views/embedding.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/embedding.py	Fri Aug 07 12:20:50 2009 +0200
@@ -73,7 +73,8 @@
                 body = '<h2>%s</h2><h3>%s</h3>' % (
                     _('error while embedding page'), err)
         self.process_rql(req.form.get('rql'))
-        return self.vreg.main_template(req, self.template, rset=self.rset, body=body)
+        return self.vreg['views'].main_template(req, self.template,
+                                                rset=self.rset, body=body)
 
 
 def entity_has_embedable_url(entity):
--- a/web/views/facets.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/facets.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,7 +11,7 @@
 
 from logilab.mtconverter import xml_escape
 
-from cubicweb.vregistry import objectify_selector
+from cubicweb.appobject import objectify_selector
 from cubicweb.selectors import (non_final_entity, two_lines_rset,
                                 match_context_prop, yes, relation_possible)
 from cubicweb.web.box import BoxTemplate
@@ -118,9 +118,9 @@
             self.w(self.bk_linkbox_template % bk_link)
 
     def get_facets(self, rset, mainvar):
-        return self.vreg.possible_vobjects('facets', self.req, rset,
-                                           context='facetbox',
-                                           filtered_variable=mainvar)
+        return self.vreg['facets'].possible_vobjects(self.req, rset=rset,
+                                                     context='facetbox',
+                                                     filtered_variable=mainvar)
 
 # facets ######################################################################
 
--- a/web/views/formrenderers.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/formrenderers.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,7 +13,7 @@
 from simplejson import dumps
 
 from cubicweb.common import tags
-from cubicweb.appobject import AppRsetObject
+from cubicweb.appobject import AppObject
 from cubicweb.selectors import entity_implements, yes
 from cubicweb.web import eid_param
 from cubicweb.web import formwidgets as fwdgs
@@ -21,7 +21,7 @@
 from cubicweb.web.formfields import HiddenInitialValueField
 
 
-class FormRenderer(AppRsetObject):
+class FormRenderer(AppObject):
     """basic renderer displaying fields in a two columns table label | value
 
     +--------------+--------------+
@@ -85,6 +85,8 @@
         return '\n'.join(data)
 
     def render_label(self, form, field):
+        if field.label is None:
+            return u''
         label = self.req._(field.label)
         attrs = {'for': form.context[field]['id']}
         if field.required:
@@ -188,22 +190,40 @@
         return fields
 
     def _render_fields(self, fields, w, form):
-        w(u'<table class="%s">' % self.table_class)
+        byfieldset = {}
         for field in fields:
-            w(u'<tr>')
-            if self.display_label:
-                w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
-            error = form.form_field_error(field)
-            if error:
-                w(u'<td class="error">')
-                w(error)
-            else:
-                w(u'<td>')
-            w(field.render(form, self))
-            if self.display_help:
-                w(self.render_help(form, field))
-            w(u'</td></tr>')
-        w(u'</table>')
+            byfieldset.setdefault(field.fieldset, []).append(field)
+        if form.fieldsets_in_order:
+            fieldsets = form.fieldsets_in_order
+        else:
+            fieldsets = byfieldset.keys()
+        for fieldset in fieldsets:
+            try:
+                fields = byfieldset.pop(fieldset)
+            except KeyError:
+                self.warning('no such fieldset: %s (%s)', fieldset, form)
+                continue
+            w(u'<fieldset class="%s">' % (fieldset or u'default'))
+            if fieldset:
+                w(u'<legend>%s</legend>' % self.req._(fieldset))
+            w(u'<table class="%s">' % self.table_class)
+            for field in fields:
+                w(u'<tr class="%s_%s_row">' % (field.name, field.role))
+                if self.display_label:
+                    w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
+                error = form.form_field_error(field)
+                if error:
+                    w(u'<td class="error">')
+                    w(error)
+                else:
+                    w(u'<td>')
+                w(field.render(form, self))
+                if self.display_help:
+                    w(self.render_help(form, field))
+                w(u'</td></tr>')
+            w(u'</table></fieldset>')
+        if byfieldset:
+            self.warning('unused fieldsets: %s', ', '.join(byfieldset))
 
     def render_buttons(self, w, form):
         if not form.form_buttons:
@@ -286,22 +306,42 @@
     """specific renderer for multiple entities edition form (muledit)"""
     id = 'composite'
 
+    _main_display_fields = None
+
     def render_fields(self, w, form, values):
         if not form.is_subform:
             w(u'<table class="listing">')
+            subfields = [field for field in form.forms[0].fields
+                         if self.display_field(form, field)
+                         and field.is_visible()]
+            if subfields:
+                # main form, display table headers
+                w(u'<tr class="header">')
+                w(u'<th align="left">%s</th>' %
+                  tags.input(type='checkbox',
+                             title=self.req._('toggle check boxes'),
+                             onclick="setCheckboxesState('eid', this.checked)"))
+                for field in subfields:
+                    w(u'<th>%s</th>' % self.req._(field.label))
+                w(u'</tr>')
         super(EntityCompositeFormRenderer, self).render_fields(w, form, values)
         if not form.is_subform:
             w(u'</table>')
+            if self._main_display_fields:
+                super(EntityCompositeFormRenderer, self)._render_fields(
+                    self._main_display_fields, w, form)
 
     def _render_fields(self, fields, w, form):
         if form.is_subform:
             entity = form.edited_entity
             values = form.form_previous_values
             qeid = eid_param('eid', entity.eid)
-            cbsetstate = "setCheckboxesState2('eid', %s, 'checked')" % xml_escape(dumps(entity.eid))
+            cbsetstate = "setCheckboxesState2('eid', %s, 'checked')" % \
+                         xml_escape(dumps(entity.eid))
             w(u'<tr class="%s">' % (entity.row % 2 and u'even' or u'odd'))
             # XXX turn this into a widget used on the eid field
-            w(u'<td>%s</td>' % checkbox('eid', entity.eid, checked=qeid in values))
+            w(u'<td>%s</td>' % checkbox('eid', entity.eid,
+                                        checked=qeid in values))
             for field in fields:
                 error = form.form_field_error(field)
                 if error:
@@ -309,22 +349,17 @@
                     w(error)
                 else:
                     w(u'<td>')
-                if isinstance(field.widget, (fwdgs.Select, fwdgs.CheckBox, fwdgs.Radio)):
+                if isinstance(field.widget, (fwdgs.Select, fwdgs.CheckBox,
+                                             fwdgs.Radio)):
                     field.widget.attrs['onchange'] = cbsetstate
                 elif isinstance(field.widget, fwdgs.Input):
                     field.widget.attrs['onkeypress'] = cbsetstate
+                # XXX else
                 w(u'<div>%s</div>' % field.render(form, self))
-                w(u'</td>')
+                w(u'</td>\n')
+            w(u'</tr>')
         else:
-            # main form, display table headers
-            w(u'<tr class="header">')
-            w(u'<th align="left">%s</th>'
-              % tags.input(type='checkbox', title=self.req._('toggle check boxes'),
-                           onclick="setCheckboxesState('eid', this.checked)"))
-            for field in self.forms[0].fields:
-                if self.display_field(form, field) and field.is_visible():
-                    w(u'<th>%s</th>' % self.req._(field.label))
-        w(u'</tr>')
+            self._main_display_fields = fields
 
 
 class EntityFormRenderer(EntityBaseFormRenderer):
@@ -435,8 +470,6 @@
         """create a form to edit entity's inlined relations"""
         if not hasattr(form, 'inlined_relations'):
             return
-        entity = form.edited_entity
-        __ = self.req.__
         for rschema, targettypes, role in form.inlined_relations():
             # show inline forms only if there's one possible target type
             # for rschema
@@ -447,37 +480,42 @@
                 continue
             targettype = targettypes[0].type
             if form.should_inline_relation_form(rschema, targettype, role):
-                w(u'<div id="inline%sslot">' % rschema)
-                existant = entity.has_eid() and entity.related(rschema)
-                if existant:
-                    # display inline-edition view for all existing related entities
-                    w(form.view('inline-edition', existant, rtype=rschema, role=role,
-                                ptype=entity.e_schema, peid=entity.eid))
-                if role == 'subject':
-                    card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0]
-                else:
-                    card = rschema.rproperty(targettype, entity.e_schema, 'cardinality')[1]
-                # there is no related entity and we need at least one: we need to
-                # display one explicit inline-creation view
-                if form.should_display_inline_creation_form(rschema, existant, card):
-                    w(form.view('inline-creation', None, etype=targettype,
-                                peid=entity.eid, ptype=entity.e_schema,
-                                rtype=rschema, role=role))
-                # we can create more than one related entity, we thus display a link
-                # to add new related entities
-                if form.should_display_add_new_relation_link(rschema, existant, card):
-                    divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
-                    w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
-                      % divid)
-                    js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % (
-                        entity.eid, targettype, rschema, role)
-                    if card in '1?':
-                        js = "toggleVisibility('%s'); %s" % (divid, js)
-                    w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
-                      % (rschema, entity.eid, js, __('add a %s' % targettype)))
-                    w(u'</div>')
-                    w(u'<div class="trame_grise">&nbsp;</div>')
-                w(u'</div>')
+                self.inline_relation_form(w, form, rschema, targettype, role)
+
+    def inline_relation_form(self, w, form, rschema, targettype, role):
+        entity = form.edited_entity
+        __ = self.req.__
+        w(u'<div id="inline%sslot">' % rschema)
+        existant = entity.has_eid() and entity.related(rschema)
+        if existant:
+            # display inline-edition view for all existing related entities
+            w(form.view('inline-edition', existant, rtype=rschema, role=role,
+                        ptype=entity.e_schema, peid=entity.eid))
+        if role == 'subject':
+            card = rschema.rproperty(entity.e_schema, targettype, 'cardinality')[0]
+        else:
+            card = rschema.rproperty(targettype, entity.e_schema, 'cardinality')[1]
+        # there is no related entity and we need at least one: we need to
+        # display one explicit inline-creation view
+        if form.should_display_inline_creation_form(rschema, existant, card):
+            w(form.view('inline-creation', None, etype=targettype,
+                        peid=entity.eid, ptype=entity.e_schema,
+                        rtype=rschema, role=role))
+        # we can create more than one related entity, we thus display a link
+        # to add new related entities
+        if form.should_display_add_new_relation_link(rschema, existant, card):
+            divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid)
+            w(u'<div class="inlinedform" id="%s" cubicweb:limit="true">'
+              % divid)
+            js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % (
+                entity.eid, targettype, rschema, role)
+            if card in '1?':
+                js = "toggleVisibility('%s'); %s" % (divid, js)
+            w(u'<a class="addEntity" id="add%s:%slink" href="javascript: %s" >+ %s.</a>'
+              % (rschema, entity.eid, js, __('add a %s' % targettype)))
+            w(u'</div>')
+            w(u'<div class="trame_grise">&nbsp;</div>')
+        w(u'</div>')
 
 
 class EntityInlinedFormRenderer(EntityFormRenderer):
--- a/web/views/forms.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/forms.py	Fri Aug 07 12:20:50 2009 +0200
@@ -20,16 +20,49 @@
 
 
 class FieldsForm(form.Form):
+    """base class for fields based forms.
+
+    The following attributes may be either set on subclasses or given on
+    form selection to customize the generated form:
+
+    * `needs_js`: sequence of javascript files that should be added to handle
+      this form (through `req.add_js`)
+
+    * `needs_css`: sequence of css files that should be added to handle this
+      form (through `req.add_css`)
+
+    * `domid`: value for the "id" attribute of the <form> tag
+
+    * `action`: value for the "action" attribute of the <form> tag
+
+    * `onsubmit`: value for the "onsubmit" attribute of the <form> tag
+
+    * `cssclass`: value for the "class" attribute of the <form> tag
+
+    * `cssstyle`: value for the "style" attribute of the <form> tag
+
+    * `cwtarget`: value for the "cubicweb:target" attribute of the <form> tag
+
+    * `redirect_path`: relative to redirect to after submitting the form
+
+    * `copy_nav_params`: flag telling if navigation paramenters should be copied
+      back in hidden input
+
+    * `form_buttons`:  form buttons sequence (button widgets instances)
+
+    * `form_renderer_id`: id of the form renderer to use to render the form
+
+    * `fieldsets_in_order`: fieldset name sequence, to control order
+    """
     id = 'base'
 
     is_subform = False
+    internal_fields = ('__errorurl',) + NAV_FORM_PARAMETERS
 
-    # attributes overrideable through __init__
-    internal_fields = ('__errorurl',) + NAV_FORM_PARAMETERS
+    # attributes overrideable by subclasses or through __init__
     needs_js = ('cubicweb.ajax.js', 'cubicweb.edition.js',)
     needs_css = ('cubicweb.form.css',)
     domid = 'form'
-    title = None
     action = None
     onsubmit = "return freezeFormButtons('%(domid)s');"
     cssclass = None
@@ -37,8 +70,9 @@
     cwtarget = None
     redirect_path = None
     copy_nav_params = False
-    form_buttons = None # form buttons (button widgets instances)
+    form_buttons = None
     form_renderer_id = 'default'
+    fieldsets_in_order = None
 
     def __init__(self, req, rset=None, row=None, col=None,
                  submitmsg=None, mainform=True,
@@ -145,9 +179,9 @@
         return renderer.render(self, values)
 
     def form_default_renderer(self):
-        return self.vreg.select_object('formrenderers', self.form_renderer_id,
-                                       self.req, self.rset,
-                                       row=self.row, col=self.col)
+        return self.vreg['formrenderers'].select(self.form_renderer_id,
+                                                self.req, rset=self.rset,
+                                                row=self.row, col=self.col)
 
     def form_build_context(self, rendervalues=None):
         """build form context values (the .context attribute which is a
@@ -254,7 +288,8 @@
 
 class EntityFieldsForm(FieldsForm):
     id = 'base'
-    __select__ = (match_kwargs('entity') | (one_line_rset & non_final_entity()))
+    __select__ = (match_kwargs('entity')
+                  | (one_line_rset() & non_final_entity()))
 
     internal_fields = FieldsForm.internal_fields + ('__type', 'eid', '__maineid')
     domid = 'entityForm'
@@ -332,10 +367,9 @@
         return value
 
     def form_default_renderer(self):
-        return self.vreg.select_object('formrenderers', self.form_renderer_id,
-                                       self.req, self.rset,
-                                       row=self.row, col=self.col,
-                                       entity=self.edited_entity)
+        return self.vreg['formrenderers'].select(
+            self.form_renderer_id, self.req, rset=self.rset, row=self.row,
+            col=self.col, entity=self.edited_entity)
 
     def form_build_context(self, values=None):
         """overriden to add edit[s|o] hidden fields and to ensure schema fields
--- a/web/views/idownloadable.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/idownloadable.py	Fri Aug 07 12:20:50 2009 +0200
@@ -122,7 +122,7 @@
     __select__ = implements(IDownloadable)
 
     def cell_call(self, row, col, title=None, **kwargs):
-        """the secondary view is a link to download the file"""
+        """the oneline view is a link to download the file"""
         entity = self.entity(row, col)
         url = xml_escape(entity.absolute_url())
         name = xml_escape(title or entity.download_file_name())
@@ -144,9 +144,21 @@
             self.wview(self.id, rset, row=i, col=0)
             self.w(u'</div>')
 
-    def cell_call(self, row, col):
+    def cell_call(self, row, col, width=None, height=None, link=False):
         entity = self.entity(row, col)
         #if entity.data_format.startswith('image/'):
-        self.w(u'<img src="%s" alt="%s"/>' % (xml_escape(entity.download_url()),
-                                              xml_escape(entity.download_file_name())))
+        imgtag = u'<img src="%s" alt="%s" ' % (xml_escape(entity.download_url()),
+                                               xml_escape(entity.download_file_name()))
+        if width:
+            imgtag += u'width="%i" ' % width
+        if height:
+            imgtag += u'height="%i" ' % height
+        imgtag += u'/>'
+        if link:
+            self.w(u'<a href="%s" alt="%s">%s</a>' % (entity.absolute_url(vid='download'),
+                                                      self.req._('download image'),
+                                                      imgtag))
+        else:
+            self.w(imgtag)
 
+
--- a/web/views/iprogress.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/iprogress.py	Fri Aug 07 12:20:50 2009 +0200
@@ -5,8 +5,8 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
-
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from logilab.mtconverter import xml_escape
 
@@ -48,7 +48,7 @@
         self.req.add_css('cubicweb.iprogress.css')
         _ = self.req._
         self.columns = columns or self.columns
-        ecls = self.vreg.etype_class(self.rset.description[0][0])
+        ecls = self.vreg['etypes'].etype_class(self.rset.description[0][0])
         self.w(u'<table class="progress">')
         self.table_header(ecls)
         self.w(u'<tbody>')
@@ -168,7 +168,8 @@
     id = 'ic_progress_table_view'
 
     def call(self):
-        view = self.vreg.select_view('progress_table_view', self.req, self.rset)
+        view = self.vreg['views'].select('progress_table_view', self.req,
+                                         rset=self.rset)
         columns = list(view.columns)
         try:
             columns.remove('project')
--- a/web/views/magicsearch.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/magicsearch.py	Fri Aug 07 12:20:50 2009 +0200
@@ -42,7 +42,7 @@
     :param translations: the reverted l10n dict
 
     :type schema: `cubicweb.schema.Schema`
-    :param schema: the application's schema
+    :param schema: the instance's schema
     """
     # var_types is used as a map : var_name / var_type
     vartypes = {}
@@ -94,7 +94,7 @@
     :param ambiguous_nodes: a map : relation_node / (var_name, available_translations)
 
     :type schema: `cubicweb.schema.Schema`
-    :param schema: the application's schema
+    :param schema: the instance's schema
     """
     # Now, try to resolve ambiguous translations
     for relation, (var_name, translations_found) in ambiguous_nodes.items():
@@ -170,10 +170,7 @@
     """
     priority = 2
     def preprocess_query(self, uquery, req):
-        try:
-            rqlst = parse(uquery, print_errors=False)
-        except (RQLSyntaxError, BadRQLQuery), err:
-            return uquery,
+        rqlst = parse(uquery, print_errors=False)
         schema = self.vreg.schema
         # rql syntax tree will be modified in place if necessary
         translate_rql_tree(rqlst, trmap(self.config, schema, req.lang), schema)
@@ -204,7 +201,7 @@
             elif len(words) == 3:
                 args = self._three_words_query(*words)
             else:
-                args = self._multiple_words_query(words)
+                raise
         return args
 
     def _get_entity_type(self, word):
@@ -291,11 +288,6 @@
                                   self._complete_rql(word3, etype, searchattr=rtype))
         return rql, {'text': word3}
 
-    def _multiple_words_query(self, words):
-        """specific process for more than 3 words query"""
-        return ' '.join(words),
-
-
     def _expand_shortcut(self, etype, rtype, searchstr):
         """Expands shortcut queries on a non final relation to use has_text or
         the main attribute (according to possible entity type) if '%' is used in the
@@ -356,8 +348,7 @@
         super(MagicSearchComponent, self).__init__(req, rset)
         processors = []
         self.by_name = {}
-        for processorcls in self.vreg.registry_objects('components',
-                                                       'magicsearch_processor'):
+        for processorcls in self.vreg['components']['magicsearch_processor']:
             # instantiation needed
             processor = processorcls()
             processors.append(processor)
--- a/web/views/management.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/management.py	Fri Aug 07 12:20:50 2009 +0200
@@ -107,13 +107,12 @@
     def owned_by_edit_form(self, entity):
         self.w('<h3>%s</h3>' % self.req._('ownership'))
         msg = self.req._('ownerships have been changed')
-        form = self.vreg.select_object('forms', 'base', self.req, entity=entity,
-                                       form_renderer_id='base',
-                                  submitmsg=msg,
-                                  form_buttons=[wdgs.SubmitButton()],
-                                  domid='ownership%s' % entity.eid,
-                                  __redirectvid='security',
-                                  __redirectpath=entity.rest_path())
+        form = self.vreg['forms'].select('base', self.req, entity=entity,
+                                         form_renderer_id='base', submitmsg=msg,
+                                         form_buttons=[wdgs.SubmitButton()],
+                                         domid='ownership%s' % entity.eid,
+                                         __redirectvid='security',
+                                         __redirectpath=entity.rest_path())
         field = guess_field(entity.e_schema, self.schema.rschema('owned_by'))
         form.append_field(field)
         self.w(form.form_render(display_progress_div=False))
@@ -161,16 +160,14 @@
             self.w(self.req._('no associated permissions'))
 
     def require_permission_edit_form(self, entity):
-        w = self.w
-        _ = self.req._
-        newperm = self.vreg.etype_class('CWPermission')(self.req, None)
+        newperm = self.vreg['etypes'].etype_class('CWPermission')(self.req)
         newperm.eid = self.req.varmaker.next()
-        w(u'<p>%s</p>' % _('add a new permission'))
-        form = self.vreg.select_object('forms', 'base', self.req, entity=newperm,
-                                       form_buttons=[wdgs.SubmitButton()],
-                                       domid='reqperm%s' % entity.eid,
-                                       __redirectvid='security',
-                                       __redirectpath=entity.rest_path())
+        self.w(u'<p>%s</p>' % self.req._('add a new permission'))
+        form = self.vreg['forms'].select('base', self.req, entity=newperm,
+                                         form_buttons=[wdgs.SubmitButton()],
+                                         domid='reqperm%s' % entity.eid,
+                                         __redirectvid='security',
+                                         __redirectpath=entity.rest_path())
         form.form_add_hidden('require_permission', entity.eid, role='object',
                              eidparam=True)
         permnames = getattr(entity, '__permissions__', None)
@@ -186,8 +183,8 @@
         form.append_field(field)
         field = guess_field(cwpermschema, self.schema.rschema('require_group'))
         form.append_field(field)
-        renderer = self.vreg.select_object('formrenderers', 'htable', self.req,
-                                           rset=None, display_progress_div=False)
+        renderer = self.vreg['formrenderers'].select(
+            'htable', self.req, rset=None, display_progress_div=False)
         self.w(form.form_render(renderer=renderer))
 
 
@@ -244,8 +241,8 @@
         submiturl = self.config['submit-url']
         submitmail = self.config['submit-mail']
         if submiturl or submitmail:
-            form = self.vreg.select_object('forms', 'base', self.req, rset=None,
-                                           mainform=False)
+            form = self.vreg['forms'].select('base', self.req, rset=None,
+                                             mainform=False)
             binfo = text_error_description(ex, excinfo, req, eversion, cversions)
             form.form_add_hidden('description', binfo,
                                  # we must use a text area to keep line breaks
@@ -286,7 +283,7 @@
 
 class ProcessInformationView(StartupView):
     id = 'info'
-    __select__ = none_rset() & match_user_groups('managers')
+    __select__ = none_rset() & match_user_groups('users', 'managers')
 
     title = _('server information')
 
--- a/web/views/massmailing.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/massmailing.py	Fri Aug 07 12:20:50 2009 +0200
@@ -68,7 +68,7 @@
     def get_allowed_substitutions(self):
         attrs = []
         for coltype in self.rset.column_types(0):
-            eclass = self.vreg.etype_class(coltype)
+            eclass = self.vreg['etypes'].etype_class(coltype)
             attrs.append(eclass.allowed_massmail_keys())
         return sorted(reduce(operator.and_, attrs))
 
@@ -123,9 +123,9 @@
 
     def call(self):
         req = self.req
-        req.add_js('cubicweb.widgets.js')
+        req.add_js('cubicweb.widgets.js', 'cubicweb.massmailing.js')
         req.add_css('cubicweb.mailform.css')
         from_addr = '%s <%s>' % (req.user.dc_title(), req.user.get_email())
-        form = self.vreg.select_object('forms', 'massmailing', self.req, self.rset,
-                                       action='sendmail', domid='sendmail')
+        form = self.vreg['forms'].select('massmailing', self.req, rset=self.rset,
+                                action='sendmail', domid='sendmail')
         self.w(form.form_render(sender=from_addr))
--- a/web/views/navigation.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/navigation.py	Fri Aug 07 12:20:50 2009 +0200
@@ -11,7 +11,7 @@
 from rql.nodes import VariableRef, Constant
 
 from logilab.mtconverter import xml_escape
-from logilab.common.deprecation import obsolete
+from logilab.common.deprecation import deprecated
 
 from cubicweb.interfaces import IPrevNext
 from cubicweb.selectors import (paginated_rset, sorted_rset,
@@ -48,6 +48,7 @@
     def index_display(self, start, stop):
         return u'%s - %s' % (start+1, stop+1)
 
+
 class SortedNavigation(NavigationComponent):
     """sorted navigation apply if navigation is needed (according to page size)
     and if the result set is sorted
@@ -147,27 +148,27 @@
 
 def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
                                show_all_option=True, page_size=None):
-    showall = forcedisplay or req.form.get('__force_display') is not None
-    nav = not showall and self.vreg.select_component('navigation', req, rset,
-                                                     page_size=page_size)
-    if nav:
-        # get boundaries before component rendering
-        start, stop = nav.page_boundaries()
-        nav.render(w=w)
-        params = dict(req.form)
-        nav.clean_params(params)
-        # make a link to see them all
-        if show_all_option:
-            url = xml_escape(self.build_url(__force_display=1, **params))
-            w(u'<p><a href="%s">%s</a></p>\n'
-              % (url, req._('show %s results') % len(rset)))
-        rset.limit(offset=start, limit=stop-start, inplace=True)
+    if not (forcedisplay or req.form.get('__force_display') is not None):
+        nav = self.vreg['components'].select_object('navigation', req,
+                                      rset=rset, page_size=page_size)
+        if nav:
+            # get boundaries before component rendering
+            start, stop = nav.page_boundaries()
+            nav.render(w=w)
+            params = dict(req.form)
+            nav.clean_params(params)
+            # make a link to see them all
+            if show_all_option:
+                url = xml_escape(self.build_url(__force_display=1, **params))
+                w(u'<p><a href="%s">%s</a></p>\n'
+                  % (url, req._('show %s results') % len(rset)))
+            rset.limit(offset=start, limit=stop-start, inplace=True)
 
 
 # monkey patch base View class to add a .pagination(req, rset, w, forcedisplay)
 # method to be called on view's result set and printing pages index in the view
 from cubicweb.view import View
-View.pagination = obsolete('.pagination is deprecated, use paginate')(limit_rset_using_paged_nav)
+View.pagination = deprecated('.pagination is deprecated, use paginate')(limit_rset_using_paged_nav)
 
 def paginate(view, show_all_option=True, w=None, page_size=None):
     limit_rset_using_paged_nav(view, view.req, view.rset, w or view.w,
--- a/web/views/owl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/owl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -6,14 +6,14 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from logilab.mtconverter import TransformError, xml_escape
 
 from cubicweb.view import StartupView, EntityView
+from cubicweb.selectors import none_rset, match_view
 from cubicweb.web.action import Action
-from cubicweb.selectors import none_rset, match_view
-
-_ = unicode
+from cubicweb.web.views import schema
 
 OWL_CARD_MAP = {'1': '<rdf:type rdf:resource="&owl;FunctionalProperty"/>',
                 '?': '<owl:maxCardinality rdf:datatype="&xsd;int">1</owl:maxCardinality>',
@@ -55,8 +55,6 @@
 
 OWL_CLOSING_ROOT = u'</rdf:RDF>'
 
-DEFAULT_SKIP_RELS = frozenset(('is', 'is_instance_of', 'identity',
-                               'owned_by', 'created_by'))
 
 class OWLView(StartupView):
     """This view export in owl format schema database. It is the TBOX"""
@@ -69,36 +67,36 @@
         skipmeta = int(self.req.form.get('skipmeta', True))
         if writeprefix:
             self.w(OWL_OPENING_ROOT % {'appid': self.schema.name})
-        self.visit_schema(skipmeta=skipmeta)
+        self.visit_schema(skiptypes=skipmeta and schema.SKIP_TYPES or ())
         if writeprefix:
             self.w(OWL_CLOSING_ROOT)
 
-    def visit_schema(self, skiprels=DEFAULT_SKIP_RELS, skipmeta=True):
+    def should_display_rschema(self, rschema):
+        return not rschema in self.skiptypes and (
+            rschema.has_local_role('read') or
+            rschema.has_perm(self.req, 'read'))
+
+    def visit_schema(self, skiptypes):
         """get a layout for a whole schema"""
-        entities = sorted([eschema for eschema in self.schema.entities()
-                           if not eschema.is_final()])
-        if skipmeta:
-            entities = [eschema for eschema in entities
-                        if not eschema.meta]
+        self.skiptypes = skiptypes
+        entities = sorted(eschema for eschema in self.schema.entities()
+                          if not eschema.is_final() or eschema in skiptypes)
         self.w(u'<!-- classes definition -->')
         for eschema in entities:
-            self.visit_entityschema(eschema, skiprels)
+            self.visit_entityschema(eschema)
             self.w(u'<!-- property definition -->')
-            self.visit_property_schema(eschema, skiprels)
+            self.visit_property_schema(eschema)
             self.w(u'<!-- datatype property -->')
             self.visit_property_object_schema(eschema)
 
-    def visit_entityschema(self, eschema, skiprels=()):
+    def visit_entityschema(self, eschema):
         """get a layout for an entity OWL schema"""
         self.w(u'<owl:Class rdf:ID="%s">'% eschema)
         self.w(u'<!-- relations -->')
         for rschema, targetschemas, role in eschema.relation_definitions():
-            if rschema.type in skiprels:
-                continue
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
+            if not self.should_display_rschema(rschema):
                 continue
             for oeschema in targetschemas:
-                label = rschema.type
                 if role == 'subject':
                     card = rschema.rproperty(eschema, oeschema, 'cardinality')[0]
                 else:
@@ -110,58 +108,43 @@
   <owl:onProperty rdf:resource="#%s"/>
   %s
  </owl:Restriction>
-</rdfs:subClassOf>
-''' % (label, cardtag))
+</rdfs:subClassOf>''' % (rschema, cardtag))
 
         self.w(u'<!-- attributes -->')
-
         for rschema, aschema in eschema.attribute_definitions():
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
-                continue
-            aname = rschema.type
-            if aname == 'eid':
+            if not self.should_display_rschema(rschema):
                 continue
             self.w(u'''<rdfs:subClassOf>
   <owl:Restriction>
    <owl:onProperty rdf:resource="#%s"/>
    <rdf:type rdf:resource="&owl;FunctionalProperty"/>
   </owl:Restriction>
-</rdfs:subClassOf>'''
-                   % aname)
+</rdfs:subClassOf>''' % rschema)
         self.w(u'</owl:Class>')
 
-    def visit_property_schema(self, eschema, skiprels=()):
+    def visit_property_schema(self, eschema):
         """get a layout for property entity OWL schema"""
         for rschema, targetschemas, role in eschema.relation_definitions():
-            if rschema.type in skiprels:
-                continue
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
+            if not self.should_display_rschema(rschema):
                 continue
             for oeschema in targetschemas:
-                label = rschema.type
                 self.w(u'''<owl:ObjectProperty rdf:ID="%s">
  <rdfs:domain rdf:resource="#%s"/>
  <rdfs:range rdf:resource="#%s"/>
-</owl:ObjectProperty>
-''' % (label, eschema, oeschema.type))
+</owl:ObjectProperty>''' % (rschema, eschema, oeschema.type))
 
     def visit_property_object_schema(self, eschema):
         for rschema, aschema in eschema.attribute_definitions():
-            if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
-                continue
-            aname = rschema.type
-            if aname == 'eid':
+            if not self.should_display_rschema(rschema):
                 continue
             self.w(u'''<owl:DatatypeProperty rdf:ID="%s">
   <rdfs:domain rdf:resource="#%s"/>
   <rdfs:range rdf:resource="%s"/>
-</owl:DatatypeProperty>'''
-                   % (aname, eschema, OWL_TYPE_MAP[aschema.type]))
+</owl:DatatypeProperty>''' % (rschema, eschema, OWL_TYPE_MAP[aschema.type]))
 
 
 class OWLABOXView(EntityView):
     '''This view represents a part of the ABOX for a given entity.'''
-
     id = 'owlabox'
     title = _('owlabox')
     templatable = False
@@ -173,8 +156,8 @@
             self.cell_call(i, 0)
         self.w(OWL_CLOSING_ROOT)
 
-    def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS):
-        self.wview('owlaboxitem', self.rset, row=row, col=col, skiprels=skiprels)
+    def cell_call(self, row, col):
+        self.wview('owlaboxitem', self.rset, row=row, col=col)
 
 
 class OWLABOXItemView(EntityView):
@@ -183,13 +166,13 @@
     templatable = False
     content_type = 'application/xml' # 'text/xml'
 
-    def cell_call(self, row, col, skiprels=DEFAULT_SKIP_RELS):
+    def cell_call(self, row, col):
         entity = self.complete_entity(row, col)
         eschema = entity.e_schema
         self.w(u'<%s rdf:ID="%s">' % (eschema, entity.eid))
         self.w(u'<!--attributes-->')
         for rschema, aschema in eschema.attribute_definitions():
-            if rschema.type in skiprels:
+            if rschema.meta:
                 continue
             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
                 continue
@@ -204,7 +187,7 @@
                 pass
         self.w(u'<!--relations -->')
         for rschema, targetschemas, role in eschema.relation_definitions():
-            if rschema.type in skiprels:
+            if rschema.meta:
                 continue
             if not (rschema.has_local_role('read') or rschema.has_perm(self.req, 'read')):
                 continue
--- a/web/views/plots.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/plots.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,7 +16,7 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb.utils import make_uid, UStringIO, datetime2ticks
-from cubicweb.vregistry import objectify_selector
+from cubicweb.appobject import objectify_selector
 from cubicweb.web.views import baseviews
 
 @objectify_selector
--- a/web/views/primary.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/primary.py	Fri Aug 07 12:20:50 2009 +0200
@@ -39,12 +39,11 @@
 
     def cell_call(self, row, col):
         self.row = row
-        # XXX move render_entity implementation here
-        self.render_entity(self.complete_entity(row, col))
         self.maxrelated = self.req.property_value('navigation.related-limit')
+        entity = self.complete_entity(row, col)
+        self.render_entity(entity)
 
     def render_entity(self, entity):
-        """return html to display the given entity"""
         self.render_entity_title(entity)
         self.render_entity_metadata(entity)
         # entity's attributes and relations, excluding meta data
@@ -54,23 +53,9 @@
             self.w(u'<table width="100%"><tr><td style="width: 75%">')
         self.w(u'<div class="mainInfo">')
         self.content_navigation_components('navcontenttop')
-        try:
-            self.render_entity_attributes(entity)
-        except TypeError, e: # XXX bw compat
-            if 'render_entity' not in e.args[0]:
-                raise
-            warn('siderelations argument of render_entity_attributes is '
-                 'deprecated (%s)' % self.__class__)
-            self.render_entity_attributes(entity, [])
+        self.render_entity_attributes(entity)
         if self.main_related_section:
-            try:
-                self.render_entity_relations(entity)
-            except TypeError, e: # XXX bw compat
-                if 'render_entity' not in e.args[0]:
-                    raise
-                warn('siderelations argument of render_entity_relations is '
-                     'deprecated')
-                self.render_entity_relations(entity, [])
+            self.render_entity_relations(entity)
         self.w(u'</div>')
         # side boxes
         if boxes or hasattr(self, 'render_side_related'):
@@ -84,12 +69,10 @@
             self.w(u'</td></tr></table>')
         self.content_navigation_components('navcontentbottom')
 
-
     def content_navigation_components(self, context):
         self.w(u'<div class="%s">' % context)
-        for comp in self.vreg.possible_vobjects('contentnavigation',
-                                                self.req, self.rset, row=self.row,
-                                                view=self, context=context):
+        for comp in self.vreg['contentnavigation'].possible_vobjects(
+            self.req, rset=self.rset, row=self.row, view=self, context=context):
             try:
                 comp.render(w=self.w, row=self.row, view=self)
             except NotImplementedError:
@@ -164,9 +147,9 @@
             label = display_name(self.req, rschema.type, role)
             vid = dispctrl.get('vid', 'sidebox')
             sideboxes.append( (label, rset, vid) )
-        sideboxes += self.vreg.possible_vobjects('boxes', self.req, self.rset,
-                                                 row=self.row, view=self,
-                                                 context='incontext')
+        sideboxes += self.vreg['boxes'].possible_vobjects(
+            self.req, rset=self.rset, row=self.row, view=self,
+            context='incontext')
         return sideboxes
 
     def _section_def(self, entity, where):
@@ -241,3 +224,21 @@
             self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql),
                                                self.req._('see them all')))
             self.w(u'</div>')
+
+## default primary ui configuration ###########################################
+
+for rtype in ('eid', 'creation_date', 'modification_date', 'cwuri',
+              'is', 'is_instance_of', 'identity',
+              'owned_by', 'created_by',
+              'in_state', 'wf_info_for', 'require_permission',
+              'from_entity', 'to_entity',
+              'see_also'):
+    uicfg.primaryview_section.tag_subject_of(('*', rtype, '*'), 'hidden')
+    uicfg.primaryview_section.tag_object_of(('*', rtype, '*'), 'hidden')
+uicfg.primaryview_section.tag_subject_of(('*', 'use_email', '*'), 'attributes')
+uicfg.primaryview_section.tag_subject_of(('*', 'primary_email', '*'), 'hidden')
+
+for attr in ('name', 'final'):
+    uicfg.primaryview_section.tag_attribute(('CWEType', attr), 'hidden')
+for attr in ('name', 'final', 'symetric', 'inlined'):
+    uicfg.primaryview_section.tag_attribute(('CWRType', attr), 'hidden')
--- a/web/views/schema.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/schema.py	Fri Aug 07 12:20:50 2009 +0200
@@ -10,29 +10,179 @@
 from itertools import cycle
 
 from logilab.mtconverter import xml_escape
-from yams import schema2dot as s2d
+from yams import BASE_TYPES, schema2dot as s2d
 
-from cubicweb.selectors import implements, yes
+from cubicweb.selectors import implements, yes, match_user_groups
+from cubicweb.schema import META_RTYPES, SCHEMA_TYPES
 from cubicweb.schemaviewer import SchemaViewer
 from cubicweb.view import EntityView, StartupView
 from cubicweb.common import tags, uilib
-from cubicweb.web import action
-from cubicweb.web.views import TmpFileViewMixin, primary, baseviews, tabs
-from cubicweb.web.facet import AttributeFacet
+from cubicweb.web import action, facet
+from cubicweb.web.views import TmpFileViewMixin
+from cubicweb.web.views import primary, baseviews, tabs, management
+
+ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES
+SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RTYPES
+SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo',
+                       'CWUser', 'CWGroup',
+                       'CWCache', 'CWProperty', 'CWPermission',
+                       'ExternalUri')))
+
+def skip_types(req):
+    if int(req.form.get('skipmeta', True)):
+        return SKIP_TYPES
+    return ALWAYS_SKIP_TYPES
+
+# global schema view ###########################################################
+
+class SchemaView(tabs.TabsMixin, StartupView):
+    id = 'schema'
+    title = _('instance schema')
+    tabs = [_('schema-text'), _('schema-image')]
+    default_tab = 'schema-text'
+
+    def call(self):
+        """display schema information"""
+        self.req.add_js('cubicweb.ajax.js')
+        self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
+        self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
+        self.render_tabs(self.tabs, self.default_tab)
+
+
+class SchemaTabImageView(StartupView):
+    id = 'schema-image'
+
+    def call(self):
+        self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
+                 u'meta-data, but you can also display a <a href="%s">complete '
+                 u'schema with meta-data</a>.</div>')
+               % xml_escape(self.build_url('view', vid='schemagraph', skipmeta=0)))
+        self.w(u'<img src="%s" alt="%s"/>\n' % (
+            xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
+            self.req._("graphical representation of the instance'schema")))
+
+
+class SchemaTabTextView(StartupView):
+    id = 'schema-text'
+
+    def call(self):
+        rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
+                                'X final FALSE')
+        self.wview('table', rset, displayfilter=True)
 
 
-class ViewSchemaAction(action.Action):
-    id = 'schema'
-    __select__ = yes()
+class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
+    id = 'schema-security'
+    __select__ = StartupView.__select__ & match_user_groups('managers')
+
+    def call(self, display_relations=True):
+        self.req.add_css('cubicweb.acl.css')
+        skiptypes = skip_types(self.req)
+        formparams = {}
+        formparams['sec'] = self.id
+        if not skiptypes:
+            formparams['skipmeta'] = u'0'
+        schema = self.schema
+        # compute entities
+        entities = sorted(eschema for eschema in schema.entities()
+                          if not (eschema.is_final() or eschema in skiptypes))
+        # compute relations
+        if display_relations:
+            relations = sorted(rschema for rschema in schema.relations()
+                               if not (rschema.is_final()
+                                       or rschema in skiptypes
+                                       or rschema in META_RTYPES))
+        else:
+            relations = []
+        # index
+        _ = self.req._
+        self.w(u'<div id="schema_security"><a id="index" href="index"/>')
+        self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
+        self.w(u'<h4>%s</h4>' %   _('Entities').capitalize())
+        ents = []
+        for eschema in sorted(entities):
+            url = xml_escape(self.build_url('schema', **formparams))
+            ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % (
+                url,  eschema.type, eschema.type, _(eschema.type)))
+        self.w(u', '.join(ents))
+        self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
+        rels = []
+        for rschema in sorted(relations):
+            url = xml_escape(self.build_url('schema', **formparams))
+            rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' %  (
+                url , rschema.type, rschema.type, _(rschema.type)))
+        self.w(u', '.join(ents))
+        # entities
+        self.display_entities(entities, formparams)
+        # relations
+        if relations:
+            self.display_relations(relations, formparams)
+        self.w(u'</div>')
 
-    title = _("site schema")
-    category = 'siteactions'
-    order = 30
+    def display_entities(self, entities, formparams):
+        _ = self.req._
+        self.w(u'<a id="entities" href="entities"/>')
+        self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
+        for eschema in entities:
+            self.w(u'<a id="%s" href="%s"/>' %  (eschema.type, eschema.type))
+            self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
+            url = xml_escape(self.build_url('schema', **formparams) + '#index')
+            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
+                url,  self.req.external_resource('UP_ICON'), _('up')))
+            self.w(u'</h3>')
+            self.w(u'<div style="margin: 0px 1.5em">')
+            self.schema_definition(eschema, link=False)
+            # display entity attributes only if they have some permissions modified
+            modified_attrs = []
+            for attr, etype in  eschema.attribute_definitions():
+                if self.has_schema_modified_permissions(attr, attr.ACTIONS):
+                    modified_attrs.append(attr)
+            if  modified_attrs:
+                self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
+                self.w(u'</div>')
+                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.schema_definition(attr, link=False)
+            self.w(u'</div>')
 
-    def url(self):
-        return self.build_url(self.id)
+    def display_relations(self, relations, formparams):
+        _ = self.req._
+        self.w(u'<a id="relations" href="relations"/>')
+        self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
+        for rschema in relations:
+            self.w(u'<a id="%s" href="%s"/>' %  (rschema.type, rschema.type))
+            self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
+            url = xml_escape(self.build_url('schema', **formparams) + '#index')
+            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
+                url,  self.req.external_resource('UP_ICON'), _('up')))
+            self.w(u'</h3>')
+            self.w(u'<div style="margin: 0px 1.5em">')
+            subjects = [str(subj) for subj in rschema.subjects()]
+            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
+                _('subject_plural:'),
+                ', '.join(str(subj) for subj in rschema.subjects()),
+                ', '.join(_(str(subj)) for subj in rschema.subjects())))
+            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
+                _('object_plural:'),
+                ', '.join(str(obj) for obj in rschema.objects()),
+                ', '.join(_(str(obj)) for obj in rschema.objects())))
+            self.schema_definition(rschema, link=False)
+            self.w(u'</div>')
 
 
+class SchemaUreportsView(StartupView):
+    id = 'schema-block'
+
+    def call(self):
+        viewer = SchemaViewer(self.req)
+        layout = viewer.visit_schema(self.schema, display_relations=True,
+                                     skiptypes=skip_types(self.req))
+        self.w(uilib.ureport_as_html(layout))
+
+
+# CWAttribute / CWRelation #####################################################
+
 class CWRDEFPrimaryView(primary.PrimaryView):
     __select__ = implements('CWAttribute', 'CWRelation')
     cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
@@ -57,14 +207,11 @@
         if final:
             self.w(u'</em>')
 
-SKIPPED_RELS = ('is', 'is_instance_of', 'identity', 'created_by', 'owned_by',
-                'has_text',)
 
 class CWETypePrimaryView(tabs.TabsMixin, primary.PrimaryView):
     __select__ = implements('CWEType')
     title = _('in memory entity schema')
     main_related_section = False
-    skip_rels = SKIPPED_RELS
     tabs = [_('cwetype-schema-text'), _('cwetype-schema-image'),
             _('cwetype-schema-permissions'), _('cwetype-workflow')]
     default_tab = 'cwetype-schema-text'
@@ -183,94 +330,59 @@
 
 # schema images ###############################################################
 
-class RestrictedSchemaDotPropsHandler(s2d.SchemaDotPropsHandler):
-    def __init__(self, req):
-        # FIXME: colors are arbitrary
-        self.nextcolor = cycle( ('#aa0000', '#00aa00', '#0000aa',
-                                 '#000000', '#888888') ).next
+class RestrictedSchemaVisitorMixIn(object):
+    def __init__(self, req, *args, **kwargs):
         self.req = req
-
-    def display_attr(self, rschema):
-        return not rschema.meta and (rschema.has_local_role('read')
-                                     or rschema.has_perm(self.req, 'read'))
+        super(RestrictedSchemaVisitorMixIn, self).__init__(*args, **kwargs)
 
-    # XXX remove this method once yams > 0.20 is out
-    def node_properties(self, eschema):
-        """return default DOT drawing options for an entity schema"""
-        label = ['{', eschema.type, '|']
-        label.append(r'\l'.join(rel.type for rel in eschema.subject_relations()
-                                if rel.final and self.display_attr(rel)))
-        label.append(r'\l}') # trailing \l ensure alignement of the last one
-        return {'label' : ''.join(label), 'shape' : "record",
-                'fontname' : "Courier", 'style' : "filled"}
+    def should_display_schema(self, rschema):
+        return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema)
+                and (rschema.has_local_role('read')
+                     or rschema.has_perm(self.req, 'read')))
 
-    def edge_properties(self, rschema, subjnode, objnode):
-        kwargs = super(RestrictedSchemaDotPropsHandler, self).edge_properties(rschema, subjnode, objnode)
-        # symetric rels are handled differently, let yams decide what's best
-        if not rschema.symetric:
-            kwargs['color'] = self.nextcolor()
-        kwargs['fontcolor'] = kwargs['color']
-        # dot label decoration is just awful (1 line underlining the label
-        # + 1 line going to the closest edge spline point)
-        kwargs['decorate'] = 'false'
-        return kwargs
+    def should_display_attr(self, rschema):
+        return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema)
+                and (rschema.has_local_role('read')
+                     or rschema.has_perm(self.req, 'read')))
 
 
-class RestrictedSchemaVisitorMiIn:
-    def __init__(self, req, *args, **kwargs):
-        # hack hack hack
-        assert len(self.__class__.__bases__) == 2
-        self.__parent = self.__class__.__bases__[1]
-        self.__parent.__init__(self, *args, **kwargs)
-        self.req = req
-
-    def nodes(self):
-        for etype, eschema in self.__parent.nodes(self):
-            if eschema.has_local_role('read') or eschema.has_perm(self.req, 'read'):
-                yield eschema.type, eschema
-
-    def edges(self):
-        for setype, oetype, rschema in self.__parent.edges(self):
-            if rschema.has_local_role('read') or rschema.has_perm(self.req, 'read'):
-                yield setype, oetype, rschema
-
-
-class FullSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.FullSchemaVisitor):
+class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor):
     pass
 
-class OneHopESchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopESchemaVisitor):
+class OneHopESchemaVisitor(RestrictedSchemaVisitorMixIn,
+                           s2d.OneHopESchemaVisitor):
     pass
 
-class OneHopRSchemaVisitor(RestrictedSchemaVisitorMiIn, s2d.OneHopRSchemaVisitor):
+class OneHopRSchemaVisitor(RestrictedSchemaVisitorMixIn,
+                           s2d.OneHopRSchemaVisitor):
     pass
 
 
 class SchemaImageView(TmpFileViewMixin, StartupView):
     id = 'schemagraph'
+    content_type = 'image/png'
 
-    content_type = 'image/png'
-    skip_rels = SKIPPED_RELS
     def _generate(self, tmpfile):
         """display global schema information"""
-        skipmeta = not int(self.req.form.get('withmeta', 0))
-        visitor = FullSchemaVisitor(self.req, self.schema, skiprels=self.skip_rels, skipmeta=skipmeta)
-        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
-                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))
+        print 'skipedtypes', skip_types(self.req)
+        visitor = FullSchemaVisitor(self.req, self.schema,
+                                    skiptypes=skip_types(self.req))
+        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
+
 
 class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
     id = 'schemagraph'
     __select__ = implements('CWEType')
-
     content_type = 'image/png'
-    skip_rels = SKIPPED_RELS
 
     def _generate(self, tmpfile):
         """display schema information for an entity"""
         entity = self.entity(self.row, self.col)
         eschema = self.vreg.schema.eschema(entity.name)
-        visitor = OneHopESchemaVisitor(self.req, eschema, skiprels=self.skip_rels)
-        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
-                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))
+        visitor = OneHopESchemaVisitor(self.req, eschema,
+                                       skiptypes=skip_types(self.req))
+        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
+
 
 class CWRTypeSchemaImageView(CWETypeSchemaImageView):
     __select__ = implements('CWRType')
@@ -280,12 +392,23 @@
         entity = self.entity(self.row, self.col)
         rschema = self.vreg.schema.rschema(entity.name)
         visitor = OneHopRSchemaVisitor(self.req, rschema)
-        s2d.schema2dot(outputfile=tmpfile, visitor=visitor,
-                       prophdlr=RestrictedSchemaDotPropsHandler(self.req))
+        s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
+
+
+# misc: facets, actions ########################################################
 
-### facets
+class CWFinalFacet(facet.AttributeFacet):
+    id = 'cwfinal-facet'
+    __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType')
+    rtype = 'final'
 
-class CWFinalFacet(AttributeFacet):
-    id = 'cwfinal-facet'
-    __select__ = AttributeFacet.__select__ & implements('CWEType', 'CWRType')
-    rtype = 'final'
+class ViewSchemaAction(action.Action):
+    id = 'schema'
+    __select__ = yes()
+
+    title = _("site schema")
+    category = 'siteactions'
+    order = 30
+
+    def url(self):
+        return self.build_url(self.id)
--- a/web/views/sessions.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/sessions.py	Fri Aug 07 12:20:50 2009 +0200
@@ -22,6 +22,11 @@
         #assert isinstance(self.authmanager, RepositoryAuthenticationManager)
         self._sessions = {}
 
+    def dump_data(self):
+        return self._sessions
+    def restore_data(self, data):
+        self._sessions = data
+
     def current_sessions(self):
         return self._sessions.values()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/views/sparql.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,122 @@
+"""SPARQL integration
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+v__docformat__ = "restructuredtext en"
+
+import rql
+from yams import xy
+
+from lxml import etree
+from lxml.builder import E
+
+from cubicweb.view import StartupView, AnyRsetView
+from cubicweb.web import Redirect, form, formfields, formwidgets as fwdgs
+from cubicweb.web.views import forms, urlrewrite
+try:
+    from cubicweb.spa2rql import Sparql2rqlTranslator
+except ImportError:
+    # fyzz not available (only a recommends)
+    Sparql2rqlTranslator = None
+
+class SparqlForm(forms.FieldsForm):
+    id = 'sparql'
+    sparql = formfields.StringField(help=_('type here a sparql query'))
+    resultvid = formfields.StringField(choices=((_('table'), 'table'),
+                                                (_('sparql xml'), 'sparqlxml')),
+                                       widget=fwdgs.Radio,
+                                       initial='table')
+    form_buttons = [fwdgs.SubmitButton()]
+    @property
+    def action(self):
+        return self.req.url()
+
+
+class SparqlFormView(form.FormViewMixIn, StartupView):
+    id = 'sparql'
+    def call(self):
+        form = self.vreg.select('forms', 'sparql', self.req)
+        self.w(form.form_render())
+        sparql = self.req.form.get('sparql')
+        vid = self.req.form.get('resultvid', 'table')
+        if sparql:
+            try:
+                qinfo = Sparql2rqlTranslator(self.schema).translate(sparql)
+            except rql.TypeResolverException, ex:
+                self.w(self.req._('can not resolve entity types:') + u' ' + unicode('ex'))
+            except UnsupportedQuery:
+                self.w(self.req._('we are not yet ready to handle this query'))
+            except xy.UnsupportedVocabulary, ex:
+                self.w(self.req._('unknown vocabulary:') + u' ' + unicode('ex'))
+            if vid == 'sparqlxml':
+                url = self.build_url('view', rql=qinfo.finalize(), vid=vid)
+                raise Redirect(url)
+            rset = self.req.execute(qinfo.finalize())
+            self.wview(vid, rset, 'null')
+
+
+## sparql resultset views #####################################################
+
+YAMS_XMLSCHEMA_MAPPING = {
+    'String': 'string',
+    'Int': 'integer',
+    'Float': 'float',
+    'Boolean': 'boolean',
+    'Datetime': 'dateTime',
+    'Date': 'date',
+    'Time': 'time',
+    # XXX the following types don't have direct mapping
+    'Decimal': 'string',
+    'Interval': 'duration',
+    'Password': 'string',
+    'Bytes': 'base64Binary',
+    }
+
+def xmlschema(yamstype):
+    return 'http://www.w3.org/2001/XMLSchema#%s' % YAMS_XMLSCHEMA_MAPPING[yamstype]
+
+class SparqlResultXmlView(AnyRsetView):
+    """The spec can be found here: http://www.w3.org/TR/rdf-sparql-XMLres/
+    """
+    id = 'sparqlxml'
+    content_type = 'application/sparql-results+xml'
+    templatable = False
+
+    def call(self):
+        # XXX handle UNION
+        rqlst = self.rset.syntax_tree().children[0]
+        varnames = [var.name for var in rqlst.selection]
+        results = E.results()
+        for rowidx in xrange(len(self.rset)):
+            result = E.result()
+            for colidx, varname in enumerate(varnames):
+                result.append(self.cell_binding(rowidx, colidx, varname))
+            results.append(result)
+        sparql = E.sparql(E.head(*(E.variable(name=name) for name in varnames)),
+                          results)
+        self.w(u'<?xml version="1.0"?>\n')
+        self.w(etree.tostring(sparql, encoding=unicode, pretty_print=True))
+
+    def cell_binding(self, row, col, varname):
+        celltype = self.rset.description[row][col]
+        if self.schema.eschema(celltype).is_final():
+            cellcontent = self.view('cell', self.rset, row=row, col=col)
+            return E.binding(E.literal(cellcontent,
+                                       datatype=xmlschema(celltype)),
+                             name=varname)
+        else:
+            entity = self.entity(row, col)
+            return E.binding(E.uri(entity.absolute_url()), name=varname)
+
+    def set_request_content_type(self):
+        """overriden to set the correct filetype and filename"""
+        self.req.set_content_type(self.content_type,
+                                  filename='sparql.xml',
+                                  encoding=self.req.encoding)
+
+def registration_callback(vreg):
+    if Sparql2rqlTranslator is not None:
+        vreg.register_all(globals().values(), __name__)
--- a/web/views/startup.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/startup.py	Fri Aug 07 12:20:50 2009 +0200
@@ -15,14 +15,11 @@
 from cubicweb.view import StartupView
 from cubicweb.selectors import match_user_groups, implements
 from cubicweb.schema import display_name
-from cubicweb.common.uilib import ureport_as_html
 from cubicweb.web import ajax_replace_url, uicfg, httpcache
-from cubicweb.web.views import tabs
-from cubicweb.web.views.management import SecurityViewMixIn
 
 class ManageView(StartupView):
     id = 'manage'
-    title = _('view_manage')
+    title = _('manage')
     http_cache_manager = httpcache.EtagHTTPCacheManager
 
     @classmethod
@@ -32,8 +29,6 @@
                 uicfg.indexview_etype_section.setdefault(eschema, 'schema')
             elif eschema.is_subobject(strict=True):
                 uicfg.indexview_etype_section.setdefault(eschema, 'subobject')
-            elif eschema.meta:
-                uicfg.indexview_etype_section.setdefault(eschema, 'system')
             else:
                 uicfg.indexview_etype_section.setdefault(eschema, 'application')
 
@@ -41,7 +36,7 @@
         return False
 
     def call(self, **kwargs):
-        """The default view representing the application's management"""
+        """The default view representing the instance's management"""
         self.req.add_css('cubicweb.manageview.css')
         self.w(u'<div>\n')
         if not self.display_folders():
@@ -81,14 +76,14 @@
 
     def folders(self):
         self.w(u'<h4>%s</h4>\n' % self.req._('Browse by category'))
-        self.vreg.select_view('tree', self.req, None).render(w=self.w)
+        self.vreg['views'].select('tree', self.req).render(w=self.w)
 
     def startup_views(self):
         self.w(u'<h4>%s</h4>\n' % self.req._('Startup views'))
         self.startupviews_table()
 
     def startupviews_table(self):
-        for v in self.vreg.possible_views(self.req, None):
+        for v in self.vreg['views'].possible_views(self.req, None):
             if v.category != 'startupview' or v.id in ('index', 'tree', 'manage'):
                 continue
             self.w('<p><a href="%s">%s</a></p>' % (
@@ -140,11 +135,7 @@
             etype = eschema.type
             label = display_name(req, etype, 'plural')
             nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
-            if nb > 1:
-                view = self.vreg.select_view('list', req, req.etype_rset(etype))
-                url = view.url()
-            else:
-                url = self.build_url('view', rql='%s X' % etype)
+            url = self.build_url(etype)
             etypelink = u'&nbsp;<a href="%s">%s</a> (%d)' % (
                 xml_escape(url), label, nb)
             yield (label, etypelink, self.add_entity_link(eschema, req))
@@ -165,157 +156,3 @@
     def display_folders(self):
         return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0]
 
-class SchemaView(tabs.TabsMixin, StartupView):
-    id = 'schema'
-    title = _('application schema')
-    tabs = [_('schema-text'), _('schema-image')]
-    default_tab = 'schema-text'
-
-    def call(self):
-        """display schema information"""
-        self.req.add_js('cubicweb.ajax.js')
-        self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
-        self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
-        self.render_tabs(self.tabs, self.default_tab)
-
-
-class SchemaTabImageView(StartupView):
-    id = 'schema-image'
-
-    def call(self):
-        self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
-                 u'meta-data, but you can also display a <a href="%s">complete '
-                 u'schema with meta-data</a>.</div>')
-               % xml_escape(self.build_url('view', vid='schemagraph', withmeta=1)))
-        self.w(u'<img src="%s" alt="%s"/>\n' % (
-            xml_escape(self.req.build_url('view', vid='schemagraph', withmeta=0)),
-            self.req._("graphical representation of the application'schema")))
-
-
-class SchemaTabTextView(StartupView):
-    id = 'schema-text'
-
-    def call(self):
-        rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
-                                'X final FALSE')
-        self.wview('table', rset, displayfilter=True)
-
-
-class ManagerSchemaPermissionsView(StartupView, SecurityViewMixIn):
-    id = 'schema-security'
-    __select__ = StartupView.__select__ & match_user_groups('managers')
-
-    def call(self, display_relations=True,
-             skiprels=('is', 'is_instance_of', 'identity', 'owned_by', 'created_by')):
-        self.req.add_css('cubicweb.acl.css')
-        _ = self.req._
-        formparams = {}
-        formparams['sec'] = self.id
-        formparams['withmeta'] = int(self.req.form.get('withmeta', True))
-        schema = self.schema
-        # compute entities
-        entities = [eschema for eschema in schema.entities()
-                   if not eschema.is_final()]
-        if not formparams['withmeta']:
-            entities = [eschema for eschema in entities
-                        if not eschema.meta]
-        # compute relations
-        if display_relations:
-            relations = [rschema for rschema in schema.relations()
-                         if not (rschema.is_final() or rschema.type in skiprels)]
-            if not formparams['withmeta']:
-                relations = [rschema for rschema in relations
-                             if not rschema.meta]
-        else:
-            relations = []
-        # index
-        self.w(u'<div id="schema_security"><a id="index" href="index"/>')
-        self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
-        self.w(u'<h4>%s</h4>' %   _('Entities').capitalize())
-        ents = []
-        for eschema in sorted(entities):
-            url = xml_escape(self.build_url('schema', **formparams))
-            ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % (
-                url,  eschema.type, eschema.type, _(eschema.type)))
-        self.w(u', '.join(ents))
-        self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
-        rels = []
-        for rschema in sorted(relations):
-            url = xml_escape(self.build_url('schema', **formparams))
-            rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' %  (
-                url , rschema.type, rschema.type, _(rschema.type)))
-        self.w(u', '.join(ents))
-        # entities
-        self.display_entities(entities, formparams)
-        # relations
-        if relations:
-            self.display_relations(relations, formparams)
-        self.w(u'</div>')
-
-    def display_entities(self, entities, formparams):
-        _ = self.req._
-        self.w(u'<a id="entities" href="entities"/>')
-        self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
-        for eschema in sorted(entities):
-            self.w(u'<a id="%s" href="%s"/>' %  (eschema.type, eschema.type))
-            self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
-            url = xml_escape(self.build_url('schema', **formparams) + '#index')
-            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url,  self.req.external_resource('UP_ICON'), _('up')))
-            self.w(u'</h3>')
-            self.w(u'<div style="margin: 0px 1.5em">')
-            self.schema_definition(eschema, link=False)
-
-            # display entity attributes only if they have some permissions modified
-            modified_attrs = []
-            for attr, etype in  eschema.attribute_definitions():
-                if self.has_schema_modified_permissions(attr, attr.ACTIONS):
-                    modified_attrs.append(attr)
-            if  modified_attrs:
-                self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
-                self.w(u'</div>')
-                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.schema_definition(attr, link=False)
-                self.w(u'</div>')
-            else:
-                self.w(u'</div>')
-
-
-    def display_relations(self, relations, formparams):
-        _ = self.req._
-        self.w(u'<a id="relations" href="relations"/>')
-        self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
-        for rschema in sorted(relations):
-            self.w(u'<a id="%s" href="%s"/>' %  (rschema.type, rschema.type))
-            self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
-            url = xml_escape(self.build_url('schema', **formparams) + '#index')
-            self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url,  self.req.external_resource('UP_ICON'), _('up')))
-            self.w(u'</h3>')
-            self.w(u'<div style="margin: 0px 1.5em">')
-            subjects = [str(subj) for subj in rschema.subjects()]
-            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('subject_plural:'),
-                                                ', '.join( [str(subj) for subj in rschema.subjects()]),
-                                                ', '.join( [_(str(subj)) for subj in rschema.subjects()])))
-            self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('object_plural:'),
-                                                ', '.join( [str(obj) for obj in rschema.objects()]),
-                                                ', '.join( [_(str(obj)) for obj in rschema.objects()])))
-            self.schema_definition(rschema, link=False)
-            self.w(u'</div>')
-
-
-class SchemaUreportsView(StartupView):
-    id = 'schematext'
-
-    def call(self):
-        from cubicweb.schemaviewer import SchemaViewer
-        skipmeta = int(self.req.form.get('skipmeta', True))
-        schema = self.schema
-        viewer = SchemaViewer(self.req)
-        layout = viewer.visit_schema(schema, display_relations=True,
-                                     skiprels=('is', 'is_instance_of', 'identity',
-                                               'owned_by', 'created_by'),
-                                     skipmeta=skipmeta)
-        self.w(ureport_as_html(layout))
-
-
--- a/web/views/tableview.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/tableview.py	Fri Aug 07 12:20:50 2009 +0200
@@ -34,8 +34,8 @@
             return ()
         rqlst.save_state()
         mainvar, baserql = prepare_facets_rqlst(rqlst, self.rset.args)
-        wdgs = [facet.get_widget() for facet in self.vreg.possible_vobjects(
-            'facets', self.req, self.rset, context='tablefilter',
+        wdgs = [facet.get_widget() for facet in self.vreg['facets'].possible_vobjects(
+            self.req, rset=self.rset, context='tablefilter',
             filtered_variable=mainvar)]
         wdgs = [wdg for wdg in wdgs if wdg is not None]
         rqlst.recover()
@@ -143,7 +143,7 @@
             actions += self.show_hide_actions(divid, True)
         self.w(u'<div id="%s"' % divid)
         if displayactions:
-            for action in self.vreg.possible_actions(req, self.rset).get('mainactions', ()):
+            for action in self.vreg['actions'].possible_actions(req, self.rset).get('mainactions', ()):
                 actions.append( (action.url(), req._(action.title), action.html_class(), None) )
             self.w(u' cubicweb:displayactions="1">') # close <div tag
         else:
--- a/web/views/tabs.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/tabs.py	Fri Aug 07 12:20:50 2009 +0200
@@ -86,7 +86,7 @@
         selected_tabs = []
         for tab in tabs:
             try:
-                self.vreg.select_view(tab, self.req, self.rset)
+                self.vreg['views'].select(tab, self.req, rset=self.rset)
                 selected_tabs.append(tab)
             except NoSelectableObject:
                 continue
@@ -107,11 +107,8 @@
         active_tab = self.active_tab(tabs, default)
         # build the html structure
         w = self.w
-        if entity:
-            w(u'<div id="entity-tabs-%s">' % entity.eid)
-        else:
-            uid = make_uid('tab')
-            w(u'<div id="entity-tabs-%s">' % uid)
+        uid = entity and entity.eid or make_uid('tab')
+        w(u'<div id="entity-tabs-%s">' % uid)
         w(u'<ul>')
         for tab in tabs:
             w(u'<li>')
@@ -132,14 +129,14 @@
             w(u'</div>')
         # call the set_tab() JS function *after* each tab is generated
         # because the callback binding needs to be done before
-        self.req.add_onload(u"""
-   jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s });
-   set_tab('%(vid)s', '%(cookiename)s');
- """ % {'tabindex'   : tabs.index(active_tab),
-        'vid'        : active_tab,
-        'eeid'       : (entity and entity.eid or uid),
-        'cookiename' : self.cookie_name})
-
+        # XXX make work history: true
+        self.req.add_onload(u'''
+  jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s });
+  set_tab('%(vid)s', '%(cookiename)s');
+''' % {'tabindex'   : tabs.index(active_tab),
+       'vid'        : active_tab,
+       'eeid'       : (entity and entity.eid or uid),
+       'cookiename' : self.cookie_name})
 
 class EntityRelationView(EntityView):
     """view displaying entity related stuff.
--- a/web/views/timetable.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/timetable.py	Fri Aug 07 12:20:50 2009 +0200
@@ -138,7 +138,7 @@
         for user, width in zip(users, widths):
             self.w(u'<th colspan="%s">' % max(MIN_COLS, width))
             if user != u"*":
-                user.view('secondary', w=self.w)
+                user.view('oneline', w=self.w)
             else:
                 self.w(user)
             self.w(u'</th>')
--- a/web/views/treeview.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/treeview.py	Fri Aug 07 12:20:50 2009 +0200
@@ -16,7 +16,7 @@
 from cubicweb.view import EntityView
 
 def treecookiename(treeid):
-    return str('treestate-%s' % treeid)
+    return str('%s-treestate' % treeid)
 
 class TreeView(EntityView):
     id = 'treeview'
@@ -26,7 +26,7 @@
 
     def call(self, subvid=None, treeid=None, initial_load=True):
         if subvid is None:
-            subvid = self.req.form.pop('subvid', 'oneline') # consume it
+            subvid = self.req.form.pop('treesubvid', 'oneline') # consume it
         if treeid is None:
             treeid = self.req.form.pop('treeid', None)
             if treeid is None:
@@ -117,7 +117,7 @@
                                              pageid=self.req.pageid,
                                              treeid=treeid,
                                              fname='view',
-                                             subvid=vid))
+                                             treesubvid=vid))
             divclasses = ['hitarea']
             if is_open:
                 liclasses.append('collapsable')
--- a/web/views/urlpublishing.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/urlpublishing.py	Fri Aug 07 12:20:50 2009 +0200
@@ -56,8 +56,7 @@
         super(URLPublisherComponent, self).__init__()
         self.default_method = default_method
         evaluators = []
-        for evaluatorcls in self.vreg.registry_objects('components',
-                                                       'urlpathevaluator'):
+        for evaluatorcls in self.vreg['components']['urlpathevaluator']:
             # instantiation needed
             evaluator = evaluatorcls(self)
             evaluators.append(evaluator)
@@ -83,7 +82,7 @@
         parts = [part for part in path.split('/')
                  if part != ''] or (self.default_method,)
         if req.form.get('rql'):
-            if parts[0] in self.vreg.registry('controllers'):
+            if parts[0] in self.vreg['controllers']:
                 return parts[0], None
             return 'view', None
         for evaluator in self.evaluators:
@@ -114,7 +113,7 @@
     """
     priority = 0
     def evaluate_path(self, req, parts):
-        if len(parts) == 1 and parts[0] in self.vreg.registry('controllers'):
+        if len(parts) == 1 and parts[0] in self.vreg['controllers']:
             return parts[0], None
         raise PathDontMatch()
 
@@ -152,7 +151,7 @@
             etype = self.vreg.case_insensitive_etypes[parts.pop(0).lower()]
         except KeyError:
             raise PathDontMatch()
-        cls = self.vreg.etype_class(etype)
+        cls = self.vreg['etypes'].etype_class(etype)
         if parts:
             if len(parts) == 2:
                 attrname = parts.pop(0).lower()
@@ -195,10 +194,9 @@
     def evaluate_path(self, req, parts):
         # uri <=> req._twreq.path or req._twreq.uri
         uri = req.url_unquote('/' + '/'.join(parts))
-        vobjects = sorted(self.vreg.registry_objects('urlrewriting'),
-                          key=lambda x: x.priority,
-                          reverse=True)
-        for rewritercls in vobjects:
+        evaluators = sorted(self.vreg['urlrewriting'].all_objects(),
+                            key=lambda x: x.priority, reverse=True)
+        for rewritercls in evaluators:
             rewriter = rewritercls()
             try:
                 # XXX we might want to chain url rewrites
@@ -220,8 +218,9 @@
         # remove last part and see if this is something like an actions
         # if so, call
         try:
+            actionsreg = self.vreg['actions']
             requested = parts.pop(-1)
-            actions = self.vreg.registry_objects('actions', requested)
+            actions = actionsreg[requested]
         except RegistryException:
             raise PathDontMatch()
         for evaluator in self.urlpublisher.evaluators:
@@ -233,9 +232,9 @@
                 continue
             else:
                 try:
-                    action = self.vreg.select(actions, req, rset)
+                    action = actionsreg.select_best(actions, req, rset=rset)
                 except RegistryException:
-                    raise PathDontMatch()
+                    continue
                 else:
                     # XXX avoid redirect
                     raise Redirect(action.url())
--- a/web/views/urlrewrite.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/urlrewrite.py	Fri Aug 07 12:20:50 2009 +0200
@@ -54,8 +54,6 @@
     __metaclass__ = metarewriter
     __registry__ = 'urlrewriting'
     __abstract__ = True
-
-    id = 'urlrewriting'
     priority = 1
 
     def rewrite(self, req, uri):
@@ -76,9 +74,11 @@
         ('/index', dict(vid='index')),
         ('/myprefs', dict(vid='propertiesform')),
         ('/siteconfig', dict(vid='systempropertiesform')),
+        ('/siteinfo', dict(vid='info')),
         ('/manage', dict(vid='manage')),
         ('/notfound', dict(vid='404')),
         ('/error', dict(vid='error')),
+        ('/sparql', dict(vid='sparql')),
         (rgx('/schema/([^/]+?)/?'),  dict(vid='eschema', rql=r'Any X WHERE X is CWEType, X name "\1"')),
         (rgx('/add/([^/]+?)/?'), dict(vid='creation', etype=r'\1')),
         (rgx('/doc/images/(.+?)/?'), dict(vid='wdocimages', fid=r'\1')),
--- a/web/views/workflow.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/workflow.py	Fri Aug 07 12:20:50 2009 +0200
@@ -18,6 +18,7 @@
 from cubicweb.selectors import (implements, has_related_entities,
                                 relation_possible, match_form_params)
 from cubicweb.interfaces import IWorkflowable
+from cubicweb.view import EntityView
 from cubicweb.web import stdmsgs, action, component, form
 from cubicweb.web.form import FormViewMixIn
 from cubicweb.web.formfields import StringField,  RichTextField
@@ -48,13 +49,12 @@
     def cell_call(self, row, col):
         entity = self.entity(row, col)
         state = entity.in_state[0]
-        transition = self.req.eid_rset(self.req.form['treid']).get_entity(0, 0)
+        transition = self.req.entity_from_eid(self.req.form['treid'])
         dest = transition.destination()
         _ = self.req._
-        form = self.vreg.select_object('forms', 'changestate', self.req,
-                                       self.rset, row=row, col=col,
-                                       entity=entity,
-                                       redirect_path=self.redirectpath(entity))
+        form = self.vreg.select('forms', 'changestate', self.req, rset=self.rset,
+                                row=row, col=col, entity=entity,
+                                redirect_path=self.redirectpath(entity))
         self.w(form.error_message())
         self.w(u'<h4>%s %s</h4>\n' % (_(transition.name),
                                       entity.view('oneline')))
@@ -69,12 +69,9 @@
         return entity.rest_path()
 
 
-class WFHistoryVComponent(component.EntityVComponent):
-    """display the workflow history for entities supporting it"""
+class WFHistoryView(EntityView):
     id = 'wfhistory'
-    __select__ = (component.EntityVComponent.__select__
-                  & relation_possible('wf_info_for', role='object'))
-    context = 'navcontentbottom'
+    __select__ = relation_possible('wf_info_for', role='object')
     title = _('Workflow history')
 
     def cell_call(self, row, col, view=None):
@@ -104,6 +101,16 @@
                        displaycols=displaycols, headers=headers)
 
 
+class WFHistoryVComponent(component.EntityVComponent):
+    """display the workflow history for entities supporting it"""
+    id = 'wfhistory'
+    __select__ = WFHistoryView.__select__ & component.EntityVComponent.__select__
+    context = 'navcontentbottom'
+    title = _('Workflow history')
+
+    def cell_call(self, row, col, view=None):
+        self.wview('wfhistory', self.rset, row=row, col=col, view=view)
+
 # workflow entity types views #################################################
 
 class CellView(view.EntityView):
@@ -111,7 +118,7 @@
     __select__ = implements('TrInfo')
 
     def cell_call(self, row, col, cellvid=None):
-        self.w(self.entity(row, col).printable_value('comment'))
+        self.w(self.entity(row, col).view('reledit', rtype='comment'))
 
 
 class StateInContextView(view.EntityView):
--- a/web/views/xmlrss.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/views/xmlrss.py	Fri Aug 07 12:20:50 2009 +0200
@@ -13,11 +13,9 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb.selectors import non_final_entity, one_line_rset, appobject_selectable
-from cubicweb.view import EntityView, AnyRsetView
-from cubicweb.web.httpcache import MaxAgeHTTPCacheManager
-from cubicweb.web.component import Component
-from cubicweb.web.box import BoxTemplate
+from cubicweb.view import EntityView, AnyRsetView, Component
 from cubicweb.common.uilib import simple_sgml_tag
+from cubicweb.web import httpcache, box
 
 
 # base xml views ##############################################################
@@ -122,10 +120,10 @@
         return self.entity(0, 0).rss_feed_url()
 
 
-class RSSIconBox(BoxTemplate):
+class RSSIconBox(box.BoxTemplate):
     """just display the RSS icon on uniform result set"""
     id = 'rss'
-    __select__ = (BoxTemplate.__select__
+    __select__ = (box.BoxTemplate.__select__
                   & appobject_selectable('components', 'rss_feed_url'))
 
     visible = False
@@ -137,7 +135,8 @@
         except KeyError:
             self.error('missing RSS_LOGO external resource')
             return
-        urlgetter = self.vreg.select_component('rss_feed_url', self.req, self.rset)
+        urlgetter = self.vreg['components'].select('rss_feed_url', self.req,
+                                                   rset=self.rset)
         url = urlgetter.feed_url()
         self.w(u'<a href="%s"><img src="%s" alt="rss"/></a>\n' % (xml_escape(url), rss))
 
@@ -147,7 +146,7 @@
     title = _('rss')
     templatable = False
     content_type = 'text/xml'
-    http_cache_manager = MaxAgeHTTPCacheManager
+    http_cache_manager = httpcache.MaxAgeHTTPCacheManager
     cache_max_age = 60*60*2 # stay in http cache for 2 hours by default
 
     def _open(self):
--- a/web/webconfig.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/webconfig.py	Fri Aug 07 12:20:50 2009 +0200
@@ -1,4 +1,4 @@
-"""common web configuration for twisted/modpython applications
+"""common web configuration for twisted/modpython instances
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -60,11 +60,11 @@
 
 
 class WebConfiguration(CubicWebConfiguration):
-    """the WebConfiguration is a singleton object handling application's
+    """the WebConfiguration is a singleton object handling instance's
     configuration and preferences
     """
-    cubicweb_vobject_path = CubicWebConfiguration.cubicweb_vobject_path | set(['web/views'])
-    cube_vobject_path = CubicWebConfiguration.cube_vobject_path | set(['views'])
+    cubicweb_appobject_path = CubicWebConfiguration.cubicweb_appobject_path | set(['web/views'])
+    cube_appobject_path = CubicWebConfiguration.cube_appobject_path | set(['views'])
 
     options = merge_options(CubicWebConfiguration.options + (
         ('anonymous-user',
@@ -83,13 +83,13 @@
         ('query-log-file',
          {'type' : 'string',
           'default': None,
-          'help': 'web application query log file',
+          'help': 'web instance query log file',
           'group': 'main', 'inputlevel': 2,
           }),
-        ('pyro-application-id',
+        ('pyro-instance-id',
          {'type' : 'string',
-          'default': Method('default_application_id'),
-          'help': 'CubicWeb application identifier in the Pyro name server',
+          'default': Method('default_instance_id'),
+          'help': 'CubicWeb instance identifier in the Pyro name server',
           'group': 'pyro-client', 'inputlevel': 1,
           }),
         # web configuration
@@ -145,6 +145,13 @@
           'sessions. Default to 2 min.',
           'group': 'web', 'inputlevel': 2,
           }),
+        ('force-html-content-type',
+         {'type' : 'yn',
+          'default': False,
+          'help': 'force text/html content type for your html pages instead of cubicweb user-agent based'\
+          'deduction of an appropriate content type',
+          'group': 'web', 'inputlevel': 2,
+          }),
         ('embed-allowed',
          {'type' : 'regexp',
           'default': None,
@@ -156,7 +163,7 @@
         ('submit-url',
          {'type' : 'string',
           'default': Method('default_submit_url'),
-          'help': ('URL that may be used to report bug in this application '
+          'help': ('URL that may be used to report bug in this instance '
                    'by direct access to the project\'s (jpl) tracker, '
                    'if you want this feature on. The url should looks like '
                    'http://mytracker.com/view?__linkto=concerns:1234:subject&etype=Ticket&type=bug&vid=creation '
@@ -168,7 +175,7 @@
         ('submit-mail',
          {'type' : 'string',
           'default': None,
-          'help': ('Mail used as recipient to report bug in this application, '
+          'help': ('Mail used as recipient to report bug in this instance, '
                    'if you want this feature on'),
           'group': 'web', 'inputlevel': 2,
           }),
@@ -215,7 +222,7 @@
     # don't use @cached: we want to be able to disable it while this must still
     # be cached
     def repository(self, vreg=None):
-        """return the application's repository object"""
+        """return the instance's repository object"""
         try:
             return self.__repo
         except AttributeError:
@@ -223,7 +230,7 @@
             if self.repo_method == 'inmemory':
                 repo = get_repository('inmemory', vreg=vreg, config=self)
             else:
-                repo = get_repository('pyro', self['pyro-application-id'],
+                repo = get_repository('pyro', self['pyro-instance-id'],
                                       config=self)
             self.__repo = repo
             return repo
@@ -298,7 +305,7 @@
                 yield join(fpath)
 
     def load_configuration(self):
-        """load application's configuration files"""
+        """load instance's configuration files"""
         super(WebConfiguration, self).load_configuration()
         # load external resources definition
         self._build_ext_resources()
--- a/web/webctl.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/webctl.py	Fri Aug 07 12:20:50 2009 +0200
@@ -9,8 +9,8 @@
 __docformat__ = "restructuredtext en"
 
 from cubicweb import underline_title
-from cubicweb.toolsutils import CommandHandler, confirm
-
+from cubicweb.toolsutils import CommandHandler
+from logilab.common.shellutils import ASK
 
 class WebCreateHandler(CommandHandler):
     cmdname = 'create'
@@ -22,9 +22,9 @@
         if config.repo_method == 'pyro':
             print '\n'+underline_title('Repository server configuration')
             config.input_config('pyro-client', inputlevel)
-        if confirm('Allow anonymous access ?', False):
+        if ASK.confirm('Allow anonymous access ?', False):
             config.global_set_option('anonymous-user', 'anon')
             config.global_set_option('anonymous-password', 'anon')
 
     def postcreate(self):
-        """hooks called once application's initialization has been completed"""
+        """hooks called once instance's initialization has been completed"""
--- a/web/widgets.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/web/widgets.py	Fri Aug 07 12:20:50 2009 +0200
@@ -617,7 +617,7 @@
         # first see if its specified by __linkto form parameters
         linkedto = entity.linked_to(self.name, self.role)
         if linkedto:
-            entities = (req.eid_rset(eid).get_entity(0, 0) for eid in linkedto)
+            entities = (req.entity_from_eid(eid) for eid in linkedto)
             return [(entity.view('combobox'), entity.eid) for entity in entities]
         # it isn't, check if the entity provides a method to get correct values
         if not self.required(entity):
--- a/wsgi/handler.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/wsgi/handler.py	Fri Aug 07 12:20:50 2009 +0200
@@ -97,10 +97,7 @@
 #         assert self.base_url[-1] == '/'
 #         self.https_url = config['https-url']
 #         assert not self.https_url or self.https_url[-1] == '/'
-        try:
-            self.url_rewriter = self.appli.vreg.select_component('urlrewriter')
-        except ObjectNotFound:
-            self.url_rewriter = None
+        self.url_rewriter = self.appli.vreg.select_object('components', 'urlrewriter')
 
     def _render(self, req):
         """this function performs the actual rendering
--- a/wsgi/request.py	Fri Aug 07 12:20:37 2009 +0200
+++ b/wsgi/request.py	Fri Aug 07 12:20:50 2009 +0200
@@ -34,7 +34,7 @@
         self._headers = dict([(normalize_header(k[5:]), v) for k, v in self.environ.items()
                               if k.startswith('HTTP_')])
         https = environ.get("HTTPS") in ('yes', 'on', '1')
-        self._base_url = base_url or self.application_uri()
+        self._base_url = base_url or self.instance_uri()
         post, files = self.get_posted_data()
         super(CubicWebWsgiRequest, self).__init__(vreg, https, post)
         if files is not None:
@@ -63,7 +63,7 @@
 
     def relative_path(self, includeparams=True):
         """return the normalized path of the request (ie at least relative
-        to the application's root, but some other normalization may be needed
+        to the instance's root, but some other normalization may be needed
         so that the returned path may be used to compare to generated urls
 
         :param includeparams:
@@ -105,10 +105,10 @@
 
     ## wsgi request helpers ###################################################
 
-    def application_uri(self):
-        """Return the application's base URI (no PATH_INFO or QUERY_STRING)
+    def instance_uri(self):
+        """Return the instance's base URI (no PATH_INFO or QUERY_STRING)
 
-        see python2.5's wsgiref.util.application_uri code
+        see python2.5's wsgiref.util.instance_uri code
         """
         environ = self.environ
         url = environ['wsgi.url_scheme'] + '://'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xy.py	Fri Aug 07 12:20:50 2009 +0200
@@ -0,0 +1,20 @@
+"""map standard cubicweb schema to xml vocabularies
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+
+from yams import xy
+
+xy.register_prefix('http://purl.org/dc/elements/1.1/', 'dc')
+xy.register_prefix('http://xmlns.com/foaf/0.1/', 'foaf')
+xy.register_prefix('http://usefulinc.com/ns/doap#', 'doap')
+
+xy.add_equivalence('creation_date', 'dc:date')
+xy.add_equivalence('created_by', 'dc:creator')
+xy.add_equivalence('description', 'dc:description')
+xy.add_equivalence('CWUser', 'foaf:Person')
+xy.add_equivalence('CWUser login', 'dc:title')
+xy.add_equivalence('CWUser surname', 'foaf:Person foaf:name')