[Cubicweb] Correct use of the 'person' cube

Florent Cayré fcayre at logilab.fr
Tue Jul 17 08:35:48 CEST 2012


Absolutely, you can use `match_rtype` together with the 
`after_add_relation` event as you propose.

This is probably the best solution to your problem. I am glad you 
figured it out by yourself, which means you finally found your way in 
the documentation.

Would you mind submitting a patch to the doc too? I think your 
experience is worth it.

Thanks for the follow-up,
Florent.

Le 17/07/2012 07:54, Stéphane Bugat a écrit :
> Florent,
>
> I've just seen your answer in the cw digest...
> Thanks for the help about the use of match_user_groups. The difference between client/server side operations was really not clear to me although chapter 6.2 of cw doc gives some details about it. But a small scheme could provide some useful help for cubicweb dumbs like me ;-)
>
> However, as you mention that the relation is built *after* the entities are created, in such case could we use a hook based on the relation with a selector like `match_rtype('in_group')` and a `after_add_relation` event? A test could be performed on the cwuser group using the `self.eidto` attribute...
>
> Thanks
>
> Stephane
> ----- Mail original -----
> De: "Stéphane Bugat"<stephane.bugat at free.fr>
> À: "Nicolas Chauvat"<nicolas.chauvat at logilab.fr>
> Cc: cubicweb at lists.cubicweb.org
> Envoyé: Dimanche 15 Juillet 2012 16:31:07
> Objet: Re: [Cubicweb] Correct use of the 'person' cube
>
> 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:
>
> class createProfileHook(Hook):
>      """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',)
>
>      def __call__(self):
>          (...)
>
> 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[0]?
>
> Stephane
>
> ----- 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__()
>
>    


-- 

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