"""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.mtconverterimporthtml_escape# don't use AnyEntity since this may cause bug with isinstance() due to reloadingfromcubicweb.interfacesimportIBreadCrumbsfromcubicweb.selectorsimportmatch_context_prop,one_line_rset,implementsfromcubicweb.entityimportEntityfromcubicweb.viewimportEntityViewfromcubicweb.common.uilibimportcutfromcubicweb.web.componentimportEntityVComponentdefbc_title(entity):textsize=entity.req.property_value('navigation.short-line-size')returnhtml_escape(cut(entity.dc_title(),textsize))classBreadCrumbEntityVComponent(EntityVComponent):id='breadcrumbs'# register msg not generated since no entity implements IPrevNext in cubicweb itselftitle=_('contentnavigation_breadcrumbs')help=_('contentnavigation_breadcrumbs_description')__select__=(one_line_rset()&match_context_prop()&implements(IBreadCrumbs))context='navtop'order=5visible=Falseseparator=u' > 'defcall(self,view=None,first_separator=True):entity=self.entity(0)path=entity.breadcrumbs(view)ifpath:self.w(u'<span class="pathbar">')iffirst_separator:self.w(self.separator)root=path.pop(0)ifisinstance(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,notpath)fori,parentinenumerate(path):self.w(self.separator)self.w(u"\n")self.wpath_part(parent,entity,i==len(path)-1)self.w(u'</span>')defwpath_part(self,part,contextentity,last=False):ifisinstance(part,Entity):iflastandpart.eid==contextentity.eid:self.w(bc_title(part))else:part.view('breadcrumbs',w=self.w)elifisinstance(part,tuple):url,title=parttextsize=self.req.property_value('navigation.short-line-size')self.w(u'<a href="%s">%s</a>'%(html_escape(url),html_escape(cut(title,textsize))))else:textsize=self.req.property_value('navigation.short-line-size')self.w(cut(unicode(part),textsize))classBreadCrumbComponent(BreadCrumbEntityVComponent):__registry__='components'__select__=(one_line_rset()&implements(IBreadCrumbs))visible=TrueclassBreadCrumbView(EntityView):id='breadcrumbs'defcell_call(self,row,col):entity=self.entity(row,col)desc=html_escape(cut(entity.dc_description(),50))self.w(u'<a href="%s" title="%s">%s</a>'%(html_escape(entity.absolute_url()),desc,bc_title(entity)))