--- a/web/test/data/bootstrap_cubes Fri Sep 11 12:52:55 2009 +0200
+++ b/web/test/data/bootstrap_cubes Fri Sep 11 13:40:49 2009 +0200
@@ -1,1 +1,1 @@
-file, blog, tag
+file, blog, tag, folder
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/test/unittest_breadcrumbs.py Fri Sep 11 13:40:49 2009 +0200
@@ -0,0 +1,17 @@
+from cubicweb.devtools.testlib import WebTest
+
+class BreadCrumbsTC(WebTest):
+
+ def test_base(self):
+ f1 = self.add_entity('Folder', name=u'par&ent')
+ f2 = self.add_entity('Folder', name=u'chi&ld')
+ self.execute('SET F2 filed_under F1 WHERE F1 eid %(f1)s, F2 eid %(f2)s',
+ {'f1' : f1.eid, 'f2' : f2.eid})
+ self.commit()
+ childrset = self.execute('Folder F WHERE F eid %s' % f2.eid)
+ self.assertEquals(childrset.get_entity(0,0).view('breadcrumbs'),
+ '<a href="http://testing.fr/cubicweb/folder/637" title="">chi&ld</a>')
+ ibc = self.vreg['components'].select('breadcrumbs', self.request(), rset=childrset)
+ self.assertEquals(ibc.render(),
+ """<span id="breadcrumbs" class="pathbar"> > <a href="http://testing.fr/cubicweb/Folder">folder_plural</a> > <a href="http://testing.fr/cubicweb/folder/636" title="">par&ent</a> > 
+chi&ld</span>""")
--- a/web/views/ibreadcrumbs.py Fri Sep 11 12:52:55 2009 +0200
+++ b/web/views/ibreadcrumbs.py Fri Sep 11 13:40:49 2009 +0200
@@ -16,14 +16,8 @@
from cubicweb.view import EntityView, Component
# don't use AnyEntity since this may cause bug with isinstance() due to reloading
from cubicweb.entity import Entity
-from cubicweb.common.uilib import cut
-
+from cubicweb.common import tags, uilib
-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(Component):
id = 'breadcrumbs'
@@ -38,7 +32,7 @@
separator = u' > '
def call(self, view=None, first_separator=True):
- entity = self.entity(0)
+ entity = self.rset.get_entity(0, 0)
path = entity.breadcrumbs(view)
if path:
self.w(u'<span id="breadcrumbs" class="pathbar">')
@@ -62,17 +56,17 @@
def wpath_part(self, part, contextentity, last=False):
if isinstance(part, Entity):
if last and part.eid == contextentity.eid:
- self.w(bc_title(part))
+ self.w(xml_escape(part.view('breadcrumbtext')))
else:
- part.view('breadcrumbs', w=self.w)
+ self.w(part.view('breadcrumbs'))
elif isinstance(part, tuple):
url, title = part
textsize = self.req.property_value('navigation.short-line-size')
self.w(u'<a href="%s">%s</a>' % (
- xml_escape(url), xml_escape(cut(title, textsize))))
+ xml_escape(url), xml_escape(uilib.cut(title, textsize))))
else:
textsize = self.req.property_value('navigation.short-line-size')
- self.w(cut(unicode(part), textsize))
+ self.w(uilib.cut(unicode(part), textsize))
class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent):
@@ -103,7 +97,17 @@
id = 'breadcrumbs'
def cell_call(self, row, col):
- entity = self.entity(row, col)
- desc = xml_escape(cut(entity.dc_description(), 50))
- self.w(u'<a href="%s" title="%s">%s</a>' % (
- xml_escape(entity.absolute_url()), desc, bc_title(entity)))
+ entity = self.rset.get_entity(row, col)
+ desc = xml_escape(uilib.cut(entity.dc_description(), 50))
+ # XXX remember camember : tags.a autoescapes !
+ self.w(tags.a(entity.view('breadcrumbtext'),
+ href=entity.absolute_url(), title=desc))
+
+
+class BreadCrumbTextView(EntityView):
+ id = 'breadcrumbtext'
+
+ def cell_call(self, row, col):
+ entity = self.rset.get_entity(row, col)
+ textsize = self.req.property_value('navigation.short-line-size')
+ self.w(uilib.cut(entity.dc_title(), textsize))