server/hook.py
branchstable
changeset 7879 9aae456abab5
parent 7638 cc7cde77184f
child 7990 a673d1d9a738
equal deleted inserted replaced
7874:be04706eacc9 7879:9aae456abab5
   535     category = None
   535     category = None
   536     order = 0
   536     order = 0
   537     # XXX deprecated
   537     # XXX deprecated
   538     enabled = True
   538     enabled = True
   539     # stop pylint from complaining about missing attributes in Hooks classes
   539     # stop pylint from complaining about missing attributes in Hooks classes
   540     eidfrom = eidto = entity = rtype = None
   540     eidfrom = eidto = entity = rtype = repo = None
   541 
   541 
   542     @classmethod
   542     @classmethod
   543     @cached
   543     @cached
   544     def filterable_selectors(cls):
   544     def filterable_selectors(cls):
   545         search = cls.__select__.search_selector
   545         search = cls.__select__.search_selector
   578         super(Hook, cls).__registered__(reg)
   578         super(Hook, cls).__registered__(reg)
   579         if getattr(cls, 'accepts', None):
   579         if getattr(cls, 'accepts', None):
   580             warn('[3.6] %s: accepts is deprecated, define proper __select__'
   580             warn('[3.6] %s: accepts is deprecated, define proper __select__'
   581                  % classid(cls), DeprecationWarning)
   581                  % classid(cls), DeprecationWarning)
   582             rtypes = []
   582             rtypes = []
   583             for ertype in cls.accepts:
   583             for ertype in cls.accepts: # pylint: disable=E1101
   584                 if ertype.islower():
   584                 if ertype.islower():
   585                     rtypes.append(ertype)
   585                     rtypes.append(ertype)
   586                 else:
   586                 else:
   587                     cls.__select__ = cls.__select__ & is_instance(ertype)
   587                     cls.__select__ = cls.__select__ & is_instance(ertype)
   588             if rtypes:
   588             if rtypes:
   599 
   599 
   600     def __call__(self):
   600     def __call__(self):
   601         if hasattr(self, 'call'):
   601         if hasattr(self, 'call'):
   602             warn('[3.6] %s: call is deprecated, implement __call__'
   602             warn('[3.6] %s: call is deprecated, implement __call__'
   603                  % classid(self.__class__), DeprecationWarning)
   603                  % classid(self.__class__), DeprecationWarning)
       
   604             # pylint: disable=E1101
   604             if self.event.endswith('_relation'):
   605             if self.event.endswith('_relation'):
   605                 self.call(self._cw, self.eidfrom, self.rtype, self.eidto)
   606                 self.call(self._cw, self.eidfrom, self.rtype, self.eidto)
   606             elif 'delete' in self.event:
   607             elif 'delete' in self.event:
   607                 self.call(self._cw, self.entity.eid)
   608                 self.call(self._cw, self.entity.eid)
   608             elif self.event.startswith('server_'):
   609             elif self.event.startswith('server_'):
   626     This hook ensure that when one of the watched relation is added, the
   627     This hook ensure that when one of the watched relation is added, the
   627     `main_rtype` relation is added to the target entity of the relation.
   628     `main_rtype` relation is added to the target entity of the relation.
   628     Notice there are no default behaviour defined when a watched relation is
   629     Notice there are no default behaviour defined when a watched relation is
   629     deleted, you'll have to handle this by yourself.
   630     deleted, you'll have to handle this by yourself.
   630 
   631 
   631     You usually want to use the :class:`match_rtype_sets` selector on concret
   632     You usually want to use the :class:`match_rtype_sets` selector on concrete
   632     classes.
   633     classes.
   633     """
   634     """
   634     events = ('after_add_relation',)
   635     events = ('after_add_relation',)
   635 
   636 
   636     # to set in concrete class
   637     # to set in concrete class
   806     def handle_event(self, event):
   807     def handle_event(self, event):
   807         """delegate event handling to the opertaion"""
   808         """delegate event handling to the opertaion"""
   808         if event == 'postcommit_event' and hasattr(self, 'commit_event'):
   809         if event == 'postcommit_event' and hasattr(self, 'commit_event'):
   809             warn('[3.10] %s: commit_event method has been replaced by postcommit_event'
   810             warn('[3.10] %s: commit_event method has been replaced by postcommit_event'
   810                  % classid(self.__class__), DeprecationWarning)
   811                  % classid(self.__class__), DeprecationWarning)
   811             self.commit_event()
   812             self.commit_event() # pylint: disable=E1101
   812         getattr(self, event)()
   813         getattr(self, event)()
   813 
   814 
   814     def precommit_event(self):
   815     def precommit_event(self):
   815         """the observed connections set is preparing a commit"""
   816         """the observed connections set is preparing a commit"""
   816 
   817 
  1090     def sendmails(self):
  1091     def sendmails(self):
  1091         self.session.vreg.config.sendmails(self.to_send)
  1092         self.session.vreg.config.sendmails(self.to_send)
  1092 
  1093 
  1093 
  1094 
  1094 class RQLPrecommitOperation(Operation):
  1095 class RQLPrecommitOperation(Operation):
       
  1096     # to be defined in concrete classes
       
  1097     rqls = None
       
  1098 
  1095     def precommit_event(self):
  1099     def precommit_event(self):
  1096         execute = self.session.execute
  1100         execute = self.session.execute
  1097         for rql in self.rqls:
  1101         for rql in self.rqls:
  1098             execute(*rql)
  1102             execute(*rql)
  1099 
  1103