backport default branch tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 04 Mar 2009 17:12:28 +0100
branchtls-sprint
changeset 1006 92a0601b2523
parent 1005 09ba3cb2a440 (current diff)
parent 1004 625e59773119 (diff)
child 1007 34e92a8d9167
backport default branch
devtools/testlib.py
ext/rest.py
i18n/es.po
interfaces.py
web/views/baseviews.py
web/views/tabs.py
web/views/treeview.py
--- a/devtools/testlib.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/devtools/testlib.py	Wed Mar 04 17:12:28 2009 +0100
@@ -248,11 +248,11 @@
     def to_test_etypes(self):
         return unprotected_entities(self.schema, strict=True)
     
-    def iter_automatic_rsets(self):
+    def iter_automatic_rsets(self, limit=10):
         """generates basic resultsets for each entity type"""
         etypes = self.to_test_etypes()
         for etype in etypes:
-            yield self.execute('Any X WHERE X is %s' % etype)
+            yield self.execute('Any X LIMIT %s WHERE X is %s' % (limit, etype))
 
         etype1 = etypes.pop()
         etype2 = etypes.pop()
@@ -347,14 +347,14 @@
     ## one each
     def test_one_each_config(self):
         self.auto_populate(1)
-        for rset in self.iter_automatic_rsets():
+        for rset in self.iter_automatic_rsets(limit=1):
             for testargs in self._test_everything_for(rset):
                 yield testargs
 
     ## ten each
     def test_ten_each_config(self):
         self.auto_populate(10)
-        for rset in self.iter_automatic_rsets():
+        for rset in self.iter_automatic_rsets(limit=10):
             for testargs in self._test_everything_for(rset):
                 yield testargs
                 
