# HG changeset patch # User Sylvain Thénault # Date 1255099604 -7200 # Node ID 275feb5370c97dcc92d155059279354065777f70 # Parent 559cad62c786fe73d6cd64f3eec10ebfc847d333 oops, feature killed by merge... diff -r 559cad62c786 -r 275feb5370c9 hooks/integrity.py --- a/hooks/integrity.py Fri Oct 09 16:39:26 2009 +0200 +++ b/hooks/integrity.py Fri Oct 09 16:46:44 2009 +0200 @@ -142,18 +142,37 @@ """check the relation satisfy its constraints this is delayed to a precommit time operation since other relation which - will make constraint satisfied may be added later. + will make constraint satisfied (or unsatisfied) may be added later. """ __regid__ = 'checkconstraint' events = ('after_add_relation',) def __call__(self): constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto, - 'constraints') + 'constraints') if constraints: _CheckConstraintsOp(self._cw, constraints=constraints, rdef=(self.eidfrom, self.rtype, self.eidto)) +class CheckAttributeConstraintHook(IntegrityHook): + """check the attribute relation satisfy its constraints + + this is delayed to a precommit time operation since other relation which + will make constraint satisfied (or unsatisfied) may be added later. + """ + __regid__ = 'checkattrconstraint' + events = ('after_add_entity', 'after_update_entity') + + def __call__(self): + schema = self._cw.vreg.schema + for attr in self.entity.edited_attributes: + if schema.rschema(attr).is_final(): + constraints = [c for c in entity.e_schema.constraints(attr) + if isinstance(c, RQLVocabularyConstraint)] + if constraints: + _CheckConstraintsOp(self._cw, constraints=constraints, + rdef=(entity.eid, attr, None)) + class CheckUniqueHook(IntegrityHook): __regid__ = 'checkunique'