[Cubicweb] About uiprops and postcreate

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Jul 30 09:26:54 CEST 2012


On 27 juillet 13:05, Stéphane Bugat wrote:
> > It's because both are in the ``ctxcomponents`` registry, not the
> > ``boxes`` one.
> > 
> > Please, try :
> > 
> >   set_property('ctxcomponents.search_box.visible', u'')
> >   set_property('ctxcomponents.blog_summary_box.visible', u'')
> > 
> 
> Worked well for 'search_box', thank you Adrien.
>  
> 'blog_summary_box' has been renamed in something like 'blog_latest_blogs' (obtained through the source code of HTML page), however in the source of cw-blog I found a ctxcomponent with regid 'blog.latest_blogs'. How does the class id is derived from the __regid__ of the component? Both the following failed:
> 
>   set_property('ctxcomponents.blog_latest_blogs.visible', u'')
>   set_property('ctxcomponents.blog.latest_blogs.visible', u'')

The DOM id is usually extracted from the __regid__ using the 
cw.uilib.domid function which does:

  string.replace('.', '_').replace('-', '_')

But set_property expect a property key. All existing property keys are
defined in a special register, which contains the property description
(type, default, description...). The value to be specified to a property
shall be acceptable according to its type. Last but not least, appobjects 
which have a cw_property_defs dictionary, like those derived from 
`CtxComponent` will have those property automatically registered using:

  <__registry__>.<__regid__>.<key> 

for each key in the dictionary. So in your case, 
'ctxcomponents.blog.latest_blogs.visible' should be the right key, provided 
that the relevant appobject is actually registered. And empty string should
be an acceptable value for boolean type, evaluated to false. So please send
us the traceback if this doesn't work.

That being said, if what you want is to deactivate the box by default but 
let users reactivate it using their preferences, fine. However if you wish
to remove it totally from your site, you should rather unregister the
class than playing with the visible property. Beside the difference explained
above (possible reactivation from user prefs), removing from the registry
has also a performance impact since, when looking for possible boxes, the class
won't ever be evaluated while if deactivated using visible property, it'ill
be considered each time, but eventually not displayed because not visible.

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (09.54.03.55.76)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the Cubicweb mailing list