[Cubicweb] Correct use of the 'person' cube

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Jul 13 09:02:45 CEST 2012

On 13 juillet 08:23, Stéphane Bugat wrote:
> One last question: I'd like to sync 'surname', 'firstname' attributes and email relations of both Person and CWUser in one and unique hook. For that I propose to select with a Hook.__select__ & (is_instance('Person') | is_instance('CWUser')) and to select on events ('after_add_entity', 'after_update_entity').
> Is there a way to retrieve the selected event and instance in the __call__() method of the hook?

You should rather write is_instance('Person', 'CWUser'). Then you can get the
event / instance in the hook using self.event / self.entity.

Note that while this is fine for user/person attributes, you should handle 
email differently as this is a related entity, and the treatment have much
probably to be done in a commit operation. See 
http://docs.cubicweb.org/devrepo/repo/hooks.html for documentation about

Sylvain Thénault, LOGILAB, Paris ( - Toulouse (
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