backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 10 Aug 2010 16:05:00 +0200
changeset 6089 b0975c6f2e44
parent 6082 57933567146f (current diff)
parent 6088 28f49a4fe702 (diff)
child 6092 ab4958e2654b
backport stable
web/views/primary.py
--- a/cwconfig.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/cwconfig.py	Tue Aug 10 16:05:00 2010 +0200
@@ -742,7 +742,7 @@
         # XXX extrapath argument to load_module_from_file only in lgc > 0.50.2
         from logilab.common.modutils import load_module_from_modpath, modpath_from_file
         module = load_module_from_modpath(modpath_from_file(sitefile, self.extrapath))
-        self.info('%s loaded', sitefile)
+        self.debug('%s loaded', sitefile)
         return module
 
     def eproperty_definitions(self):
--- a/entity.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/entity.py	Tue Aug 10 16:05:00 2010 +0200
@@ -456,11 +456,15 @@
     def cw_has_perm(self, action):
         return self.e_schema.has_perm(self._cw, action, eid=self.eid)
 
-    def view(self, __vid, __registry='views', w=None, **kwargs): # XXX cw_view
+    def view(self, __vid, __registry='views', w=None, initargs=None, **kwargs): # XXX cw_view
         """shortcut to apply a view on this entity"""
+        if initargs is None:
+            initargs = kwargs
+        else:
+            initargs.update(kwargs)
         view = self._cw.vreg[__registry].select(__vid, self._cw, rset=self.cw_rset,
                                                 row=self.cw_row, col=self.cw_col,
-                                                **kwargs)
+                                                **initargs)
         return view.render(row=self.cw_row, col=self.cw_col, w=w, **kwargs)
 
     def absolute_url(self, *args, **kwargs): # XXX cw_url
--- a/server/schemaserial.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/server/schemaserial.py	Tue Aug 10 16:05:00 2010 +0200
@@ -152,6 +152,8 @@
     for etype, stype in session.execute(
         'Any XN, ETN WHERE X is CWEType, X name XN, X specializes ET, ET name ETN',
         build_descr=False):
+        etype = ETYPE_NAME_MAP.get(etype, etype)
+        stype = ETYPE_NAME_MAP.get(stype, stype)
         schema.eschema(etype)._specialized_type = stype
         schema.eschema(stype)._specialized_by.append(etype)
     for eid, rtype, desc, sym, il, ftc in session.execute(
--- a/web/request.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/web/request.py	Tue Aug 10 16:05:00 2010 +0200
@@ -27,6 +27,7 @@
 from datetime import date
 from urlparse import urlsplit
 from itertools import count
+from warnings import warn
 
 from rql.utils import rqlvar_maker
 
@@ -383,7 +384,6 @@
             try:
                 ret = func(req, *args)
             except TypeError:
-                from warnings import warn
                 warn('[3.2] user callback should now take request as argument')
                 ret = func(*args)
             self.unregister_callback(self.pageid, cbname)
--- a/web/views/primary.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/web/views/primary.py	Tue Aug 10 16:05:00 2010 +0200
@@ -131,7 +131,8 @@
         for rschema, _, role, dispctrl in self._section_def(entity, 'attributes'):
             vid = dispctrl.get('vid', 'reledit')
             if rschema.final or vid == 'reledit' or dispctrl.get('rtypevid'):
-                value = entity.view(vid, rtype=rschema.type, role=role)
+                value = entity.view(vid, rtype=rschema.type, role=role,
+                                    initargs={'dispctrl': dispctrl})
             else:
                 rset = self._relation_rset(entity, rschema, role, dispctrl)
                 if rset:
@@ -159,6 +160,16 @@
 
     def render_entity_relations(self, entity):
         for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'):
+            if rschema.final:
+                self.w(u'<div class="section">')
+                label = self._rel_label(entity, rschema, role, dispctrl)
+                if label:
+                    self.w(u'<h4>%s</h4>' % label)
+                vid = dispctrl.get('vid', 'reledit')
+                entity.view(vid, rtype=rschema.type, role=role, w=self.w,
+                            initargs={'dispctrl': dispctrl})
+                self.w(u'</div>')
+                continue
             rset = self._relation_rset(entity, rschema, role, dispctrl)
             if rset:
                 if support_args(self._render_relation, 'label'):
--- a/web/views/pyviews.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/web/views/pyviews.py	Tue Aug 10 16:05:00 2010 +0200
@@ -15,14 +15,14 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Views to display bare python values
-
+"""Basic views for python values (eg without any result set)
 """
 __docformat__ = "restructuredtext en"
 
 from cubicweb.view import View
 from cubicweb.selectors import match_kwargs
 
+
 class PyValTableView(View):
     __regid__ = 'pyvaltable'
     __select__ = match_kwargs('pyvalue')
--- a/web/views/schema.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/web/views/schema.py	Tue Aug 10 16:05:00 2010 +0200
@@ -113,7 +113,7 @@
         perms = {}
         for rdef in rschema.rdefs.itervalues():
             rdef_perms = []
-            for action in ('read', 'add', 'delete'):
+            for action in rdef.ACTIONS:
                 groups = sorted(rdef.get_groups(action))
                 exprs = sorted(e.expression for e in rdef.get_rqlexprs(action))
                 rdef_perms.append( (action, (tuple(groups), tuple(exprs))) )
--- a/web/views/tabs.py	Tue Aug 10 08:39:06 2010 +0200
+++ b/web/views/tabs.py	Tue Aug 10 16:05:00 2010 +0200
@@ -55,18 +55,20 @@
             urlparams['rql'] = uilib.rql_for_eid(eid)
         elif rset:
             urlparams['rql'] = rset.printable_rql()
+        if tabid is None:
+            tabid = uilib.domid(vid)
         w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
-            tabid or vid, xml_escape(self._cw.build_url('json', **urlparams))))
+            tabid, xml_escape(self._cw.build_url('json', **urlparams))))
         if show_spinbox:
             w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>'
