server/hook.py
changeset 5877 0c7b7b76a84f
parent 5848 b5640328ffad
child 6142 8bc6eac1fac1
child 6263 e91ac6e95116
equal deleted inserted replaced
5876:e77aa963fb19 5877:0c7b7b76a84f
    61 from logilab.common.logging_ext import set_log_methods
    61 from logilab.common.logging_ext import set_log_methods
    62 
    62 
    63 from cubicweb import RegistryNotFound
    63 from cubicweb import RegistryNotFound
    64 from cubicweb.cwvreg import CWRegistry, VRegistry
    64 from cubicweb.cwvreg import CWRegistry, VRegistry
    65 from cubicweb.selectors import (objectify_selector, lltrace, ExpectedValueSelector,
    65 from cubicweb.selectors import (objectify_selector, lltrace, ExpectedValueSelector,
    66                                 implements)
    66                                 is_instance)
    67 from cubicweb.appobject import AppObject
    67 from cubicweb.appobject import AppObject
    68 from cubicweb.server.session import security_enabled
    68 from cubicweb.server.session import security_enabled
    69 
    69 
    70 ENTITIES_HOOKS = set(('before_add_entity',    'after_add_entity',
    70 ENTITIES_HOOKS = set(('before_add_entity',    'after_add_entity',
    71                       'before_update_entity', 'after_update_entity',
    71                       'before_update_entity', 'after_update_entity',
   244             rtypes = []
   244             rtypes = []
   245             for ertype in cls.accepts:
   245             for ertype in cls.accepts:
   246                 if ertype.islower():
   246                 if ertype.islower():
   247                     rtypes.append(ertype)
   247                     rtypes.append(ertype)
   248                 else:
   248                 else:
   249                     cls.__select__ = cls.__select__ & implements(ertype)
   249                     cls.__select__ = cls.__select__ & is_instance(ertype)
   250             if rtypes:
   250             if rtypes:
   251                 cls.__select__ = cls.__select__ & match_rtype(*rtypes)
   251                 cls.__select__ = cls.__select__ & match_rtype(*rtypes)
   252         return cls
   252         return cls
   253 
   253 
   254     known_args = set(('entity', 'rtype', 'eidfrom', 'eidto', 'repo', 'timestamp'))
   254     known_args = set(('entity', 'rtype', 'eidfrom', 'eidto', 'repo', 'timestamp'))
   260         self.event = event
   260         self.event = event
   261 
   261 
   262     def __call__(self):
   262     def __call__(self):
   263         if hasattr(self, 'call'):
   263         if hasattr(self, 'call'):
   264             cls = self.__class__
   264             cls = self.__class__
   265             warn('[3.6] %s.%s: call is deprecated, implements __call__'
   265             warn('[3.6] %s.%s: call is deprecated, implement __call__'
   266                  % (cls.__module__, cls.__name__), DeprecationWarning)
   266                  % (cls.__module__, cls.__name__), DeprecationWarning)
   267             if self.event.endswith('_relation'):
   267             if self.event.endswith('_relation'):
   268                 self.call(self._cw, self.eidfrom, self.rtype, self.eidto)
   268                 self.call(self._cw, self.eidfrom, self.rtype, self.eidto)
   269             elif 'delete' in self.event:
   269             elif 'delete' in self.event:
   270                 self.call(self._cw, self.entity.eid)
   270                 self.call(self._cw, self.entity.eid)