server/repository.py
changeset 3589 a5432f99f2d9
parent 3446 fc5055a09550
parent 3584 585c4423a54c
child 3629 559cad62c786
equal deleted inserted replaced
3536:f6c9a5df80fb 3589:a5432f99f2d9
   841         try:
   841         try:
   842             eid = self.system_source.create_eid(session)
   842             eid = self.system_source.create_eid(session)
   843             self._extid_cache[cachekey] = eid
   843             self._extid_cache[cachekey] = eid
   844             self._type_source_cache[eid] = (etype, source.uri, extid)
   844             self._type_source_cache[eid] = (etype, source.uri, extid)
   845             entity = source.before_entity_insertion(session, extid, etype, eid)
   845             entity = source.before_entity_insertion(session, extid, etype, eid)
       
   846             if not hasattr(entity, 'edited_attributes'):
       
   847                 entity.edited_attributes = set()
   846             if source.should_call_hooks:
   848             if source.should_call_hooks:
   847                 entity.edited_attributes = set(entity)
   849                 entity.edited_attributes = set(entity)
   848                 self.hm.call_hooks('before_add_entity', session, entity=entity)
   850                 self.hm.call_hooks('before_add_entity', session, entity=entity)
   849             # XXX call add_info with complete=False ?
   851             # XXX call add_info with complete=False ?
   850             self.add_info(session, entity, source, extid)
   852             self.add_info(session, entity, source, extid)
   963         """add an entity to the repository
   965         """add an entity to the repository
   964 
   966 
   965         the entity eid should originaly be None and a unique eid is assigned to
   967         the entity eid should originaly be None and a unique eid is assigned to
   966         the entity instance
   968         the entity instance
   967         """
   969         """
       
   970         # init edited_attributes before calling before_add_entity hooks
       
   971         entity._is_saved = False # entity has an eid but is not yet saved
       
   972         entity.edited_attributes = set(entity)
   968         entity = entity.pre_add_hook()
   973         entity = entity.pre_add_hook()
   969         eschema = entity.e_schema
   974         eschema = entity.e_schema
   970         etype = str(eschema)
   975         etype = str(eschema)
   971         source = self.locate_etype_source(etype)
   976         source = self.locate_etype_source(etype)
   972         # attribute an eid to the entity before calling hooks
   977         # attribute an eid to the entity before calling hooks
   973         entity.set_eid(self.system_source.create_eid(session))
   978         entity.set_eid(self.system_source.create_eid(session))
   974         if server.DEBUG & server.DBG_REPO:
   979         if server.DEBUG & server.DBG_REPO:
   975             print 'ADD entity', etype, entity.eid, dict(entity)
   980             print 'ADD entity', etype, entity.eid, dict(entity)
   976         entity._is_saved = False # entity has an eid but is not yet saved
       
   977         relations = []
   981         relations = []
   978         # init edited_attributes before calling before_add_entity hooks
       
   979         entity.edited_attributes = set(entity)
       
   980         if source.should_call_hooks:
   982         if source.should_call_hooks:
   981             self.hm.call_hooks('before_add_entity', session, entity=entity)
   983             self.hm.call_hooks('before_add_entity', session, entity=entity)
   982         # XXX use entity.keys here since edited_attributes is not updated for
   984         # XXX use entity.keys here since edited_attributes is not updated for
   983         # inline relations
   985         # inline relations
   984         for attr in entity.keys():
   986         for attr in entity.keys():
  1150     # pyro handling ###########################################################
  1152     # pyro handling ###########################################################
  1151 
  1153 
  1152     def pyro_register(self, host=''):
  1154     def pyro_register(self, host=''):
  1153         """register the repository as a pyro object"""
  1155         """register the repository as a pyro object"""
  1154         from logilab.common.pyro_ext import register_object
  1156         from logilab.common.pyro_ext import register_object
  1155         appid = self.config['pyro-id'] or self.config.appid
  1157         appid = self.config['pyro-instance-id'] or self.config.appid
  1156         daemon = register_object(self, appid, self.config['pyro-ns-group'],
  1158         daemon = register_object(self, appid, self.config['pyro-ns-group'],
  1157                                  self.config['pyro-host'],
  1159                                  self.config['pyro-host'],
  1158                                  self.config['pyro-ns-host'])
  1160                                  self.config['pyro-ns-host'])
  1159         msg = 'repository registered as a pyro object using group %s and id %s'
  1161         msg = 'repository registered as a pyro object using group %s and id %s'
  1160         self.info(msg, self.config['pyro-ns-group'], appid)
  1162         self.info(msg, self.config['pyro-ns-group'], appid)
  1183 
  1185 
  1184 
  1186 
  1185 def pyro_unregister(config):
  1187 def pyro_unregister(config):
  1186     """unregister the repository from the pyro name server"""
  1188     """unregister the repository from the pyro name server"""
  1187     from logilab.common.pyro_ext import ns_unregister
  1189     from logilab.common.pyro_ext import ns_unregister
  1188     appid = config['pyro-id'] or config.appid
  1190     appid = config['pyro-instance-id'] or config.appid
  1189     ns_unregister(appid, config['pyro-ns-group'], config['pyro-ns-host'])
  1191     ns_unregister(appid, config['pyro-ns-group'], config['pyro-ns-host'])
  1190 
  1192 
  1191 
  1193 
  1192 from logging import getLogger
  1194 from logging import getLogger
  1193 from cubicweb import set_log_methods
  1195 from cubicweb import set_log_methods