[Cubicweb] nested relation / hook validation

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Jan 25 17:00:19 CET 2011

On 25 janvier 09:30, Carlos Balderas wrote:
> Hey Syt, thank you very much for such a complete explanation.
> In case I use the Operation option, I am getting like the entity ProcessRole
> has been already related to Process. e.i.
> class CheckJobTitleinProcess(hook.Operation):
>     """checks job title is not repeated in a process
>     """
>     def precommit_event(self):
>         """validates jobtitle before commit
>         """
>         for eid in
> self.session.transaction_data.pop('pending_jobtitle_checking'):
>             process_role = self.session.entity_from_eid(eid)
>             process = process_role.reverse_has_role[0]
>             if process.is_jobtitle_related(process_role):
>                 msgerror = u'%s' % self.session._('the process can have '
>                                                   'just one jobtitle')
>                 raise ValidationError(self, {'error': msgerror})
> then this is the Process method:
> By the time I get to "is_jobtitle_related" method the ProcessRole already is
> related to Process, and I am not sure if it is one of the commited
> ProcessRole in database or is the one I am trying to add.

at commit time, your process role is linked to the process you're trying to
add, which is in the database. Raising ValidationError will trigger a rollback
of the transaction (hence restore the value in the database).
Sylvain Thénault                               LOGILAB, Paris (France)
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