hooks/integrity.py
changeset 3998 94cc7cad3d2d
parent 3894 27cbf98ad863
child 4003 b9436fe77c9e
equal deleted inserted replaced
3895:92ead039d3d0 3998:94cc7cad3d2d
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     8 """
     8 """
     9 __docformat__ = "restructuredtext en"
     9 __docformat__ = "restructuredtext en"
    10 
    10 
    11 from cubicweb import ValidationError
    11 from cubicweb import ValidationError
    12 from cubicweb.schema import RQLVocabularyConstraint
    12 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    13 from cubicweb.selectors import entity_implements
    13 from cubicweb.selectors import entity_implements
    14 from cubicweb.common.uilib import soup2xhtml
    14 from cubicweb.common.uilib import soup2xhtml
    15 from cubicweb.server import hook
    15 from cubicweb.server import hook
    16 
    16 
    17 # special relations that don't have to be checked for integrity, usually
    17 # special relations that don't have to be checked for integrity, usually
   144     """
   144     """
   145     __regid__ = 'checkconstraint'
   145     __regid__ = 'checkconstraint'
   146     events = ('after_add_relation',)
   146     events = ('after_add_relation',)
   147 
   147 
   148     def __call__(self):
   148     def __call__(self):
       
   149         # XXX get only RQL[Unique]Constraints?
   149         constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
   150         constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
   150                                                 'constraints')
   151                                                 'constraints')
   151         if constraints:
   152         if constraints:
   152             _CheckConstraintsOp(self._cw, constraints=constraints,
   153             _CheckConstraintsOp(self._cw, constraints=constraints,
   153                                rdef=(self.eidfrom, self.rtype, self.eidto))
   154                                rdef=(self.eidfrom, self.rtype, self.eidto))
   165         schema = self._cw.vreg.schema
   166         schema = self._cw.vreg.schema
   166         entity = self.entity
   167         entity = self.entity
   167         for attr in entity.edited_attributes:
   168         for attr in entity.edited_attributes:
   168             if schema.rschema(attr).final:
   169             if schema.rschema(attr).final:
   169                 constraints = [c for c in entity.rdef(attr).constraints
   170                 constraints = [c for c in entity.rdef(attr).constraints
   170                                if isinstance(c, RQLVocabularyConstraint)]
   171                                if isinstance(c, (RQLUniqueConstraint, RQLConstraint))]
   171                 if constraints:
   172                 if constraints:
   172                     _CheckConstraintsOp(self._cw, constraints=constraints,
   173                     _CheckConstraintsOp(self._cw, constraints=constraints,
   173                                         rdef=(entity.eid, attr, None))
   174                                         rdef=(entity.eid, attr, None))
   174 
   175 
   175 
   176