[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 26 Aug 2009 10:06:17 +0200
branchstable
changeset 3007 a15e982aa9a3
parent 3006 4d85386b06a5
child 3008 094c597c1d01
[breadcrumb] only provides a breadcrumbs component, no more as pluggable content nav comp; provides alternative implentation for rset with more than one entity
web/views/ibreadcrumbs.py
--- a/web/views/ibreadcrumbs.py	Wed Aug 26 09:14:45 2009 +0200
+++ b/web/views/ibreadcrumbs.py	Wed Aug 26 10:06:17 2009 +0200
@@ -10,50 +10,55 @@
 
 from logilab.mtconverter import xml_escape
 
+from cubicweb.interfaces import IBreadCrumbs
+from cubicweb.selectors import (one_line_rset, implements, one_etype_rset,
+                                two_lines_rset, any_rset)
+from cubicweb.view import EntityView, Component
 # don't use AnyEntity since this may cause bug with isinstance() due to reloading
-from cubicweb.interfaces import IBreadCrumbs
-from cubicweb.selectors import match_context_prop, one_line_rset, implements
 from cubicweb.entity import Entity
-from cubicweb.view import EntityView
 from cubicweb.common.uilib import cut
-from cubicweb.web.component import EntityVComponent
 
 
 def bc_title(entity):
     textsize = entity.req.property_value('navigation.short-line-size')
     return xml_escape(cut(entity.dc_title(), textsize))
 
+# XXX only provides the component version
 
-class BreadCrumbEntityVComponent(EntityVComponent):
+class BreadCrumbEntityVComponent(Component):
     id = 'breadcrumbs'
-    # register msg not generated since no entity implements IPrevNext in cubicweb itself
+    __select__ = one_line_rset() & implements(IBreadCrumbs)
+
+    property_defs = {
+        _('visible'):  dict(type='Boolean', default=True,
+                            help=_('display the component or not')),
+        }
     title = _('contentnavigation_breadcrumbs')
     help = _('contentnavigation_breadcrumbs_description')
-    __select__ = (one_line_rset() & match_context_prop() & implements(IBreadCrumbs))
-    context = 'navtop'
-    order = 5
-    visible = False
     separator = u'&#160;&gt;&#160;'
 
     def call(self, view=None, first_separator=True):
         entity = self.entity(0)
         path = entity.breadcrumbs(view)
         if path:
-            self.w(u'<span class="pathbar">')
+            self.w(u'<span id="breadcrumbs" class="pathbar">')
             if first_separator:
                 self.w(self.separator)
-            root = path.pop(0)
-            if isinstance(root, Entity):
-                self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id),
-                                                 root.dc_type('plural')))
-                self.w(self.separator)
-            self.wpath_part(root, entity, not path)
-            for i, parent in enumerate(path):
-                self.w(self.separator)
-                self.w(u"\n")
-                self.wpath_part(parent, entity, i == len(path) - 1)
+            self.render_breadcrumbs(entity, path)
             self.w(u'</span>')
 
+    def render_breadcrumbs(self, contextentity, path):
+        root = path.pop(0)
+        if isinstance(root, Entity):
+            self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id),
+                                             root.dc_type('plural')))
+            self.w(self.separator)
+        self.wpath_part(root, contextentity, not path)
+        for i, parent in enumerate(path):
+            self.w(self.separator)
+            self.w(u"\n")
+            self.wpath_part(parent, contextentity, i == len(path) - 1)
+
     def wpath_part(self, part, contextentity, last=False):
         if isinstance(part, Entity):
             if last and part.eid == contextentity.eid:
@@ -70,10 +75,24 @@
             self.w(cut(unicode(part), textsize))
 
 
-class BreadCrumbComponent(BreadCrumbEntityVComponent):
-    __registry__ = 'components'
-    __select__ = (one_line_rset() & implements(IBreadCrumbs))
-    visible = True
+class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent):
+    __select__ = two_lines_rset() & one_etype_rset() & implements(IBreadCrumbs)
+
+    def render_breadcrumbs(self, contextentity, path):
+        # XXX hack: only display etype name or first non entity path part
+        root = path.pop(0)
+        if isinstance(root, Entity):
+            self.w(u'<a href="%s">%s</a>' % (self.req.build_url(root.id),
+                                             root.dc_type('plural')))
+        else:
+            self.wpath_part(root, entity, not path)
+
+
+class BreadCrumbAnyRSetVComponent(BreadCrumbEntityVComponent):
+    __select__ = any_rset()
+
+    def render_breadcrumbs(self, contextentity, path):
+        self.w(self.req._('search'))
 
 
 class BreadCrumbView(EntityView):