--- a/ext/rest.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/ext/rest.py	Wed Mar 04 17:12:28 2009 +0100
@@ -1,6 +1,16 @@
 """rest publishing functions
 
-contains some functions and setup of docutils for cubicweb
+contains some functions and setup of docutils for cubicweb. Provides the
+following ReST directives:
+
+* `eid`, create link to entity in the repository by their eid
+
+* `card`, create link to card entity in the repository by their wikiid
+  (proposing to create it when the refered card doesn't exist yet)
+
+* `winclude`, reference to a web documentation file (in wdoc/ directories)
+
+* `sourcecode` (if pygments is installed), source code colorization
 
 :organization: Logilab
 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
@@ -156,6 +166,36 @@
                               'encoding': directives.encoding}
 directives.register_directive('winclude', winclude_directive)
 
+try:
+    from pygments import highlight
+    from pygments.lexers import get_lexer_by_name, LEXERS
+    from pygments.formatters import HtmlFormatter
+except ImportError:
+    pass
+else:
+    _PYGMENTS_FORMATTER = HtmlFormatter()
+
+    def pygments_directive(name, arguments, options, content, lineno,
+                           content_offset, block_text, state, state_machine):
+        try:
+            lexer = get_lexer_by_name(arguments[0])
+        except ValueError:
+            import traceback
+            traceback.print_exc()
+            print sorted(aliases for module_name, name, aliases, _, _  in LEXERS.itervalues())
+            # no lexer found
+            lexer = get_lexer_by_name('text')
+        print 'LEXER', lexer
+        parsed = highlight(u'\n'.join(content), lexer, _PYGMENTS_FORMATTER)
+        context = state.document.settings.context
+        context.req.add_css('pygments.css')
+        return [nodes.raw('', parsed, format='html')]
+     
+    pygments_directive.arguments = (1, 0, 1)
+    pygments_directive.content = 1
+    directives.register_directive('sourcecode', pygments_directive)
+
+
 class CubicWebReSTParser(Parser):
     """The (customized) reStructuredText parser."""
 
--- a/i18n/es.po	Wed Mar 04 17:09:10 2009 +0100
+++ b/i18n/es.po	Wed Mar 04 17:12:28 2009 +0100
@@ -76,8 +76,8 @@
 msgstr "%d semanas"
 
 #, python-format
-msgid "%d years"
-msgstr "%d años"
+msgid "%d years"
+msgstr "%d años"
 
 #, python-format
 msgid "%d days"
@@ -104,10 +104,6 @@
 msgstr "%d semanas"
 
 #, python-format
-msgid "%d years"
-msgstr "%d años"
-
-#, python-format
 msgid "%s error report"
 msgstr "%s reporte de errores"
 
--- a/interfaces.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/interfaces.py	Wed Mar 04 17:12:28 2009 +0100
@@ -238,7 +238,20 @@
     def rss_feed_url(self):
         """return an url which layout sub-entities item
         """
-class ISIOC(Interface):
-    """interface for entities with sioc views"""
+class ISiocItem(Interface):
+    """interface for entities (which are item
+    in sioc specification) with sioc views"""
     
-   
+    def isioc_content(self):
+        """return content entity"""
+
+    def isioc_container(self):
+        """return container entity"""           
+            
+class ISiocContainer(Interface):
+    """interface for entities (which are container
+    in sioc specification) with sioc views"""
+
+    def isioc_type(self):
+        """return container type (forum, weblog, mailinglist)"""
+    
--- a/web/data/cubicweb.css	Wed Mar 04 17:09:10 2009 +0100
+++ b/web/data/cubicweb.css	Wed Mar 04 17:12:28 2009 +0100
@@ -586,9 +586,13 @@
   margin-bottom: 0px;
 }
 
+div.primaryRight{
+  float:right;
+  
+ }
+
 div.sideRelated {
   margin-right: 1em;
-  float: right;
   padding: 12px 0px 12px 12px;
   min-width: 21em;
   max-width: 50em;
--- a/web/data/cubicweb.edition.js	Wed Mar 04 17:09:10 2009 +0100
+++ b/web/data/cubicweb.edition.js	Wed Mar 04 17:12:28 2009 +0100
@@ -264,7 +264,8 @@
     var d = async_rawremote_exec('inline_creation_form', peid, ptype, ttype, rtype, role);
     d.addCallback(function (response) {
 	var linknode = getNode('add' + rtype + ':' + peid + 'link');
-	var form = jQuery(getDomFromResponse(response));
+        var dom = getDomFromResponse(response);
+	var form = jQuery(dom);
 	form.css('display', 'none');
 	form.insertBefore(linknode.parentNode).slideDown('fast');
 	// setStyle(form, {display: 'none'});
@@ -273,6 +274,7 @@
 	// slideDown(form, {'duration':0.6});
 	reorderTabindex();
 	form.trigger('inlinedform-added');
+        postAjaxLoad(dom);
 	// MochiKit.Signal.signal(CubicWeb, 'inlinedform-added', form);
     });
     d.addErrback(function (xxx) {
--- a/web/views/baseviews.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/web/views/baseviews.py	Wed Mar 04 17:12:28 2009 +0100
@@ -139,22 +139,19 @@
         self.render_entity_metadata(entity)
         # entity's attributes and relations, excluding meta data
         # if the entity isn't meta itself
-        self.w(u'<table border="0" width="100%">')
-        self.w(u'<tr>')
-        self.w(u'<td valign="top">')
+        self.w(u'<div>')
         self.w(u'<div class="mainInfo">')
         self.render_entity_attributes(entity, siderelations)
         self.w(u'</div>')
         self.content_navigation_components('navcontenttop')
         if self.main_related_section:
             self.render_entity_relations(entity, siderelations)
-        self.w(u'</td>')
+        self.w(u'</div>')
         # side boxes
-        self.w(u'<td valign="top">')
+        self.w(u'<div class="primaryRight">')
         self.render_side_related(entity, siderelations)
-        self.w(u'</td>')
-        self.w(u'</tr>')
-        self.w(u'</table>')        
+        self.w(u'</div>')
+        self.w(u'<div class="clear"></div>')          
         self.content_navigation_components('navcontentbottom')
 
     def content_navigation_components(self, context):
@@ -246,40 +243,28 @@
             sideboxes = [(label, rset) for label, rset in self.get_side_boxes_defs(entity)
                          if rset]
             if sideboxes:
-                self.w(u'<table width="100%">')
                 for label, rset in sideboxes:
-                    self.w(u'<tr><td>')
                     self.w(u'<div class="sideRelated">')
                     self.wview('sidebox', rset, title=label)
                     self.w(u'</div>')
-                    self.w(u'</td></tr>')
-                self.w(u'</table>')
         elif siderelations:
-            self.w(u'<table width="100%">')
-            self.w(u'<tr><td>')
             self.w(u'<div class="sideRelated">')
             for relatedinfos in siderelations:
                 # if not relatedinfos[0].meta:
                 #    continue
                 self._render_related_entities(entity, *relatedinfos)
             self.w(u'</div>')
-            self.w(u'</td></tr>')
-            self.w(u'</table>')
         boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
                                                  row=self.row, view=self,
                                                  context='incontext'))
         if boxes:
-            self.w(u'<table width="100%">')
             for box in boxes:
-                self.w(u'<tr><td>')
                 try:
                     box.dispatch(w=self.w, row=self.row)
                 except NotImplementedError:
                     # much probably a context insensitive box, which only implements
                     # .call() and not cell_call()
-                    box.dispatch(w=self.w)
-                self.w(u'</td></tr>')
-            self.w(u'</table>')
+                    box.dispatch(w=self.w)               
                 
     def is_side_related(self, rschema, eschema):
         return rschema.meta and \
--- a/web/views/tabs.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/web/views/tabs.py	Wed Mar 04 17:12:28 2009 +0100
@@ -32,15 +32,22 @@
   });""" % {'event': 'load_%s' % vid, 'vid': vid,
             'reloadable' : str(reloadable).lower()})
 
