proper field's role handling: may be 'subject' / 'object' *in case
of entity's relation*, but None in other case. So you should correctly
specify it to field_by_name
"""navigation components definition for CubicWeb web client:organization: Logilab:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"_=unicodefromlogilab.mtconverterimportxml_escapefromcubicweb.interfacesimportIBreadCrumbsfromcubicweb.selectorsimport(one_line_rset,implements,one_etype_rset,two_lines_rset,any_rset)fromcubicweb.viewimportEntityView,Component# don't use AnyEntity since this may cause bug with isinstance() due to reloadingfromcubicweb.entityimportEntityfromcubicwebimporttags,uilibclassBreadCrumbEntityVComponent(Component):__regid__='breadcrumbs'__select__=one_line_rset()&implements(IBreadCrumbs,accept_none=False)cw_property_defs={_('visible'):dict(type='Boolean',default=True,help=_('display the component or not')),}title=_('contentnavigation_breadcrumbs')help=_('contentnavigation_breadcrumbs_description')separator=u' > 'link_template=u'<a href="%s">%s</a>'defcall(self,view=None,first_separator=True):entity=self.cw_rset.get_entity(0,0)path=entity.breadcrumbs(view)ifpath:self.open_breadcrumbs()iffirst_separator:self.w(self.separator)self.render_breadcrumbs(entity,path)self.close_breadcrumbs()defopen_breadcrumbs(self):self.w(u'<span id="breadcrumbs" class="pathbar">')defclose_breadcrumbs(self):self.w(u'</span>')defrender_breadcrumbs(self,contextentity,path):root=path.pop(0)ifisinstance(root,Entity):self.w(self.link_template%(self._cw.build_url(root.__regid__),root.dc_type('plural')))self.w(self.separator)self.wpath_part(root,contextentity,notpath)fori,parentinenumerate(path):self.w(self.separator)self.w(u"\n")self.wpath_part(parent,contextentity,i==len(path)-1)defwpath_part(self,part,contextentity,last=False):ifisinstance(part,Entity):iflastandpart.eid==contextentity.eid:self.w(xml_escape(part.view('breadcrumbtext')))else:self.w(part.view('breadcrumbs'))elifisinstance(part,tuple):url,title=parttextsize=self._cw.property_value('navigation.short-line-size')self.w(self.link_template%(xml_escape(url),xml_escape(uilib.cut(title,textsize))))else:textsize=self._cw.property_value('navigation.short-line-size')self.w(uilib.cut(unicode(part),textsize))classBreadCrumbETypeVComponent(BreadCrumbEntityVComponent):__select__=two_lines_rset()&one_etype_rset()& \implements(IBreadCrumbs,accept_none=False)defrender_breadcrumbs(self,contextentity,path):# XXX hack: only display etype name or first non entity path partroot=path.pop(0)ifisinstance(root,Entity):self.w(u'<a href="%s">%s</a>'%(self._cw.build_url(root.__regid__),root.dc_type('plural')))else:self.wpath_part(root,contextentity,notpath)classBreadCrumbAnyRSetVComponent(BreadCrumbEntityVComponent):__select__=any_rset()defcall(self,view=None,first_separator=True):self.w(u'<span id="breadcrumbs" class="pathbar">')iffirst_separator:self.w(self.separator)self.w(self._cw._('search'))self.w(u'</span>')classBreadCrumbView(EntityView):__regid__='breadcrumbs'defcell_call(self,row,col):entity=self.cw_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))classBreadCrumbTextView(EntityView):__regid__='breadcrumbtext'defcell_call(self,row,col):entity=self.cw_rset.get_entity(row,col)textsize=self._cw.property_value('navigation.short-line-size')self.w(uilib.cut(entity.dc_title(),textsize))