oops, feature killed by merge...
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 09 Oct 2009 16:46:44 +0200
changeset 3630 275feb5370c9
parent 3629 559cad62c786
child 3645 7272b793d7c9
oops, feature killed by merge...
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'