[breadcrumbs] keep proper breadcrumbs when creating an entity linked to another by inspecting __linkto (closes #1947476)
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 23 Sep 2011 09:17:37 +0200
changeset 7841 287813c487b7
parent 7829 58f696c0f5b3
child 7845 2172978be237
[breadcrumbs] keep proper breadcrumbs when creating an entity linked to another by inspecting __linkto (closes #1947476)
web/views/ibreadcrumbs.py
--- a/web/views/ibreadcrumbs.py	Thu Sep 22 16:12:33 2011 +0200
+++ b/web/views/ibreadcrumbs.py	Fri Sep 23 09:17:37 2011 +0200
@@ -28,7 +28,8 @@
 from cubicweb import tags, uilib
 from cubicweb.entity import Entity
 from cubicweb.selectors import (is_instance, one_line_rset, adaptable,
-                                one_etype_rset, multi_lines_rset, any_rset)
+                                one_etype_rset, multi_lines_rset, any_rset,
+                                match_form_params)
 from cubicweb.view import EntityView, EntityAdapter
 from cubicweb.web.views import basecomponents
 # don't use AnyEntity since this may cause bug with isinstance() due to reloading
@@ -120,7 +121,10 @@
     # XXX support kwargs for compat with other components which gets the view as
     # argument
     def render(self, w, **kwargs):
-        entity = self.cw_rset.get_entity(0, 0)
+        try:
+            entity = self.cw_extra_kwargs['entity']
+        except KeyError:
+            entity = self.cw_rset.get_entity(0, 0)
         adapter = ibreadcrumb_adapter(entity)
         view = self.cw_extra_kwargs.get('view')
         path = adapter.breadcrumbs(view)
@@ -190,6 +194,17 @@
         w(u'</span>')
 
 
+class BreadCrumbLinkToVComponent(BreadCrumbEntityVComponent):
+    __select__ = basecomponents.HeaderComponent.__select__ & match_form_params('__linkto')
+
+    def render(self, w, **kwargs):
+        eid = self._cw.list_form_param('__linkto')[0].split(':')[1]
+        entity = self._cw.entity_from_eid(eid)
+        ecmp = self._cw.vreg[self.__registry__].select(
+            self.__regid__, self._cw, entity=entity, **kwargs)
+        ecmp.render(w, **kwargs)
+
+
 class BreadCrumbView(EntityView):
     __regid__ = 'breadcrumbs'