[Cubicweb] customize rendering of a specific attribute in cw
aurelien.campeas at gmail.com
Fri May 25 10:10:57 CEST 2012
2012/5/25 Stéphane Bugat <stephane.bugat at free.fr>
> Ok. If I get this well, this means I have to overwrite the method "def
> printable_value(self, name)" in my "class Airport(EntityType)" and select
> the case when the name corresponds to "latitude" or "longitude", right?
> Or do I have to do it in the equivalent AnyEntity class that I have
this should happen e.g. in module mycube/entities/airport.py,
__regid__ = 'airport'
def printable_value(self, rtype, **kwargs):
if rtype in ('latitude', 'longitude'):
return super(Airport, self).printable_value(rtype, **kwargs)
So indeed definitely NOT in schema.py (where schema entities get defined).
I also think you should have a look at the views/igeocodable stuff.
Either you will find here something that already suits your need or some
place where to provide a generally useful patch maybe ...
> ----- Mail original -----
> De: "aurélien campéas" <aurelien.campeas at gmail.com>
> À: "Stéphane Bugat" <stephane.bugat at free.fr>
> Cc: cubicweb at lists.cubicweb.org
> Envoyé: Vendredi 25 Mai 2012 09:29:43
> Objet: Re: [Cubicweb] customize rendering of a specific attribute in cw
> 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
> 2012/5/25 Stéphane Bugat < stephane.bugat at free.fr >
> Hi all,
> I was wondering if there was a way to customize the rendering of a
> specific attribute of an entity.
> For instance, I have an Airport entity with 2 Float(), latitude and
> longitude. These floats are usually displayed using the form xx°yy'zz''
> (for instance 45.658333 ==> 45° 39' 30.00 " N).
> At present I have modified the Airport PrimaryView function
> render_attributes(), but this means I have to set up how all other
> attributes are rendered. Moreover I have to do this for all specific
> context views of the Airport object.
> Another option would be to define a full Entity "Coordinate" and to put an
> inlined relation between Airport and Coordinate, but that would be a hammer
> to crush a fly.
> Thanks for any help!
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Cubicweb