[Cubicweb] Correct use of the 'person' cube
stephane.bugat at free.fr
Sun Jul 15 16:31:07 CEST 2012
Ok, Nicolas. I still encounter a last problem with my hook. I try to select only CWUser belonging to the 'users' group. For that, my hook selector looks like this:
"""automatically creates a profile, a person and a blog when a user is created"""
__regid__ = 'create_profile'
__select__ = Hook.__select__ & is_instance('CWUser') & match_user_groups('users')
events = ('after_add_entity',)
Obviously this does not work and the hook is not called when creating a new CWUser with something like:
rset = rql(u'INSERT CWUser X: X login "jdoe", X upassword "foobar", '
u'X firstname "John", X surname "Doe", X in_group G '
u'WHERE G name "users"')
If I remove the 'match_user_groups' selector it is actually called... Does this mean that this selector cannot apply in a hook?
If so, how can I check the user group in the __call__ method? Using a test on self.entity.in_group?
----- Mail original -----
De: "Nicolas Chauvat" <nicolas.chauvat at logilab.fr>
À: "Stéphane Bugat" <stephane.bugat at free.fr>
Cc: cubicweb at lists.cubicweb.org
Envoyé: Vendredi 13 Juillet 2012 18:53:00
Objet: Re: [Cubicweb] Correct use of the 'person' cube
On Fri, Jul 13, 2012 at 08:23:52AM +0200, 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_instance('Person', 'CWUser') would be better
> Is there a way to retrieve the selected event and instance in the
> __call__() method of the hook?
According to http://docs.cubicweb.org/devrepo/repo/hooks I would say
you are looking for self.entity in YourOwnHook.__call__()
logilab.fr - services en informatique scientifique et gestion de connaissances
More information about the Cubicweb