[Cubicweb] Retrieve CWUser attributes in a view

Florent Cayré fcayre at logilab.fr
Tue Jul 3 17:26:21 CEST 2012


Le 03/07/2012 14:06, Stéphane Bugat a écrit :
> Dear all,
>
> In my CW project, I want to associate to any user the possibility to display or hide some entity attributes in the current entity view. To be more specific, I have an Airport entity type with a "fuel type" attribute, but not all users are interested to view the available fuel types.
>
> For that, I just need to build a specific "user preferences" entity with booleans attributes for the display/hide of Airport attributes, and associate this entity with CWUser using an inline relation.
>
> For the second part, that is the effective display or not of the attributes in a specific Airport view, I don't know how to proceed: how can I retrieve these booleans associated to the current CWUser in my EntityView? I guess there is a way to get them through self._cw but I don't know how.
>
> Hope this is clear for all of you - if not just let me know.
>
> Best regards
>
> Stéphane
>
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
>    
Hello,

I think you are looking for something like :

   self._cw.user.preferences[0].my_boolean_attribute

with "preferences" being the relation name from the CWUser to your user 
preferences entity type, and "my_boolean_attribute" the boolean 
attribute name you want the value of.

Note that self._cw is accessible from any AppObject instance, View being 
one of them (like Controller...).

Regards,

-- 

Florent Cayré

LOGILAB S.A.                      104, bd Auguste Blanqui 75013 PARIS
                                   tél +33 (0)1.45.32.03.12
                                   tél +33 (0)1.83.64.25.26
Formations Python, Debian, XP     http://www.logilab.fr/formations
Développement logiciel sur mesure http://www.logilab.fr/services
Python et calcul scientifique     http://www.logilab.fr/science
Gestion des connaissances         http://www.logilab.fr/gestion-connaissances
CubicWeb, semantic web framework  http://www.cubicweb.org




More information about the Cubicweb mailing list