merge stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 06 Oct 2009 17:18:23 +0200
branchstable
changeset 3573 cdb41ceeffc7
parent 3572 606ce53dc557 (diff)
parent 3563 f1dbb9bf4da3 (current diff)
child 3574 f179ccbd13e6
merge
--- a/cwconfig.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/cwconfig.py	Tue Oct 06 17:18:23 2009 +0200
@@ -529,6 +529,11 @@
                 vocab = getattr(self, vocab.method, ())
         return CFGTYPE2ETYPE_MAP[optdict['type']], vocab
 
+    def default_instance_id(self):
+        """return the instance identifier, useful for option which need this
+        as default value
+        """
+        return None
 
 class CubicWebConfiguration(CubicWebNoAppConfiguration):
     """base class for cubicweb server and web configurations"""
--- a/entities/__init__.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/entities/__init__.py	Tue Oct 06 17:18:23 2009 +0200
@@ -183,6 +183,8 @@
         """return (path, parameters) which should be used as redirect
         information when this entity is being deleted
         """
+        if self.parent():
+            return self.parent().rest_path(), {}
         return str(self.e_schema).lower(), {}
 
     def pre_web_edit(self):
--- a/server/hooks.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/server/hooks.py	Tue Oct 06 17:18:23 2009 +0200
@@ -173,18 +173,25 @@
         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')
+            if self.role == 'subject':
+                rql = 'DELETE %s X WHERE X eid %%(x)s, NOT X %s Y'
+            else: # self.role == 'object':
+                rql = 'DELETE %s X WHERE X eid %%(x)s, NOT Y %s X'
+            session.unsafe_execute(rql % (etype, self.rtype), {'x': self.eid}, 'x')
 
 
 def handle_composite_before_del_relation(session, eidfrom, rtype, eidto):
     """delete the object of composite relation"""
+    # if the relation is being delete, don't delete composite's components
+    # automatically
+    pendingrdefs = session.transaction_data.get('pendingrdefs', ())
+    if (session.describe(eidfrom)[0], rtype, session.describe(eidto)[0]) in pendingrdefs:
+        return
     composite = rproperty(session, rtype, eidfrom, eidto, 'composite')
     if composite == 'subject':
-        DelayedDeleteOp(session, eid=eidto, relation='Y %s X' % rtype)
+        DelayedDeleteOp(session, eid=eidto, rtype=rtype, role='object')
     elif composite == 'object':
-        DelayedDeleteOp(session, eid=eidfrom, relation='X %s Y' % rtype)
+        DelayedDeleteOp(session, eid=eidfrom, rtype=rtype, role='subject')
 
 
 def before_del_group(session, eid):
@@ -318,7 +325,6 @@
         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:
@@ -544,7 +550,8 @@
     _change_state(session, entity['wf_info_for'],
                   entity['from_state'], entity['to_state'])
     forentity = session.entity_from_eid(entity['wf_info_for'])
-    assert forentity.current_state.eid == entity['to_state'], forentity.current_state.name
+    assert forentity.current_state.eid == entity['to_state'], (
+        forentity.eid, forentity.current_state.name)
     if forentity.main_workflow.eid != forentity.current_workflow.eid:
         # we're in a subworkflow, check if we've reached an exit point
         wftr = forentity.subworkflow_input_transition()
--- a/server/repository.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/server/repository.py	Tue Oct 06 17:18:23 2009 +0200
@@ -882,6 +882,8 @@
             self._extid_cache[cachekey] = eid
             self._type_source_cache[eid] = (etype, source.uri, extid)
             entity = source.before_entity_insertion(session, extid, etype, eid)
+            if not hasattr(entity, 'edited_attributes'):
+                entity.edited_attributes = set()
             if source.should_call_hooks:
                 self.hm.call_hooks('before_add_entity', etype, session, entity)
             # XXX call add_info with complete=False ?
--- a/vregistry.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/vregistry.py	Tue Oct 06 17:18:23 2009 +0200
@@ -361,10 +361,13 @@
             # if it was modified, raise RegistryOutOfDate to reload everything
             self.info('File %s changed since last visit', filepath)
             raise RegistryOutOfDate()
+        # set update time before module loading, else we get some reloading
+        # weirdness in case of syntax error or other error while importing the
+        # module
+        self._lastmodifs[filepath] = modified_on
         # load the module
         module = load_module_from_name(modname, use_sys=not force_reload)
         self.load_module(module)
