[Cubicweb] Workflows and Hooks
aurelien.campeas at logilab.fr
Wed Aug 1 11:37:53 CEST 2012
Le 01/08/2012 11:17, Stéphane Bugat a écrit :
> Dear all
> I'm trying to capture the moment when a workflow changes its status to perform a relation creation.
A quite common need indeed.
> To be more specific, I have created a workflowable entity, 'ContactNotification',
> and I want that when the corresponding status of this entity becomes
> a link is created between the 2 persons (the one that created the
> and the targeted person by this notification).
> For that, I've tried to create a hook selecting instances of 'State' on events
>'after_update_entity', get the workflowable entity with a
> then get both persons involved, and finally set a symmetric relation
>both of them (with something like
sometimes I write such hooks like:
__regid__ = 'mycube.foo_happens'
events = ('after_add_relation',)
__select__ = (Hook.__select__ &
state = self._cw.entity_from_eid(self.eidto)
if state.name = 'foo':
This may not be the only/prettiest/... way but certainly useful.
> Tests performed shown that once a ContactNotification is accepted, the hook
>is not called at all (I've traced it using ugly *print* statements in
the __call__ of the hook)...
I personnally don't think print statements are an ugly debugging tool ....
> My 2 questions are:
> 1. Why this kind of hook is not called on such entities?
State entities dont get updated on workflowable transitions (see
cw/schemas/workflow.py for its structure & relations)... (They are
mostly immutable entities, which used in conjunction with Transitions,
describe a workflow.)
What gets updated is the workflowable entity state & history, through
the (X in_state State) (current) and (TrInfo wf_info_for X) (all) relations.
> 2. Is there another way to do it?
That leaves at least another way using wf_info_for (as an exercice ;-)
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
More information about the Cubicweb