-              % (tabid or vid, self._cw._('(loading ...)')))
+              % (tabid, self._cw._('(loading ...)')))
         else:
-            w(u'<div id="%s-hole"></div>' % (tabid or vid))
+            w(u'<div id="%s-hole"></div>' % tabid)
         w(u'<noscript><p><a class="style: hidden" id="seo-%s" href="%s">%s</a></p></noscript>'
-          % (tabid or vid, xml_escape(self._cw.build_url(**urlparams)), xml_escape('%s (%s)') %
-             (tabid or vid, self._cw._('follow this link if javascript is deactivated'))))
+          % (tabid, xml_escape(self._cw.build_url(**urlparams)), xml_escape('%s (%s)') %
+             (tabid, self._cw._('follow this link if javascript is deactivated'))))
         w(u'</div>')
-        self._prepare_bindings(tabid or vid, reloadable)
+        self._prepare_bindings(tabid, reloadable)
 
     def forceview(self, vid):
         """trigger an event that will force immediate loading of the view
@@ -91,15 +93,16 @@
         cookiename = self.cookie_name
         activetab = cookies.get(cookiename)
         if activetab is None:
-            cookies[cookiename] = default
+            domid = uilib.domid(default)
+            cookies[cookiename] = domid
             self._cw.set_cookie(cookies, cookiename)
-            return default
+            return domid
         return activetab.value
 
     def prune_tabs(self, tabs, default_tab):
         selected_tabs = []
         may_be_active_tab = self.active_tab(default_tab)
-        active_tab = default_tab
+        active_tab = uilib.domid(default_tab)
         viewsvreg = self._cw.vreg['views']
         for tab in tabs:
             try:
@@ -109,13 +112,14 @@
                 tabid, tabkwargs = tab, {}
             tabkwargs.setdefault('rset', self.cw_rset)
             vid = tabkwargs.get('vid', tabid)
+            domid = uilib.domid(tabid)
             try:
                 viewsvreg.select(vid, self._cw, **tabkwargs)
-                selected_tabs.append((tabid, tabkwargs))
             except NoSelectableObject:
                 continue
-            if tabid == may_be_active_tab:
-                active_tab = tabid
+            selected_tabs.append((tabid, domid, tabkwargs))
+            if domid == may_be_active_tab:
+                active_tab = domid
         return selected_tabs, active_tab
 
     def render_tabs(self, tabs, default, entity=None):
@@ -135,21 +139,21 @@
         w(u'<div id="entity-tabs-%s">' % uid)
         w(u'<ul>')
         active_tab_idx = None
-        for i, (tabid, tabkwargs) in enumerate(tabs):
+        for i, (tabid, domid, tabkwargs) in enumerate(tabs):
             w(u'<li>')
-            w(u'<a href="#%s">' % tabid)
-            w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tabid, self.cookie_name))
+            w(u'<a href="#%s">' % domid)
+            w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (domid, self.cookie_name))
             w(tabkwargs.pop('label', self._cw._(tabid)))
             w(u'</span>')
             w(u'</a>')
             w(u'</li>')
-            if tabid == active_tab:
+            if domid == active_tab:
                 active_tab_idx = i
         w(u'</ul>')
         w(u'</div>')
-        for tabid, tabkwargs in tabs:
-            w(u'<div id="%s">' % tabid)
-            tabkwargs.setdefault('tabid', tabid)
+        for tabid, domid, tabkwargs in tabs:
+            w(u'<div id="%s">' % domid)
+            tabkwargs.setdefault('tabid', domid)
             tabkwargs.setdefault('vid', tabid)
             tabkwargs.setdefault('rset', self.cw_rset)
             self.lazyview(**tabkwargs)
@@ -159,9 +163,9 @@
         # XXX make work history: true
         self._cw.add_onload(u"""
   jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s });
-  set_tab('%(vid)s', '%(cookiename)s');
+  set_tab('%(domid)s', '%(cookiename)s');
 """ % {'tabindex'   : active_tab_idx,
-       'vid'        : active_tab,
+       'domid'        : active_tab,
        'eeid'       : (entity and entity.eid or uid),
        'cookiename' : self.cookie_name})