-    def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None):
+    def lazyview(self, vid, rql=None, eid=None, rset=None, static=False,
+                 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, 'mode' : 'html'}
-        if eid:
-            urlparams['rql'] = uilib.rql_for_eid(eid)
+        if rql:
+            urlparams['rql'] = rql
+        elif eid:
+            urlparams['rql'] = rql_for_eid(eid)
+        elif rset:
+            urlparams['rql'] = rset.printable_rql()
         w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
             vid, html_escape(self.build_url('json', **urlparams))))
         if show_spinbox:
@@ -64,12 +71,12 @@
         return str('%s_active_tab' % self.config.appid)
 
     def active_tab(self, tabs, default):
-        cookie = self.req.get_cookie()
+        cookies = self.req.get_cookie()
         cookiename = self.cookie_name
-        activetab = cookie.get(cookiename)
+        activetab = cookies.get(cookiename)
         if activetab is None:
-            cookie[cookiename] = default
-            self.req.set_cookie(cookie, cookiename)
+            cookies[cookiename] = default
+            self.req.set_cookie(cookies, cookiename)
             tab = default
         else:
             tab = activetab.value
@@ -89,13 +96,18 @@
         self.req.add_css('ui.tabs.css')
         self.req.add_js(('ui.core.js', 'ui.tabs.js',
                          'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js'))
+        # tabbed views do no support concatenation
+        # hence we delegate to the default tab
+        if self.req.form.get('vid') == 'primary':
+            entity.view(default)
+            return
         # prune tabs : not all are to be shown
         tabs = self.prune_tabs(tabs)
         # select a tab
         active_tab = self.active_tab(tabs, default)
         # build the html structure
         w = self.w
-        w(u'<div id="entity-tabs">')
+        w(u'<div id="entity-tabs-%s">' % entity.eid)
         w(u'<ul>')
         for tab in tabs:
             w(u'<li>')
@@ -109,15 +121,16 @@
         w(u'</div>')
         for tab in tabs:
             w(u'<div id="as-%s">' % tab)
-            self.lazyview(tab, entity.eid)
+            self.lazyview(tab, eid=entity.eid)
             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.html_headers.add_onload(u"""
-   jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s });
+   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.eid,
         'cookiename' : self.cookie_name})
 
 
--- a/web/views/treeview.py	Wed Mar 04 17:09:10 2009 +0100
+++ b/web/views/treeview.py	Wed Mar 04 17:12:28 2009 +0100
@@ -26,21 +26,24 @@
     css_classes = 'treeview widget'
     title = _('tree view')
 
-    def call(self, subvid=None):
-        if subvid is None and 'subvid' in self.req.form:
-            subvid = self.req.form.pop('subvid') # consume it
+    def call(self, subvid=None, treeid=None, initial_load=True):
         if subvid is None:
-            subvid = 'oneline'
-        self.req.add_css('jquery.treeview.css')
-        self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js', 'cubicweb.widgets.js'))
-        # XXX noautoload is a quick hack to avoid treeview to be rebuilt
-        #     after a json query and avoid double toggling bugs.
-        #     Need to find a way to do that cleanly.
-        if 'noautoload' in self.req.form:
-            self.w(u'<ul class="%s" cubicweb:wdgtype="TreeView">' % self.css_classes)
-        else:
-            self.w(u'<ul class="%s" cubicweb:loadtype="auto" cubicweb:wdgtype="TreeView">'
-                   % self.css_classes)
+            if 'subvid' in self.req.form:
+                subvid = self.req.form.pop('subvid') # consume it
+            else:
+                subvid = 'oneline'
+        if treeid is None:
+            if 'treeid' in self.req.form:
+                treeid = self.req.form.pop('treeid')
+            else:
+                treeid = make_uid('throw away uid')
+                self.warning('Tree state won\'t be properly restored after next reload')
+        if initial_load:
+            self.req.add_css('jquery.treeview.css')
+            self.req.add_js(('cubicweb.ajax.js', 'jquery.treeview.js'))
+            self.req.html_headers.add_onload(u"""
+jQuery("#tree-%s").treeview({toggle: toggleTree, prerendered: true});""" % treeid)
+        self.w(u'<ul id="tree-%s" class="%s">' % (treeid, self.css_classes))
         for rowidx in xrange(len(self.rset)):
             self.wview(self.itemvid, self.rset, row=rowidx, col=0,
                        vid=subvid, parentvid=self.id, treeid=treeid)