[Cubicweb] customize rendering of a specific attribute in cw

Stéphane Bugat stephane.bugat at free.fr
Fri May 25 10:45:22 CEST 2012


Sylvain, this trick is also good and should be sufficient for my issue. I think I'll try to implement it (sorry Aurélien!) as I really like to control the display through uicfg.

----- Mail original -----
De: "Sylvain Thénault" <sylvain.thenault at logilab.fr>
À: "aurélien campéas" <aurelien.campeas at gmail.com>
Cc: "Stéphane Bugat" <stephane.bugat at free.fr>, cubicweb at lists.cubicweb.org
Envoyé: Vendredi 25 Mai 2012 10:37:29
Objet: Re: [Cubicweb] customize rendering of a specific attribute in cw

On 25 mai 09:29, aurélien campéas wrote:
> On entity classes, there is a printable_value method that can also be
> customized (on Airport in your case) .
> This should be invoked (automatically) by the 'attribute' view (in
> views/primary.py).

This is an option, though I would rather suggest the following:

class DegreeAttributeView(EntityView):
    __regid__ = 'degree'
    __select__ = is_instance('Airport') & match_kwargs('rtype')

    def entity_call(self, entity, rtype, **kwargs):
        self.w(format(entity.coordinate))


_pvdc = uicfg.primaryview_display_ctrl
_pvdc.tag_attribute(('Airport', 'coordinate'), {'vid': 'degree'})

This should be enough for most places, but not all like printable_value.
If this is not enough to you, then go for Aurelien'suggestion (but think
to test edition :p.

-- 
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