[component] refactor layout retrieval to handle case where we've an entity without rset properly stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 27 Jan 2011 13:43:49 +0100
branchstable
changeset 6907 449e5b46ed3d
parent 6906 5f13aefb470b
child 6908 f07dc0e8948d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
web/component.py
--- a/web/component.py	Thu Jan 27 13:42:51 2011 +0100
+++ b/web/component.py	Thu Jan 27 13:43:49 2011 +0100
@@ -294,16 +294,18 @@
             self.call(**kwargs)
             return
         getlayout = self._cw.vreg['components'].select
+        layout = getlayout('layout', self._cw, **self.layout_select_args())
+        layout.render(w)
+
+    def layout_select_args(self):
         try:
             # XXX ensure context is given when the component is reloaded through
             # ajax
             context = self.cw_extra_kwargs['context']
         except KeyError:
             context = self.cw_propval('context')
-        layout = getlayout('layout', self._cw, rset=self.cw_rset,
-                           row=self.cw_row, col=self.cw_col,
-                           view=self, context=context)
-        layout.render(w)
+        return dict(rset=self.cw_rset, row=self.cw_row, col=self.cw_col,
+                    view=self, context=context)
 
     def init_rendering(self):
         """init rendering callback: that's the good time to check your component
@@ -388,6 +390,11 @@
             entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
         self.entity = entity
 
+    def layout_select_args(self):
+        args = super(EntityCtxComponent, self).layout_select_args()
+        args['entity'] = self.entity
+        return args
+
     @property
     def domid(self):
         return domid(self.__regid__) + unicode(self.entity.eid)