-        self._lastmodifs[filepath] = modified_on
         return True
 
     def load_module(self, module):
--- a/web/data/cubicweb.css	Tue Oct 06 16:56:22 2009 +0200
+++ b/web/data/cubicweb.css	Tue Oct 06 17:18:23 2009 +0200
@@ -747,6 +747,21 @@
   top: -1px;
 }
 
+table.htableForm {
+  vertical-align: middle;
+}
+table.htableForm td{
+  padding-left: 1em;
+  padding-top: 0.5em;
+}
+table.htableForm th{
+  padding-left: 1em;
+}
+table.htableForm .validateButton {
+  margin-right: 0.2em;
+  vertical-align: top;
+  margin-bottom: 0.2em; /* because vertical-align doesn't seems to have any effect */
+}
 
 /***************************************/
 /* error view (views/management.py)    */
--- a/web/views/basecontrollers.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/web/views/basecontrollers.py	Tue Oct 06 17:18:23 2009 +0200
@@ -198,6 +198,10 @@
             req.cnx.commit() # ValidationError may be raise on commit
         except ValidationError, ex:
             return (False, _validation_error(req, ex), ctrl._edited_entity)
+        except Exception, ex:
+            req.cnx.rollback()
+            req.exception('unexpected error while validating form')
+            return (False, req._(str(ex).decode('utf-8')), ctrl._edited_entity)
         else:
             return (True, ex.location, ctrl._edited_entity)
     except Exception, ex:
--- a/web/views/formrenderers.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/web/views/formrenderers.py	Tue Oct 06 17:18:23 2009 +0200
@@ -273,7 +273,7 @@
 
     display_help = False
     def _render_fields(self, fields, w, form):
-        w(u'<table border="0">')
+        w(u'<table border="0" class="htableForm">')
         w(u'<tr>')
         for field in fields:
             if self.display_label:
--- a/web/views/tabs.py	Tue Oct 06 16:56:22 2009 +0200
+++ b/web/views/tabs.py	Tue Oct 06 17:18:23 2009 +0200
@@ -15,6 +15,7 @@
 from cubicweb.view import EntityView
 from cubicweb.common import tags, uilib
 from cubicweb.utils import make_uid
+from cubicweb.web.views import primary
 
 class LazyViewMixin(object):
     """provides two convenience methods for the tab machinery
@@ -30,13 +31,11 @@
   });""" % {'event': 'load_%s' % vid, 'vid': vid,
             'reloadable' : str(reloadable).lower()})
 
-    def lazyview(self, vid, rql=None, eid=None, rset=None, static=False,
+    def lazyview(self, vid, rql=None, eid=None, rset=None, tabid=None,
                  reloadable=False, show_spinbox=True, w=None):
         """a lazy version of wview
         first version only support lazy viewing for an entity at a time
         """
-        assert rql or eid or rset or static, \
-            'lazyview wants at least : rql, or an eid, or an rset -- or call it with static=True'
         w = w or self.w
         self.req.add_js('cubicweb.lazy.js')
         urlparams = {'vid' : vid, 'fname' : 'view'}
@@ -47,12 +46,12 @@
         elif rset:
             urlparams['rql'] = rset.printable_rql()
         w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
-            vid, xml_escape(self.build_url('json', **urlparams))))
+            tabid or vid, xml_escape(self.build_url('json', **urlparams))))
         if show_spinbox:
             w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>'
-              % (vid, self.req._('loading')))
+              % (tabid or vid, self.req._('loading')))
         w(u'</div>')
