web/component.py
changeset 7991 dcc5a4d48122
parent 7990 a673d1d9a738
child 7998 9ef285eb20f4
equal deleted inserted replaced
7990:a673d1d9a738 7991:dcc5a4d48122
   243     else:
   243     else:
   244         w(u'<li>%s</li>' % item)
   244         w(u'<li>%s</li>' % item)
   245 
   245 
   246 
   246 
   247 class Layout(Component):
   247 class Layout(Component):
   248     __regid__ = 'layout'
   248     __regid__ = 'component_layout'
   249     __abstract__ = True
   249     __abstract__ = True
   250 
   250 
   251     def init_rendering(self):
   251     def init_rendering(self):
   252         """init view for rendering. Return true if we should go on, false
   252         """init view for rendering. Return true if we should go on, false
   253         if we should stop now.
   253         if we should stop now.
   261         except EmptyComponent:
   261         except EmptyComponent:
   262             return False
   262             return False
   263         return True
   263         return True
   264 
   264 
   265 
   265 
   266 class CtxComponent(AppObject):
   266 class LayoutableMixIn(object):
       
   267     layout_id = None # to be defined in concret class
       
   268     layout_args = {}
       
   269 
       
   270     def layout_render(self, w):
       
   271         getlayout = self._cw.vreg['components'].select
       
   272         layout = getlayout(self.layout_id, self._cw, **self.layout_select_args())
       
   273         layout.render(w)
       
   274 
       
   275     def layout_select_args(self):
       
   276         args  = dict(rset=self.cw_rset, row=self.cw_row, col=self.cw_col,
       
   277                      view=self)
       
   278         args.update(self.layout_args)
       
   279         return args
       
   280 
       
   281 
       
   282 class CtxComponent(LayoutableMixIn, AppObject):
   267     """base class for contextual components. The following contexts are
   283     """base class for contextual components. The following contexts are
   268     predefined:
   284     predefined:
   269 
   285 
   270     * boxes: 'left', 'incontext', 'right'
   286     * boxes: 'left', 'incontext', 'right'
   271     * section: 'navcontenttop', 'navcontentbottom', 'navtop', 'navbottom'
   287     * section: 'navcontenttop', 'navcontentbottom', 'navtop', 'navbottom'
   308     visible = True
   324     visible = True
   309     order = 0
   325     order = 0
   310     context = 'left'
   326     context = 'left'
   311     contextual = False
   327     contextual = False
   312     title = None
   328     title = None
       
   329     layout_id = 'component_layout'
   313 
   330 
   314     # XXX support kwargs for compat with old boxes which gets the view as
   331     # XXX support kwargs for compat with old boxes which gets the view as
   315     # argument
   332     # argument
   316     def render(self, w, **kwargs):
   333     def render(self, w, **kwargs):
   317         if hasattr(self, 'call'):
   334         if hasattr(self, 'call'):
   321             def wview(__vid, rset=None, __fallback_vid=None, **kwargs):
   338             def wview(__vid, rset=None, __fallback_vid=None, **kwargs):
   322                 self._cw.view(__vid, rset, __fallback_vid, w=self.w, **kwargs)
   339                 self._cw.view(__vid, rset, __fallback_vid, w=self.w, **kwargs)
   323             self.wview = wview
   340             self.wview = wview
   324             self.call(**kwargs) # pylint: disable=E1101
   341             self.call(**kwargs) # pylint: disable=E1101
   325             return
   342             return
   326         getlayout = self._cw.vreg['components'].select
   343         self.layout_render(w)
   327         layout = getlayout('layout', self._cw, **self.layout_select_args())
       
   328         layout.render(w)
       
   329 
   344 
   330     def layout_select_args(self):
   345     def layout_select_args(self):
       
   346         args = super(CtxComponent, self).layout_select_args()
   331         try:
   347         try:
   332             # XXX ensure context is given when the component is reloaded through
   348             # XXX ensure context is given when the component is reloaded through
   333             # ajax
   349             # ajax
   334             context = self.cw_extra_kwargs['context']
   350             args['context'] = self.cw_extra_kwargs['context']
   335         except KeyError:
   351         except KeyError:
   336             context = self.cw_propval('context')
   352             args['context'] = self.cw_propval('context')
   337         return dict(rset=self.cw_rset, row=self.cw_row, col=self.cw_col,
   353         return args
   338                     view=self, context=context)
       
   339 
   354 
   340     def init_rendering(self):
   355     def init_rendering(self):
   341         """init rendering callback: that's the good time to check your component
   356         """init rendering callback: that's the good time to check your component
   342         has some content to display. If not, you can still raise
   357         has some content to display. If not, you can still raise
   343         :exc:`EmptyComponent` to inform it should be skipped.
   358         :exc:`EmptyComponent` to inform it should be skipped.