-        self._prepare_bindings(vid, reloadable)
+        self._prepare_bindings(tabid or vid, reloadable)
 
     def forceview(self, vid):
         """trigger an event that will force immediate loading of the view
@@ -70,30 +69,39 @@
     def cookie_name(self):
         return str('%s_active_tab' % self.config.appid)
 
-    def active_tab(self, tabs, default):
-        formtab = self.req.form.get('tab')
-        if formtab in tabs:
-            return formtab
+    def active_tab(self, default):
+        if 'tab' in self.req.form:
+            return self.req.form['tab']
         cookies = self.req.get_cookie()
         cookiename = self.cookie_name
         activetab = cookies.get(cookiename)
         if activetab is None:
             cookies[cookiename] = default
             self.req.set_cookie(cookies, cookiename)
-            tab = default
-        else:
-            tab = activetab.value
-        return tab in tabs and tab or default
+            return default
+        return activetab.value
 
-    def prune_tabs(self, tabs):
+    def prune_tabs(self, tabs, default_tab):
         selected_tabs = []
+        may_be_active_tab = self.active_tab(default_tab)
+        active_tab = default_tab
+        viewsvreg = self.vreg['views']
         for tab in tabs:
             try:
-                self.vreg['views'].select(tab, self.req, rset=self.rset)
-                selected_tabs.append(tab)
+                tabid, tabkwargs = tab
+                tabkwargs = tabkwargs.copy()
+            except ValueError:
+                tabid, tabkwargs = tab, {}
+            tabkwargs.setdefault('rset', self.rset)
+            vid = tabkwargs.get('vid', tabid)
+            try:
+                viewsvreg.select(vid, self.req, **tabkwargs)
+                selected_tabs.append((tabid, tabkwargs))
             except NoSelectableObject:
                 continue
-        return selected_tabs
+            if tabid == may_be_active_tab:
+                active_tab = tabid
+        return selected_tabs, active_tab
 
     def render_tabs(self, tabs, default, entity=None):
         # delegate to the default tab if there is more than one entity
@@ -105,30 +113,31 @@
         self.req.add_js(('ui.core.js', 'ui.tabs.js',
                          'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js'))
         # prune tabs : not all are to be shown
-        tabs = self.prune_tabs(tabs)
-        # select a tab
-        active_tab = self.active_tab(tabs, default)
+        tabs, active_tab = self.prune_tabs(tabs, default)
         # build the html structure
         w = self.w
         uid = entity and entity.eid or make_uid('tab')
         w(u'<div id="entity-tabs-%s">' % uid)
         w(u'<ul>')
-        for tab in tabs:
+        active_tab_idx = None
+        for i, (tabid, tabkwargs) in enumerate(tabs):
             w(u'<li>')
-            w(u'<a href="#%s">' % tab)
-            w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name))
-            w(self.req._(tab))
+            w(u'<a href="#%s">' % tabid)
+            w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tabid, self.cookie_name))
+            w(tabkwargs.pop('label', self.req._(tabid)))
             w(u'</span>')
             w(u'</a>')
             w(u'</li>')
+            if tabid == active_tab:
+                active_tab_idx = i
         w(u'</ul>')
         w(u'</div>')
-        for tab in tabs:
-            w(u'<div id="%s">' % tab)
-            if entity:
-                self.lazyview(tab, eid=entity.eid)
-            else:
-                self.lazyview(tab, static=True)
+        for tabid, tabkwargs in tabs:
+            w(u'<div id="%s">' % tabid)
+            tabkwargs.setdefault('tabid', tabid)
+            tabkwargs.setdefault('vid', tabid)
+            tabkwargs.setdefault('rset', self.rset)
+            self.lazyview(**tabkwargs)
             w(u'</div>')
         # call the set_tab() JS function *after* each tab is generated
         # because the callback binding needs to be done before
@@ -136,7 +145,7 @@
         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),
+""" % {'tabindex'   : active_tab_idx,
        'vid'        : active_tab,
        'eeid'       : (entity and entity.eid or uid),
        'cookiename' : self.cookie_name})
@@ -170,3 +179,30 @@
             self.w(tags.h1(self.req._(self.title)))
         self.wview(self.vid, rset, 'noresult')
         self.w(u'</div>')
+
+
+class TabedPrimaryView(TabsMixin, primary.PrimaryView):
+    __abstract__ = True # don't register
+
+    tabs = ['main_tab']
+    default_tab = 'main_tab'
+
+    def cell_call(self, row, col):
+        entity = self.complete_entity(row, col)
+        self.render_entity_title(entity)
+        self.render_entity_metadata(entity)
+        self.render_tabs(self.tabs, self.default_tab, entity)
+
+
+class PrimaryTab(primary.PrimaryView):
+    id = 'main_tab'
+
+    def is_primary(self):
+        return True
+
+    def render_entity_title(self, entity):
+        pass
+
+    def render_entity_metadata(self, entity):
+        pass
+